Class: CAIterator

Inherits:
Object
  • Object
show all
Defined in:
lib/carray/iterator.rb

Overview


CAIterator -- the form-only base of the iterator family. It carries no engine: each family member (CASlabIterator / CAWindowIterator / CABlockIterator / CACategoricalIterator / CAGroupIterator) implements its own fast engine. The base declares two things: the shared form accessors over the @ndim / @shape ivars, and the common reduction surface every member must implement (surface uniformity is the value: "this is an iterator, so it must answer these").

shape is canonical; dim is a legacy alias. A member exposes what it actually holds (source / reference / labels) and adds its own methods (min_index / max_index / map / correlate / convolve / sort_addr / ...); those are NOT part of the common contract because some members legitimately omit them (a window has no map, a group has no within-piece min_index).

The 2.0 generic dispatch (calculate / filter / evaluate over a kernel_at_addr slot) was retired in 3.0.


Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ndim ⇒ Object (readonly)

No include Enumerable: the family surface is fully explicit per iterator, so Enumerable's reduction-like names (to_a / min / sum / count / ...) do not leak in and silently fold the pieces. A method outside the contract below that a member does not define is a clean NoMethodError, not a wrong answer.



29
30
31
# File 'lib/carray/iterator.rb', line 29

def ndim
  @ndim
end

#shape ⇒ Object (readonly) Also known as: dim

No include Enumerable: the family surface is fully explicit per iterator, so Enumerable's reduction-like names (to_a / min / sum / count / ...) do not leak in and silently fold the pieces. A method outside the contract below that a member does not define is a clean NoMethodError, not a wrong answer.



29
30
31
# File 'lib/carray/iterator.rb', line 29

def shape
  @shape
end

Instance Method Details

#accumulate ⇒ CArray

Returns the sum of each piece kept in the source's own data_type, wrapping at its width, where #sum answers in the type the core promotes to (:float64 for integers).

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#all ⇒ CArray

Returns whether every cell of each piece is true.

Returns:

  • (CArray) —

    :boolean, one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#any ⇒ CArray

Returns whether any cell of each piece is true.

Returns:

  • (CArray) —

    :boolean, one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#count(value = nil) ⇒ CArray

Returns a count per piece: with no argument the cells that are not masked, with UNDEF the masked cells, and with any other value the cells equal to it.

Parameters:

  • value (Object) (defaults to: nil) —

    value to match, or UNDEF.

Returns:

  • (CArray) —

    one count per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#count_masked ⇒ CArray

Returns the number of masked cells of each piece.

Returns:

  • (CArray) —

    one count per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#count_not_masked ⇒ CArray

Returns the number of cells of each piece that are not masked.

Returns:

  • (CArray) —

    one count per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#cumcount ⇒ CArray

Returns a source-shaped array of the running count of cells that are not masked within each piece.

Returns:

  • (CArray) —

    shaped like the source.

Raises:

  • (NotImplementedError) —

    for a member whose pieces overlap.



212
213
214
215
216
217
# File 'lib/carray/iterator.rb', line 212

[:map, :sort_addr,
 :cumsum, :cumprod, :cummax, :cummin, :cumcount].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} does not provide ##{name} (optional)"
  end
end

#cummax ⇒ CArray

Returns a source-shaped array of the running maximum within each piece.

Returns:

  • (CArray) —

    shaped like the source.

Raises:

  • (NotImplementedError) —

    for a member whose pieces overlap.



212
213
214
215
216
217
# File 'lib/carray/iterator.rb', line 212

[:map, :sort_addr,
 :cumsum, :cumprod, :cummax, :cummin, :cumcount].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} does not provide ##{name} (optional)"
  end
end

#cummin ⇒ CArray

Returns a source-shaped array of the running minimum within each piece.

Returns:

  • (CArray) —

    shaped like the source.

Raises:

  • (NotImplementedError) —

    for a member whose pieces overlap.



212
213
214
215
216
217
# File 'lib/carray/iterator.rb', line 212

[:map, :sort_addr,
 :cumsum, :cumprod, :cummax, :cummin, :cumcount].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} does not provide ##{name} (optional)"
  end
end

#cumprod ⇒ CArray

Returns a source-shaped array of the running product within each piece.

Returns:

  • (CArray) —

    shaped like the source.

Raises:

  • (NotImplementedError) —

    for a member whose pieces overlap.



212
213
214
215
216
217
# File 'lib/carray/iterator.rb', line 212

[:map, :sort_addr,
 :cumsum, :cumprod, :cummax, :cummin, :cumcount].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} does not provide ##{name} (optional)"
  end
end

#cumsum ⇒ CArray

Returns a source-shaped array of the running sum within each piece.

Returns:

  • (CArray) —

    shaped like the source.

Raises:

  • (NotImplementedError) —

    for a member whose pieces overlap, where a cell has no single running value.



212
213
214
215
216
217
# File 'lib/carray/iterator.rb', line 212

[:map, :sort_addr,
 :cumsum, :cumprod, :cummax, :cummin, :cumcount].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} does not provide ##{name} (optional)"
  end
