lib/numru/gphys/gphys.rb in gphys-1.1.1 vs lib/numru/gphys/gphys.rb in gphys-1.2.2

- old
+ new

@@ -407,12 +407,18 @@ ---coerce(other) ((|You know what it is.|)) ---shape_coerce(other) - Like ((<coerce>)), but just changes shape without changing numeric type. + Like ((<coerce>)), but just changes shape without changing numeric type + by possibly inserting dimensions whose lengths are one (i.e., + without changeing the total length of data). +---shape_coerce_full(other) + Similar to ((<shape_coerce>)) but to return the gphyses having + really the same shape with possible expansion by replication. + ---transpose(*dims) Transpose. ARGUMENTS * dims (integers) : for example, [1,0] to transpose a 2D object. @@ -763,9 +769,19 @@ [longer, shorter] else [shorter, longer] end end + end + + def shape_coerce_full(other) + o, s = shape_coerce(other) + if o.length < s.length + o = GPhys.new( s.grid, o + NArray.new(o.typecode,*s.shape) ) + elsif o.length > s.length + s = GPhys.new( o.grid, s + NArray.new(s.typecode,*o.shape) ) + end + [o, s] end def transpose(*dims) grid = @grid.transpose(*dims) data = @data.transpose(*dims)