public idx(idxdim d) { spec = new idxspec(0, d); pidxdim = null; srgptr = new Ptr <srg <T> >(new srg <T>()); growstorage(); }
static public idxdim read_matrix_header(ref FILE fp, ref int magic) { int ndim = 0, v = 0; int ndim_min = 3; // std header requires at least 3 dims even empty ones. idxdim dims = new idxdim(); //read magic number if (fp.fread(ref magic) != 1) { fp.fclose(); Global.eblerror("cannot read magic number"); } if (is_magic(magic)) {// regular magic numnber, read next number if (fp.fread(ref ndim) != 1) { fp.fclose(); Global.eblerror("cannot read number of dimensions"); } //check number is valid if (ndim > Global.MAXDIMS) { fp.fclose(); Global.eblerror("too many dimensions: " + ndim + "(MAXDIMS = " + Global.MAXDIMS + ")."); } } else { // unknown magic fp.fclose(); Global.eblerror("unknown magic number: " + magic); } //read each dimension for (int i = 0; (i < ndim) || (i < ndim_min); ++i) { if (fp.fread(ref v) != 1) { fp.fclose(); Global.eblerror("failed to read matrix dimensions"); } if (i < ndim) { // ndim may be less than ndim_min if (v <= 0) { // check that dimension is valid fp.fclose(); Global.eblerror("dimension is negative or zero"); } dims.insert_dim(i, v); // insert dimension } } return(dims); }
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 idxdim get_matrix_dims(string name) { //open file FILE fp = new FILE(name); if (fp == null) { Global.eblerror("failed to open " + name); } //read it int magic = 0; idxdim d = read_matrix_header(ref fp, ref magic); fp.fclose(); return(d); }
public idx(Ptr <srg <T> > sg, intg o, idxdim d) { pidxdim = null; if (!(sg == null)) { spec = new idxspec(o, d); srgptr = sg.Addreference(); } else { spec = new idxspec(0, d); srgptr = new Ptr <srg <T> >(new srg <T>()); } growstorage(); }
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); }
public idxdim get_idxdim() { idxdim d = new idxdim(); d.setdims(spec); return(d); }