toList method

List<double> toList([
  1. bool deepCopy = true
])

Returns the List<double> of this Vector

Note that by default this function returns a List that does not shares its storage with the Vector, but allocates it's own memory. This means you can freely change the matrix after creating the vector and the vector will be unaffected.

If you wish to share the storage with the Vector for performance reasons pass deepCopy = false. This means that changes to the Vector also appear in the List, however this only works for row vectors. Column vectors always make a deep copy.

Implementation

List<double> toList([bool deepCopy = true]) {
  if (_vectorType == VectorType.row) {
    if (deepCopy) {
      return List<double>.generate(this.elements, (i) => this._matrix[0][i]);
    } else {
      return this._matrix[0];
    }
  } else {
    if (deepCopy) {
      return List<double>.generate(this.elements, (i) => this._matrix[i][0]);
    } else {
      throw MatrixUnsupportedOperation("Cannot create shallow copy of column vector");
    }
  }
}