public T gget(T val, intg i0 = 0, intg i1 = 0, intg i2 = 0, intg i3 = 0, intg i4 = 0, intg i5 = 0, intg i6 = 0, intg i7 = 0) { switch (spec.ndim) { case 7: i7 = -1; break; case 6: i6 = -1; i7 = -1; break; case 5: i5 = -1; i6 = -1; i7 = -1; break; case 4: i4 = -1; i5 = -1; i6 = -1; i7 = -1; break; case 3: set(val, i0, i1, i2); break; case 2: set(val, i0, i1); break; case 1: set(val, i0); break; case 0: set(val); break; default: break; } return(ptr(i0, i1, i2, i3, i4, i5, i6, i7).item = val); }
// select, narrow, unfold, etc // Each function has 3 version: // 1. XXX_into: which writes the result // into an existing idxspec apssed as argument. // 2. XXX_inplace: writes into the current idxspec // 3. XXX: creates a new idxspec and returns it. public intg select_into(ref idxspec dst, int d, intg n) { if (ndim <= 0) { throw new Exception("cannot select an empty idx idx that is a scalar (" + this + ")"); } if ((n < 0) || (n >= dim[d])) { throw new Exception("trying to select layer " + n + " of dimension " + d + " which is of size " + dim[d] + " in idx " + this); } // this preserves the dim/mod arrays if dst == this dst.setndim(ndim - 1); dst.offset = offset + (n * mod[d]); if (ndim - 1 > 0) { // dim and mod don't exist for idx0 for (int j = 0; j < d; j++) { dst.dim[j] = dim[j]; dst.mod[j] = mod[j]; } for (int j = d; j < ndim - 1; j++) { dst.dim[j] = dim[j + 1]; dst.mod[j] = mod[j + 1]; } } return(n); }
public T gget(intg i0 = 0, intg i1 = 0, intg i2 = 0, intg i3 = 0, intg i4 = 0, intg i5 = 0, intg i6 = 0, intg i7 = 0) { switch (spec.ndim) { case 7: i7 = -1; break; case 6: i6 = -1; i7 = -1; break; case 5: i5 = -1; i6 = -1; i7 = -1; break; case 4: i4 = -1; i5 = -1; i6 = -1; i7 = -1; break; case 3: return(get(i0, i1, i2)); case 2: return(get(i0, i1)); case 1: return(get(i0)); case 0: return(get()); default: break; } return(ptr(i0, i1, i2, i3, i4, i5, i6, i7).item); }
public idx(intg size0) { spec = new idxspec(0, size0); pidxdim = null; srgptr = new Ptr <srg <T> >(new srg <T>()); growstorage(); }
public idx <T> narrow(int d, intg s, intg o) { idx <T> r = new idx <T>(srgptr, spec.getoffset()); spec.narrow_into(ref r.spec, d, s, o); return(r); }
public idx <T> unfold(int d, intg k, intg s) { idx <T> r = new idx <T>(srgptr, spec.getoffset()); spec.unfold_into(ref r.spec, d, k, s); return(r); }
public idxspec unfold(int d, intg k, intg s) { idxspec r = new idxspec(); unfold_into(ref r, d, k, s); return(r); }
public idx <T> select(int d, intg i) { idx <T> r = new idx <T>(srgptr, spec.getoffset()); spec.select_into(ref r.spec, d, i); return(r); }
public idxspec select(int d, intg n) { idxspec r = new idxspec(); select_into(ref r, d, n); return(r); }
public intg narrow_into(ref idxspec dst, int d, intg s, intg o) { if (ndim <= 0) { throw new Exception("cannot narrow a scalar"); } if ((d < 0) || (d >= ndim)) { throw new Exception("narrow: illegal dimension index " + d + " in " + this); } if ((o < 0) || (s < 1) || (s + o > dim[d])) { throw new Exception("trying to narrow dimension " + d + " to size " + s + " starting at offset " + o + " in " + this); } // this preserves the dim/mod arrays if dst == this dst.setndim(ndim); dst.offset = offset + o * mod[d]; for (int j = 0; j < ndim; j++) { dst.dim[j] = dim[j]; dst.mod[j] = mod[j]; } dst.dim[d] = s; return(s); }
public void set(T val, intg i0) { if (Global.DEBUG) { loops.idx_checkorder1(this, 1); } srgptr.I.Set(spec.getoffset() + i0 * spec.mod[0], val); }
public void set(T val, intg i0, intg i1, intg i2) { if (Global.DEBUG) { loops.idx_checkorder1(this, 3); } srgptr.I.Set(spec.getoffset() + i0 * spec.mod[0] + i1 * spec.mod[1] + i2 * spec.mod[2], val); }
public idx(T[] mat, intg s0, intg s1, intg s2) { pidxdim = null; spec = new idxspec(0, s0, s1, s2); srgptr = new Ptr <srg <T> >(new srg <T>()); growstorage(); srgptr.I.Set(srgptr.I.GetData()); }
private void growstorage_chunk(intg s_chunk) { if (srgptr.I.growsize_chunk(spec.footprint(), s_chunk) < 0) { throw new Exception("cannot grow storage to " + spec.footprint() + " size (probably out of memory)"); } }
idxspec narrow(int d, intg s, intg o) { // create new idxspec of order ndim idxspec r = new idxspec(); narrow_into(ref r, d, s, o); return(r); }
public idx(intg s0, intg s1, intg s2, intg s3, intg s4 = -1, intg s5 = -1, intg s6 = -1, intg s7 = -1) { spec = new idxspec(0, s0, s1, s2, s3, s4, s5, s6, s7); pidxdim = null; srgptr = new Ptr <srg <T> >(new srg <T>()); growstorage(); }
public virtual void resize(intg s0 = -1, intg s1 = -1, intg s2 = -1, intg s3 = -1, intg s4 = -1, intg s5 = -1, intg s6 = -1, intg s7 = -1) { if (!same_dim(s0, s1, s2, s3, s4, s5, s6, s7)) { // save some time spec.resize(s0, s1, s2, s3, s4, s5, s6, s7); growstorage(); } }
public eptr <T> ptr(intg i0) { loops.idx_checkorder1(this, 1); if ((i0 < 0) || (i0 >= spec.dim[0])) { Global.eblerror("index 0 out of bound"); } return(new eptr <T>(srgptr, spec.getoffset())); }
public intg footprint() { intg r = offset + 1; for (int i = 0; i < ndim; i++) { r += mod[i] * (dim[i] - 1); } return(r); }
public idx <T> view_as_order(int n) { if (n < 0) { throw new Exception("view_as_order: input dimension must be positive"); return(this); } if (n == spec.ndim) { return(this); } else { if ((n == 1) && (spec.ndim == 1)) { // the order is already 1, do nothing and return current idx. return(new idx <T>(this)); } else if (n == 1) { // the order is not 1, check that data is contiguous and return // a 1D idx. loops.CHECK_CONTIGUOUS1(this); idx <T> r = new idx <T>(getstorage(), 0, spec.nelements()); return(r); } else if (n > spec.ndim) { intg[] ldim = new intg[n]; intg[] lmod = new intg[n]; ldim = spec.dim; lmod = spec.mod; for (int i = spec.ndim; i < n; ++i) { ldim[i] = 1; lmod[i] = 1; } idx <T> r = new idx <T>(getstorage(), spec.getoffset(), n, ldim, lmod); if (!(ldim == null)) { ldim = null; } if ((lmod == null)) { lmod = null; } return(r); } else { throw new Exception("view_as_order is not defined when n < current order"); return(new idx <T>(this)); } } }
public virtual void resize1(intg dimn, intg size) { if (dimn > spec.ndim) { throw new Exception("cannot change order of idx in resize"); } if (spec.dim[dimn] != size) { spec.resize1(dimn, size); growstorage(); } }
public idxlooper(idx <T> m, int ld) { if (m.order() == 0) { Global.eblerror("cannot loop on idx with order 0. idx is: " + m); } i = 0; dimd = m.spec.dim[ld]; modd = m.spec.mod[ld]; m.spec.select_into(ref spec, ld, i); this.srgptr = m.srgptr.Addreference(); item = new eptr <T>(srgptr, spec.getoffset()); }
public eptr <T> ptr(intg i0, intg i1) { loops.idx_checkorder1(this, 2); if ((i0 < 0) || (i0 >= spec.dim[0])) { Global.eblerror("index 0 out of bound"); } if ((i1 < 0) || (i1 >= spec.dim[1])) { Global.eblerror("index 1 out of bound"); } return(new eptr <T>(srgptr, spec.getoffset() + i0 * spec.mod[0] + i1 * spec.mod[1])); }
public T get(intg i0, intg i1, intg i2) { if (Global.DEBUG) { loops.idx_checkorder1(this, 3); if (((i0 < 0) || (i0 >= spec.dim[0])) || ((i1 < 0) || (i1 >= spec.dim[1])) || ((i2 < 0) || (i2 >= spec.dim[2]))) { Global.eblerror("error accessing elt " + i0 + "x" + i1 + "x" + i2 + " in " + this + ", index out of bound"); } return(srgptr.I.Get(spec.getoffset() + i0 * spec.mod[0] + i1 * spec.mod[1] + i2 * spec.mod[2])); } return(srgptr.I.Get(spec.getoffset() + i0 * spec.mod[0])); }
public T get(intg i0) { if (Global.DEBUG) { loops.idx_checkorder1(this, 1); if ((i0 < 0) || (i0 >= spec.dim[0])) { Global.eblerror("error accessing elt " + i0 + " in " + this + ", index out of bound"); } return(srgptr.I.Get(spec.getoffset() + i0 * spec.mod[0])); } return(srgptr.I.Get(spec.getoffset() + i0 * spec.mod[0])); }
public idxspec(intg o, int n, intg[] ldim, intg[] lmod) { dim = null; mod = null; offset = o; ndim = -1; setndim(n); for (int i = 0; i < n; i++) { if (ldim[i] < 0) { throw new Exception("negative dimension"); } dim[i] = ldim[i]; mod[i] = lmod[i]; } }
public idx(Ptr <srg <T> > sg, intg o, intg n, int[] dims, intg[] mods) { pidxdim = null; if (!(sg == null)) { spec = new idxspec(o, n, dims, mods); srgptr = sg.Addreference(); } else { spec = new idxspec(0, n, dims, mods); } srgptr = new Ptr <srg <T> >(new srg <T>()); growstorage(); }
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 idx(Ptr <srg <T> > sg, intg o, intg s0, intg s1, intg s2, intg s3, intg s4 = -1, intg s5 = -1, intg s6 = -1, intg s7 = -1) { pidxdim = null; if (!(sg == null)) { spec = new idxspec(o, s0, s1, s2, s3, s4, s5, s6, s7); srgptr = sg.Addreference(); } else { spec = new idxspec(0, s0, s1, s2, s3, s4, s5, s6, s7); srgptr = new Ptr <srg <T> >(new srg <T>()); } growstorage(); }
public intg setoffset(intg o) { if (o < 0) { throw new Exception("idx::setoffset: offset must be positive"); } if (o > spec.getoffset()) { spec.setoffset(o); growstorage(); return(o); } else { spec.setoffset(o); return(o); } }