public virtual void AssignSubArray(uint[] memorypos, NamedMultiDimArray buffer, uint[] bufferpos, uint[] count) { NamedMultiDimArray mema = this; NamedMultiDimArray memb = buffer; MultiDimArray_CalculateCopyIndicesIter iter = MultiDimArray_CalculateCopyIndicesIter.BeginIter(mema.Dims, memorypos, memb.Dims, bufferpos, count); uint indexa; uint indexb; uint len; while (iter.Next(out indexa, out indexb, out len)) { Array.Copy(memb.namedarray_array, (long)indexb, mema.namedarray_array, (long)indexa, (long)len); } }
public virtual void RetrieveSubArray(uint[] memorypos, PodMultiDimArray buffer, uint[] bufferpos, uint[] count) { PodMultiDimArray mema = this; PodMultiDimArray memb = buffer; MultiDimArray_CalculateCopyIndicesIter iter = MultiDimArray_CalculateCopyIndicesIter.BeginIter(mema.Dims, memorypos, memb.Dims, bufferpos, count); uint indexa; uint indexb; uint len; while (iter.Next(out indexa, out indexb, out len)) { Array.Copy(mema.pod_array, (long)indexa, memb.pod_array, (long)indexb, (long)len); } }
public static MultiDimArray_CalculateCopyIndicesIter BeginIter(uint[] mema_dims, uint[] mema_pos, uint[] memb_dims, uint[] memb_pos, uint[] count) { if (count.Length == 0) { throw new ArgumentException("MultiDimArray count invalid"); } if (count.Length > mema_dims.Length || count.Length > memb_dims.Length) { throw new ArgumentException("MultiDimArray copy count invalid"); } if (count.Length > memb_dims.Length || count.Length > memb_dims.Length) { throw new ArgumentException("MultiDimArray copy count invalid"); } for (int i = 0; i < mema_dims.Length; i++) { if (mema_dims[i] < 0) { throw new ArgumentException("MultiDimArray mema_dims invalid"); } } for (int i = 0; i < memb_dims.Length; i++) { if (memb_dims[i] < 0) { throw new ArgumentException("MultiDimArray memb_dims invalid"); } } for (int i = 0; i < count.Length; i++) { if (count[i] < 0) { throw new ArgumentException("MultiDimArray count invalid"); } } for (int i = 0; i < mema_dims.Length && i < count.Length; i++) { if (mema_pos[i] > mema_dims[i] || (mema_pos[i] + count[i]) > mema_dims[i]) { throw new ArgumentException("MultiDimArray A count invalid"); } } for (int i = 0; i < memb_dims.Length && i < count.Length; i++) { if (memb_pos[i] > memb_dims[i] || (memb_pos[i] + count[i]) > memb_dims[i]) { throw new ArgumentException("MultiDimArray B count invalid"); } } var stridea = new uint[count.Length]; stridea[0] = 1; for (uint i = 1; i < (uint)count.Length; i++) { stridea[i] = stridea[i - 1] * mema_dims[i - 1]; } var strideb = new uint[count.Length]; strideb[0] = 1; for (uint i = 1; i < (uint)count.Length; i++) { strideb[i] = strideb[i - 1] * memb_dims[i - 1]; } var o = new MultiDimArray_CalculateCopyIndicesIter(); o.mema_dims = mema_dims; o.memb_dims = memb_dims; o.mema_pos = mema_pos; o.memb_pos = memb_pos; o.count = count; o.current_count = new uint[count.Length]; o.done = false; o.stridea = stridea; o.strideb = strideb; return(o); }