public virtual void resize(idxdim d) { if (d.order() > spec.ndim) { throw new Exception("cannot change order of idx in resize while trying to resize " + " from " + this + " to " + d); } if (!same_dim(d)) { // save some time if dims are same spec.resize(d); growstorage(); } }
public bool same_dim(idxdim d) { if (spec.ndim != d.order()) { return(false); } for (int i = 0; i < spec.ndim; ++i) { if (spec.dim[i] != d.dim(i)) { return(false); } } return(true); }
public static idx <T> load_matrix <T>(ref FILE fp) where T : struct { int magic = 0; idxdim dims = read_matrix_header(ref fp, ref magic); idx <T> Out = new idx <T>(); Out = new idx <T>(dims); if (Out.get_idxdim() != dims) { // different order/dimensions // if order is different, it's from the input matrix, error if (Out.order() != dims.order()) { Global.eblerror("error: different orders: " + Out + " " + dims); } // resize output idx Out.resize(dims); } if ((magic == get_magic <T>())) { // read read_matrix_body(ref fp, ref Out); } else { // different type, read original type, then copy/cast into out switch (magic) { case MAGIC_BYTE_MATRIX: case MAGIC_UBYTE_VINCENT: read_cast_matrix <Byte, T>(ref fp, ref Out); break; case MAGIC_INTEGER_MATRIX: case MAGIC_INT_VINCENT: read_cast_matrix <int, T>(ref fp, ref Out); break; case MAGIC_FLOAT_MATRIX: case MAGIC_FLOAT_VINCENT: read_cast_matrix <float, T>(ref fp, ref Out); break; case MAGIC_DOUBLE_MATRIX: case MAGIC_DOUBLE_VINCENT: read_cast_matrix <double, T>(ref fp, ref Out); break; case MAGIC_LONG_MATRIX: read_cast_matrix <long, T>(ref fp, ref Out); break; case MAGIC_UINT_MATRIX: read_cast_matrix <uint, T>(ref fp, ref Out); break; case MAGIC_UINT64_MATRIX: read_cast_matrix <UInt64, T>(ref fp, ref Out); break; case MAGIC_INT64_MATRIX: read_cast_matrix <Int64, T>(ref fp, ref Out); break; default: Global.eblerror("unknown magic number"); break; } } return(Out); }