bool dimensionalExpansion(List<int> dimensionSizes, [T initVal = null])

Dimensional Expander algorithm.

This algorithm essentially creates a new matrix construct with a number of dimensions equal to the length of dimensionSizes with each dimension k having a size equal to the value at the kth index in dimensionSizes. It also ports all values of the data points of the old matrix construct to their same "dimensional address" in the new matrix construct. All remaining values in the new matrix construct are set to initVal. This algorithm then replaces the core of this object with the new matrix construct. Returns true if expansion was successful, and false otherwise. Note, to expand a matrix construct, a new matrix's dimensions can only be >= the current number of dimensions. Also, for each new dimension to the number of dimensions of the current matrix construct, each dimensions Size can only be >= each of the current matrix dimension's sizes. This ensures there is no "shrinking" effect which would cause a loss in data of the current matrix. For instance, {2,2,2} => {2,3,2} | {2,2,2,3} | {2,2,2,1} is valid, but {2,2,2} => {1} | {2,2,1,2} is invalid.

Source

bool dimensionalExpansion(List<int> dimensionSizes, [T initVal = null]) {
  bool isExpanded = false;
  if (dimensionSizes.length >= this._matrixDimension) {
    bool validFlag = true;
    int k = 0;
    while ((k < this._dimensionSizes.length) && (validFlag)) {
      if (dimensionSizes[k] < this._dimensionSizes[k]) {
        validFlag = false;
      }
      k++;
    }
    if (validFlag) {
      //If Expanded Dimensions are Valid, Port existing values to new expanded Matrix Construct:
      //Set the initValue to the new initial value, if one is provided. Otherwise set it to null.
      //already is.
      this._initValue = initVal;

      //Reset dataPointCount before running extrude for the new matrix construct.
      this._dataPointCount = 0;

      //Extrude the new matrix to the defined number of dimensions.
      NMatrix<T> newNM =
          new NMatrix.dimensional(dimensionSizes, this._initValue);

      ///Used to fetch elements at this address in the matrixPort algorithm.
      List dimensionalAdress = new List(this._dimensionSizes.length);
      for (int i = 0; i < this._dimensionSizes.length; i++) {
        for (int j = 0; j < this._dimensionSizes[i]; j++) {
          dimensionalAdress[i] = 0;
        }
      }

      //Port the old dataPoints in the current core to the new core.
      this._matrixPort(0, newNM.matrix, newNM, dimensionalAdress);

      //Set the new list of dimensionSizes:
      this._dimensionSizes = dimensionSizes;
      //Set to new number of dimensions:
      this._matrixDimension = dimensionSizes.length;

      //Finally, swap the cores:
      this._core = newNM.matrix;

      //Notify flag:
      isExpanded = true;
    }
  }
  return isExpanded;
}