static public void read_cast_matrix <T, T2>(ref FILE fp, ref idx <T2> Out) where T : struct where T2 : struct { idx <T> m = new idx <T>(Out.get_idxdim()); read_matrix_body(ref fp, ref m); idxops <T> .idx_copy <T2>(m, Out); }
public static idx <T> idx_copy(idx <T> m) { idx <T> dst = new idx <T>(m.get_idxdim()); idx_copy <T>(m, dst); return(dst); }
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); }