lib/numru/gphys/gphys.rb in gphys-1.5.2 vs lib/numru/gphys/gphys.rb in gphys-1.5.3

- old
+ new

@@ -803,18 +803,43 @@ end ## For graphics --> def first3D raise "rank less than 3" if rank < 3 - self[true,true,*([0]*(rank-3))] + self[true,true,true,*([0]*(rank-3))] end def first2D raise "rank less than 2" if rank < 2 self[true,true,*([0]*(rank-2))] end def first1D raise "rank less than 1" if rank < 1 self[true,*([0]*(rank-1))] + end + def firstNDreally(nd) + sh = shape_current + n = 0 + sel = sh.map do |len| + if len > 1 && n < nd + n += 1 + true + else + 0 + end + end + if n<nd + raise "Invalid shape #{sh} (not really #{nd}D or greater): # of dims with len>1 is fewer than #{nd}" + end + self[*sel] + end + def first3Dreally + firstNDreally(3) + end + def first2Dreally + firstNDreally(2) + end + def first1Dreally + firstNDreally(1) end ## <-- For graphics def coerce(other) case other