| Class | Matrix |
| In: |
aprl/base/ap_lina.rb
|
| Parent: | Vector |
# 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
# 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
# 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
# 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
# File aprl/base/ap_lina.rb, line 328 def collect_flat each do |row| row.collect do |cell| yield(cell) end end end
# File aprl/base/ap_lina.rb, line 320 def collect_flat! each do |row| row.collect! do |cell| yield(cell) end end end
# 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
# 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
# File aprl/base/ap_lina.rb, line 336 def each_flat each do |row| row.each do |cell| yield(cell) end end end
# 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
# 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
# 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
# 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
# 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
# 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