changeDim method Null safety

List changeDim(
  1. List list,
  2. int dim
)

Implementation

List changeDim(List list, int dim) {
  if (dim == 0) {
    throw new Exception("DartTensorException : dimension cannot be 0.");
  } else {
    int getdim = getDim(list).length;
    if (getdim == dim) {
    } else if (getdim < dim) {
      int remain = dim - getdim;
      for (int i = 0; i < remain; i++) {
        list = List.generate(1, (i) => list, growable: true);
      }
    } else {
      throw new Exception(
          "DartTensorException : ndim cannot be lower than dimmension of DartTensor.");
    }
  }
  return list;
}