operator []= method

void operator []=(
  1. int index,
  2. dynamic value
)

Sets the value at index to value.

Throws a RangeError if index is out of bounds.

Implementation

void operator []=(int index, dynamic value) {
  _checkRange(index);

  if (numDimensions != 1) {
    int? valueNumDimensions;

    if (value is NdArray) {
      valueNumDimensions = value.numDimensions;
    } else if (value is List) {
      valueNumDimensions = ListTools.countDimensions(value);
    }

    if (valueNumDimensions == null || valueNumDimensions != numDimensions) {
      throw ArgumentError('value must have the same number of dimensions as '
          'the original array\n'
          'Expected: ${numDimensions - 1}\n'
          'Actual: $valueNumDimensions');
    }
  }

  _data[index] = value;
}