Class Matrix
In: aprl/base/ap_lina.rb
Parent: Vector
Vector Matrix Array dot/f_26.png

Methods

Public Class methods

[Source]

# File aprl/base/ap_lina.rb, line 310
  def initialize(m=0,n=0,v=0)    
    @m=m;@n=n
    @m.times { self.push Vector.new(n) }    
    collect_flat! { |x| v }
  end

Public Instance methods

[Source]

# File aprl/base/ap_lina.rb, line 422
  def *(v)
    case true
    when v.kind_of?(Vector)
      r=Vector.new
      @m.times do |i|
        r.push row(i)*v
      end
      r
    else
      
    end
  end

[Source]

# File aprl/base/ap_lina.rb, line 447
  def*(m)
    r=Matrix.new(@m,@n)
    if m.kind_of?(Float) or m.kind_of?(Integer) 
      r.iiv_collect!{|i,j,v| self[i][j]*m }    
    end
    r
  end

[Source]

# File aprl/base/ap_lina.rb, line 439
  def +(m)
    raise "Matrixes can only be added to each other" if not m.kind_of?(Matrix)
    raise "Matrixes can only be added if  of same size" if m.size()!=size()
    #collect_flat_together(m) { |a,b| a+b }          

    r=Matrix.new(@m,@n)
    r.iiv_collect!{|i,j,v| m[i][j]+self[i][j]}    
  end

[Source]

# File aprl/base/ap_lina.rb, line 328
  def collect_flat
    each do |row|
      row.collect do |cell|
        yield(cell)
      end      
    end    
  end

[Source]

# File aprl/base/ap_lina.rb, line 320
  def collect_flat!
    each do |row|
      row.collect! do |cell|
        yield(cell)
      end      
    end    
  end

[Source]

# File aprl/base/ap_lina.rb, line 352
  def collect_flat_together(o)
    iiv_collect do |i,j,v|
      yield(v,o[i][j]) 
    end    
  end

[Source]

# File aprl/base/ap_lina.rb, line 344
  def collect_flat_together!(o)
    each_iv do |i,row|
      row.each_iv do |j,cell|
        self[i][j]=yield(cell,o[i][j])
      end      
    end    
  end

[Source]

# File aprl/base/ap_lina.rb, line 336
  def each_flat
    each do |row|
      row.each do |cell|
        yield(cell)
      end      
    end    
  end

[Source]

# File aprl/base/ap_lina.rb, line 316
  def fill_flat(*a)
    collect_flat!{ a.shift }
  end

[Source]

# File aprl/base/ap_lina.rb, line 386
  def iiv_collect
    ret = Matrix.new(@m,@n)
    @m.times do |i|
      @n.times do |j| 
        ret[i][j]=yield(i,j,self[i][j])  
      end
    end
    ret
  end

[Source]

# File aprl/base/ap_lina.rb, line 377
  def iiv_collect!
    each_iv do |i,row|
      row.each_iv do |j,v|
        self[i][j]=yield(i,j,v)
      end
    end
    self
  end

[Source]

# File aprl/base/ap_lina.rb, line 396
  def iiv_collect_old
    iv_collect do |i,row|
      row.iv_collect do |j,v|
        yield(i,j,v)
      end
    end    
  end

[Source]

# File aprl/base/ap_lina.rb, line 364
  def iv_collect
    ret = Matrix.new(@m,@n)
    length.times { |i|
      row=yield(i,self[i]) 
      @n.times { |j| ret[i][j]=row[j] }
    } 
    ret
  end

[Source]

# File aprl/base/ap_lina.rb, line 358
  def iv_collect_putt
    z = Matrix.new 
    @m.times { |i| z.push(yield(i,self[i])) } 
    z
  end

[Source]

# File aprl/base/ap_lina.rb, line 404
  def row(i)
    self[i]
  end

[Source]

# File aprl/base/ap_lina.rb, line 435
  def size
    return @m,@n
  end

[Source]

# File aprl/base/ap_lina.rb, line 373
  def to_s(fmt=nil) 
    super(fmt)
  end

[Source]

# File aprl/base/ap_lina.rb, line 455
  def to_s(fmt=-1,sep="\n",sep1=',')
    s=''
    @m.times do  |r|
      s<<sep unless r==0
      @n.times do |d|
        s<<sep1 unless d==0
        if fmt!=-1
          s<<sprintf(fmt,self[r][d])
        else
          s<<self[r][d].to_s
        end        
      end      
    end
    s
  end

def push(v)

  super(Vector.from_array(v))

end

[Source]

# File aprl/base/ap_lina.rb, line 412
  def transpose()
    r = Matrix.new(@n,@m)
    iv_collect do |i,row|
      row.iv_collect do |j,v|
        r[j][i]=v
      end
    end
    r
  end

[Validate]