public static bool HasIndex <T>(this T[,,] self, long index0, long index1, long index2) { if (index0 < 0) { return(false); } var lenght0 = self.GetLongLength(0); if (lenght0 <= index0 || index1 < 0) { return(false); } var lenght1 = self.GetLongLength(1); if (lenght1 <= index1 || index2 < 0) { return(false); } var lenght2 = self.GetLongLength(1); if (lenght2 <= index2) { return(false); } return(true); }
/// <summary> /// Copies the entire current three-dimentional array (cube) into a new one. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="me">The current three-dimetional array.</param> /// <returns>A copy of the entire current three-dimetional array.</returns> public static T[,,] GetCopy <T>(this T[,,] me) { if (me == null) { return(null); } T[,,] copy = new T[me.GetLongLength(0), me.GetLongLength(1), me.GetLongLength(2)]; Array.Copy(me, copy, me.LongLength); return(copy); }
public void Data <T>(T[, ,] data, BufferUsage usage) where T : struct { if (data == null) { throw new ArgumentNullException("data"); } Data(data, new IntPtr(checked (Marshal.SizeOf(typeof(T)) * data.GetLongLength(0) * data.GetLongLength(1) * data.GetLongLength(2))), usage); }
/// <summary> /// Copies the contents to this buffer to the given array. /// </summary> /// <param name="stream">The used accelerator stream.</param> /// <param name="target">The target array.</param> /// <param name="sourceOffset">The source offset.</param> /// <param name="targetOffset">The target offset.</param> /// <param name="extent">The length.</param> /// <remarks> /// Note that the output array will contain the data as a transposed array to /// match the source layout. /// </remarks> public void CopyTo( AcceleratorStream stream, T[,,] target, LongIndex3 sourceOffset, LongIndex3 targetOffset, LongIndex3 extent) { if (target == null) { throw new ArgumentNullException(nameof(target)); } if (sourceOffset.X < 0 || sourceOffset.Y < 0 || sourceOffset.Z < 0 || sourceOffset.X >= Extent.X || sourceOffset.Y >= Extent.Y || sourceOffset.Z >= Extent.Z) { throw new ArgumentOutOfRangeException(nameof(sourceOffset)); } if (targetOffset.X < 0 || targetOffset.Y < 0 || targetOffset.Z < 0 || targetOffset.X >= target.GetLongLength(0) || targetOffset.Y >= target.GetLongLength(1) || targetOffset.Z >= target.GetLongLength(2)) { throw new ArgumentOutOfRangeException(nameof(targetOffset)); } if (extent.X < 0 || extent.Y < 0 || extent.Z < 0 || sourceOffset.X + extent.X > Extent.X || sourceOffset.Y + extent.Y > Extent.Y || sourceOffset.Z + extent.Z > Extent.Z || targetOffset.X + extent.X > target.GetLongLength(0) || targetOffset.Y + extent.Y > target.GetLongLength(1) || targetOffset.Z + extent.Z > target.GetLongLength(2)) { throw new ArgumentOutOfRangeException(nameof(extent)); } var tempBuffer = new T[extent.Size]; buffer.CopyTo(stream, tempBuffer, sourceOffset, 0, extent); for (long i = 0; i < extent.X; ++i) { for (long j = 0; j < extent.Y; ++j) { for (long k = 0; k < extent.Z; ++k) { var sourceIdx = new LongIndex3(i, j, k). ComputeLinearIndex(extent); target[ i + targetOffset.X, j + targetOffset.Y, k + targetOffset.Z] = tempBuffer[sourceIdx]; } } } }
/// <summary> /// Copies the contents of this buffer from the given array. /// </summary> /// <param name="stream">The used accelerator stream.</param> /// <param name="source">The source array.</param> /// <param name="sourceOffset">The source offset.</param> /// <param name="targetOffset">The target offset.</param> /// <param name="extent">The length.</param> /// <remarks> /// Note that the input array will stored as a transposed array to match the /// target layout. /// </remarks> public void CopyFrom( AcceleratorStream stream, T[,,] source, LongIndex3 sourceOffset, LongIndex3 targetOffset, LongIndex3 extent) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (sourceOffset.X < 0 || sourceOffset.Y < 0 || sourceOffset.Z < 0 || sourceOffset.X >= source.GetLongLength(0) || sourceOffset.Y >= source.GetLongLength(1) || sourceOffset.Z >= source.GetLongLength(2)) { throw new ArgumentOutOfRangeException(nameof(sourceOffset)); } if (targetOffset.X < 0 || targetOffset.Y < 0 || targetOffset.Z < 0 || targetOffset.X >= Extent.X || targetOffset.Y >= Extent.Y || targetOffset.Z >= Extent.Z) { throw new ArgumentOutOfRangeException(nameof(targetOffset)); } if (extent.X < 0 || extent.Y < 0 || extent.Z < 0 || sourceOffset.X + extent.X > source.GetLength(0) || sourceOffset.Y + extent.Y > source.GetLength(1) || sourceOffset.Z + extent.Z > source.GetLength(2) || targetOffset.X + extent.X > Extent.X || targetOffset.Y + extent.Y > Extent.Y || targetOffset.Z + extent.Z > Extent.Z) { throw new ArgumentOutOfRangeException(nameof(extent)); } var tempBuffer = new T[extent.Size]; for (long i = 0; i < extent.X; ++i) { for (long j = 0; j < extent.Y; ++j) { for (long k = 0; k < extent.Z; ++k) { var targetIdx = new LongIndex3(i, j, k). ComputeLinearIndex(extent); tempBuffer[targetIdx] = source[ i + sourceOffset.X, j + sourceOffset.Y, k + sourceOffset.Z]; } } } buffer.CopyFrom( stream, tempBuffer, 0, targetOffset, extent.Size); }
public void Write <T>(long offsetInBytes, T[, ,] data) where T : struct { Write(offsetInBytes, data, checked (data.GetLongLength(0) * data.GetLongLength(1) * data.GetLongLength(2))); }
/// <summary> /// Gets a 64-bit integer that represents the number of elements in the specified dimension of the array. /// </summary> /// <typeparam name="T">The type of values stored in the array.</typeparam> /// <param name="array">The array.</param> /// <param name="dimension">The dimension whose length needs to be determined.</param> /// <returns>A 64-bit integer that represents the number of elements in the specified dimension.</returns> public static long GetLongLength <T>(this T[,,] array, Axis3D dimension) { Contracts.Requires.That(array != null); return(array.GetLongLength((int)dimension)); }