Method: MDArray#section

Defined in:
lib/mdarray/views.rb

#section(origin, shape, reduce = false) ⇒ Object


Create a new Array as a subsection of this Array, without rank reduction. No data is moved, so the new Array references the same backing store as the original. Throws: InvalidRangeException - if ranges is invalid


Parameters:

  • origin

    ruby array specifying the starting index. Must be same rank as original Array.

  • shape

    ruby array specifying the extents in each dimension. This becomes the shape of the returned Array. Must be same rank as original Array.

  • reduce (defaults to: false)

    true if the array should be reduced by removing dimensions of size 1



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/mdarray/views.rb', line 133

def section(origin, shape, reduce = false)

  jorigin = origin.to_java :int
  jshape = shape.to_java :int

  if (reduce)
    arr = @nc_array.section(jorigin, jshape)
  else
    arr = @nc_array.sectionNoReduce(jorigin, jshape, nil)
  end

  # this is an array section, set it to true
  if (arr.rank == 0)
    return arr.get()
  end

  # Build the new array as a section from the given one.  Last argument to build is
  # "true" indicating this is a section.
  section = MDArray.build_from_nc_array(@type, arr, true)
  copy_print_parameters(section)
  return section

end