class Tensor
Attributes
order[R]
p[R]
q[R]
qorder[R]
rank[R]
Public Class Methods
builder(a,*args)
click to toggle source
# File lib/m500.rb, line 3865 def Tensor.builder(a,*args) tmp = "" script = "_" if @@script == "covarient" script = "U" if @@script == "contravarient" m = [a]+args unless a.class == Array m = a if a.class == Array # assume this is an @order from + call z1 = "" z2 = "" x1, x2 = m, "INNER" m.reverse.to_a.each_index{|c| t2 = @@t1 + "#{m.length-c}" t3 = @@t1 + "#{c+1}" x1 = "#{x2}" x1 , x2 = x2, "(1..#{m.reverse.at(c)}).to_a.each{|#{t2}|\n#{x1}\n}" z1 << "#{script}\#{#{t3}}" z2 << "#{script}\\\#{#{t3}}" } t3 = "@at#{z1} = 0 \n" t4 = "def at#{z1}\n @at#{z1}\nend \n" t5 = "def at#{z1}=(a)\n @at#{z1} = a\nend \n" t6a = "def +(mn)\n if mn.order == @order then a= Tensor(@order)\n" t6b = "\nreturn a\n else\n # #raise error\n end\n end" t6 = t6a + x2.gsub("INNER"," z = \\\"a.at#{z2} = self.at#{z2} + mn.at#{z2}\\\"\n eval(z)") + t6b t7 = [x2,z1] tmp = x2.gsub("INNER","z = \"#{t3}#{t4}#{t5}\"\n instance_eval(z)\n #puts z") return tmp,m,t6,t7 end
instanciate(a,*args)
click to toggle source
# File lib/m500.rb, line 3946 def Tensor.instanciate(a,*args) t = Tensor.builder(a,*args) t6 =t.at(2) # for information o n t6 see T::builder new(t.at(0) + "\n instance_eval(\"#{t6}\")",t.at(1)) end
new(a,p)
click to toggle source
# File lib/m500.rb, line 3969 def initialize(a,p) eval(a) @tr = false @p = @@script == "covarient" ? p.length : 0 @q = @@script == "covarient" ? 0 : q.length @order = @@script == "covarient" ? p : [] @qorder = @@script == "covarient" ? [] : q @rank = @p + @q @rframe= [] end
new!(a,*args)
click to toggle source
# File lib/m500.rb, line 3893 def Tensor.new!(a,*args) t1, t2 = [],[] u1, u2 = [],[] if a.kind_of?(Hash) then a.each{|x,y| x =~ %r{(_(?!_.*)(?!.*=$).*)} unless $1 == nil then t1 << $1 ; t2 << y end x =~ %r{(U(?!U.*)(?!.*=$).*)} unless $1 == nil then u1 << $1 ; u2 << y end } m,n = nil,nil o,p = [],[] t1.each{|a,b| s = a.split('_'); s.shift o << s } u1.each{|a,b| t = a.split('U'); t.shift p << t } m = Array.new(o.at(0).length,Array.new) n = Array.new(p.at(0).length,Array.new) o.each{|t| t.each_index{|h| m[h] += [t.at(h)] } } m.each_index{|i| m[i] = [m.at(i).max] } p.each{|t| t.each_index{|h| n[h] += [t.at(h)] } } n.each_index{|i| n[i] = [n.at(i).max] } tu = Tensor.instanciate(m) t1.each_index{|s| eval("tu.at#{t1.at(s)} = #{t2.at(s)}") } if n then tu.contra(n) u1.each_index{|s| eval("tu.at#{u1.at(s)} = #{u2.at(s)}") } end tu else Tensor.instanciate(a,*args) end end
Public Instance Methods
*(other)
click to toggle source
# File lib/m500.rb, line 3985 def *(other) ta1 ="a= Tensor(x+y)# @ order+other.order)\n a.contra(s+t) # @qorder+other.qorder)\n #puts a.indicies\n" t1= Tensor.builder(@order+other.order).at(3) t2= Tensor.builder(@order).at(3) t3= Tensor.builder(other.order).at(3) u1= Tensor.builder(@qorder+other.qorder).at(3) if @q+other.q <0 u2= Tensor.builder(@qorder).at(3) if @q+other.q <0 u3= Tensor.builder(other.qorder).at(3)if @q+other.q <0 tu = " Proc.new{|x,y,z,s,t| \n" + ta1 + t1.at(0).gsub("INNER"," z = \"a.at#{t1.at(1)} = self.at#{t2.at(1)} * other.at#{t3.at(1)}\"\n eval(z)") tu += "\n"+ u1.at(0).gsub("INNER"," z = \"a.at#{u1.at(1)} = self.at#{u2.at(1)} * other.at#{u3.at(1)}\"\n #eval(z)") if @q+other.q <0 tu += "\na\n}" tp = eval(tu) t = tp.call(@order, other.order,"",@qorder,other.qorder) return t.inspect end
+(other)
click to toggle source
# File lib/m500.rb, line 3980 def +(other) t6a = "if other.order == @order && other.qorder == @qorder then a= Tensor(@order)\n" t6b = "\nreturn a\n else\n # #raise error\n end\n end" end
contra(n,*args)
click to toggle source
# File lib/m500.rb, line 3963 def contra(n,*args) @@script = "contravarient" t = Tensor.builder(n,*args) @@script = "covarient" eval(t.at(0)) end
indicies()
click to toggle source
# File lib/m500.rb, line 3951 def indicies z = self.public_methods x = [] z.each{|y| y =~ %r{(_(?!_.*)(?!methods)(?!variable.*)(?!defined.)(?!eval)(?!send)(?!at)(?!get|set)(?!a|s|h)(?!id.*)(?!.*=$)(?!.*\?$).*)} unless $1 == nil then x << $1 end y =~ %r{(U(?!U.*)(?!.*=$).*)} unless $1 == nil then x << $1 end } x.delete("_") return x end
product(&block)
click to toggle source
# File lib/m500.rb, line 4001 def product(&block) a = block.call return a end
to_csv()
click to toggle source
# File lib/m500.rb, line 4019 def to_csv t = "" (1..@order.a(0)).to_a.each{|a| (1..@order.at(1)).to_a.each{|b| t << eval("at_#{a}_#{b}_1").to_s unless b == @order.at(1) then t << 44 end } t << 10 } t end
to_h()
click to toggle source
# File lib/m500.rb, line 4032 def to_h eval(to_s) end
to_s()
click to toggle source
# File lib/m500.rb, line 4005 def to_s t = "" page = 4 (1..@order.at(0)).to_a.each{|a| t << "|" (1..@order.at(1)).to_a.each{|b| t << eval("at_#{a}_#{b}_#{page}").to_s unless b == @order.at(1) then t << 9 end } t << "|" unless a == @order.at(1) then t << 10 end } t end
to_sgml()
click to toggle source
# File lib/m500.rb, line 4030 def to_sgml end