Sets the value at the Dimension address provided to the value of T type val.
Since this object can have n dimensions, a val
's position in the Matrix is
referred to as it's dimensionAddress
. If the length of the dimensionAddress
does not match the matrix's dimensions an error is thrown. If at each point in
the dimension address, the value is out of bounds of that dimensions range, an
error is thrown.
Source
void set(List<int> dimensionAddress, T val) {
List get = this._core;
if (this._matrixDimension == dimensionAddress.length) {
for (int k = 0; k < dimensionAddress.length; k++) {
if (dimensionAddress[k] < get.length) {
if ((k + 1) == dimensionAddress.length) {
get[dimensionAddress[k]] = val;
} else {
get = get[dimensionAddress[k]];
}
} else {
///Calcuate how far out of bounds in Dimension k the value is.
int outOfBounds = dimensionAddress[k] - get.length;
throw new DimensionalMisMatchException(
"ERROR: Dimension MisMatch at Dimension $k of the NMatrix. Out of Bounds by: $outOfBounds.");
}
}
} else {
///Gets the difference in D
int dimDiff = dimensionAddress.length - this._matrixDimension;
throw new DimensionalMisMatchException(
"ERROR: Dimension MisMatch. NMatrix object does not have same number dimensions as the dimensionsAddress provided. Dimension Dif: $dimDiff.");
}
}