end

#each {|piece| ... } ⇒ Enumerator, self

Yields each piece in turn as a CArray.

Yield Parameters:

Returns:

  • (Enumerator, self) —

    an Enumerator when no block is given.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#elements ⇒ CArray

Returns the total number of cells in each piece, masked or not.

Returns:

  • (CArray) —

    one count per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#map {|piece| ... } ⇒ CArray

Returns a source-shaped array built by applying the block to each piece and scattering the result back into that piece's cells.

Yield Parameters:

Yield Returns:

  • (CArray, Numeric) —

    replacement values for the piece.

Returns:

  • (CArray) —

    shaped like the source.

Raises:

  • (NotImplementedError) —

    for a member whose pieces overlap, where a cell would receive more than one value.



212
213
214
215
216
217
# File 'lib/carray/iterator.rb', line 212

[:map, :sort_addr,
 :cumsum, :cumprod, :cummax, :cummin, :cumcount].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} does not provide ##{name} (optional)"
  end
end

#max ⇒ CArray

Returns the largest value in each piece.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#max_addr ⇒ CArray

Returns the flat address in the source of the largest value of each piece.

Returns:

  • (CArray) —

    one flat address per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#max_index ⇒ CArray

Returns the position of the largest value within each piece.

Returns:

  • (CArray) —

    one index per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#mean ⇒ CArray

Returns the arithmetic mean of each piece.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#median ⇒ CArray

Returns the median of each piece.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#min ⇒ CArray

Returns the smallest value in each piece.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#min_addr ⇒ CArray

Returns the flat address in the source of the smallest value of each piece -- which source cell holds it, rather than where it sits inside the piece. Use it to read the same cell out of another source-shaped array.

Returns:

  • (CArray) —

    one flat address per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#min_index ⇒ CArray

Returns the position of the smallest value within each piece.

Returns:

  • (CArray) —

    one index per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#minmax ⇒ Array<CArray>

Returns the smallest and largest value of each piece, found in one pass.

Returns:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#percentile(*pers) ⇒ CArray+

Returns the requested percentile(s) of each piece.

Parameters:

  • pers (Array<Numeric>) —

    percentile positions in 0..100.

Returns:

  • (CArray, Array<CArray>) —

    one array per requested position; a single position returns that array directly.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#prod ⇒ CArray

Returns the product of each piece.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#quantile ⇒ Array<CArray>

Returns the five-number summary of each piece, [min, Q1, median, Q3, max].

Returns:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#reduce(init = nil) {|acc, piece| ... } ⇒ Object

Folds the pieces with a block, for a reduction the family does not name. Without init the first piece seeds the accumulator.

Parameters:

  • init (Object) (defaults to: nil) —

    initial accumulator value.

Yield Parameters:

  • acc (Object) —

    running accumulator.

  • piece (CArray) —

    next piece.

Yield Returns:

  • (Object) —

    updated accumulator.

Returns:

  • (Object) —

    the final accumulator.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#sort_addr ⇒ CArray

Returns a source-shaped array whose cells, read piece by piece, give the flat source addresses that put that piece in ascending order.

Returns:

  • (CArray) —

    :int64, shaped like the source.

Raises:

  • (NotImplementedError) —

    for a member whose pieces overlap.



212
213
214
215
216
217
# File 'lib/carray/iterator.rb', line 212

[:map, :sort_addr,
 :cumsum, :cumprod, :cummax, :cummin, :cumcount].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} does not provide ##{name} (optional)"
  end
end

#stddev ⇒ CArray

Returns the sample standard deviation (divisor n - 1) of each piece.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#stddevp ⇒ CArray

Returns the population standard deviation (divisor n) of each piece.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#sum ⇒ CArray

Returns the sum of each piece.

Returns:



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#variance ⇒ CArray

Returns the sample variance (divisor n - 1) of each piece.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#variancep ⇒ CArray

Returns the population variance (divisor n) of each piece.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#wmean(weights) ⇒ CArray

Returns the weighted mean of each piece.

Parameters:

  • weights (CArray) —

    one weight per source cell, shaped like the source.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end

#wsum(weights) ⇒ CArray

Returns the weighted sum of each piece.

Parameters:

  • weights (CArray) —

    one weight per source cell, shaped like the source.

Returns:

  • (CArray) —

    one value per piece.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/carray/iterator.rb', line 147

[
  :sum, :accumulate, :prod, :mean, :min, :max,                      # tier 1
  :variance, :stddev, :all, :any,
  :variancep, :stddevp, :minmax,                                    # tier 2
  :min_index, :max_index, :min_addr, :max_addr,                     # position
  :wsum, :wmean,                                                    # weighted
  :median, :percentile, :quantile,                                 # tier 3
  :count, :count_not_masked, :count_masked, :elements,             # count family
  :each, :reduce,                                                   # generic iterate
].each do |name|
  define_method(name) do |*, **, &_blk|
    raise NotImplementedError, "#{self.class} must implement ##{name}"
  end
end