/// <summary> /// Construct an ArrayBufferObjectInterleaved specifying its item layout on CPU side. /// </summary> /// <param name="arrayItemType"> /// A <see cref="Type"/> describing the type of the array item. /// </param> /// <param name="hint"> /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints. /// </param> public ArrayBufferObjectInterleaved(Type arrayItemType, BufferObjectHint hint) : base(arrayItemType, hint) { // Get fields for defining array item definition FieldInfo[] arrayItemTypeFields = arrayItemType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (arrayItemTypeFields.Length == 0) throw new ArgumentException("no public fields", "arrayItemType"); // Determine array sections stride int structStride = Marshal.SizeOf(arrayItemType); for (int i = 0; i < arrayItemTypeFields.Length; i++) { FieldInfo arrayItemTypeField = arrayItemTypeFields[i]; ArraySection arraySection = new ArraySection(this, arrayItemTypeField.FieldType); // Determine array section offset arraySection.ItemOffset = Marshal.OffsetOf(arrayItemType, arrayItemTypeField.Name); // Determine array section stride arraySection.ItemStride = new IntPtr(structStride); // Mission Normalized property management: add attributes? arraySection.Normalized = false; ArraySections.Add(arraySection); } // Determine array item size ItemSize = (uint)structStride; }
/// <summary> /// Construct an ArrayBufferObjectInterleaved specifying its item layout on CPU side. /// </summary> /// <param name="arrayItemType"> /// A <see cref="Type"/> describing the type of the array item. /// </param> /// <param name="hint"> /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints. /// </param> public ArrayBufferObjectInterleaved(Type arrayItemType, BufferObjectHint hint) : base(arrayItemType, hint) { // Get fields for defining array item definition FieldInfo[] arrayItemTypeFields = arrayItemType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (arrayItemTypeFields.Length == 0) { throw new ArgumentException("no public fields", "arrayItemType"); } // Determine array sections stride int structStride = Marshal.SizeOf(arrayItemType); for (int i = 0; i < arrayItemTypeFields.Length; i++) { FieldInfo arrayItemTypeField = arrayItemTypeFields[i]; ArraySection arraySection = new ArraySection(this, arrayItemTypeField.FieldType); // Determine array section offset arraySection.ItemOffset = Marshal.OffsetOf(arrayItemType, arrayItemTypeField.Name); // Determine array section stride arraySection.ItemStride = new IntPtr(structStride); // Mission Normalized property management: add attributes? arraySection.Normalized = false; ArraySections.Add(arraySection); } // Determine array item size ItemSize = (uint)structStride; }
public State() { _arguments = null; _locals = null; _memory = new Dictionary <string, SSA.Value>(); _bindings = new List <Nesting>(); _bindings.Add(new Nesting()); }
/// <summary> /// Computing cumulative moments from the histogram. /// </summary> private void HistogramToMoments() { // Not using ArraySection for these because they are too small for pooling. // We could use stackalloc but it's too negligible advantage for a fairly large stack allocation long[] area = new long[histCount]; long[] areaR = new long[histCount]; long[] areaG = new long[histCount]; long[] areaB = new long[histCount]; float[] area2 = new float[histCount]; ArraySection <long> wtBuf = wt.Buffer; ArraySection <long> mrBuf = mr.Buffer; ArraySection <long> mgBuf = mg.Buffer; ArraySection <long> mbBuf = mb.Buffer; ArraySection <float> m2Buf = m2.Buffer; for (int r = 1; r <= histSize; r++) { for (int i = 0; i <= histSize; i++) { area2[i] = area[i] = areaR[i] = areaG[i] = areaB[i] = 0; } for (int g = 1; g <= histSize; g++) { float line2 = 0f; long line = 0; long lineR = 0; long lineG = 0; long lineB = 0; for (int b = 1; b <= histSize; b++) { // instead of [r, g, b] int ind1 = (r << 10) + (r << 6) + r + (g << 5) + g + b; line += wtBuf[ind1]; lineR += mrBuf[ind1]; lineG += mgBuf[ind1]; lineB += mbBuf[ind1]; line2 += m2Buf[ind1]; area[b] += line; areaR[b] += lineR; areaG[b] += lineG; areaB[b] += lineB; area2[b] += line2; // instead of [r-1, g, b] int ind2 = ind1 - 1089; wtBuf[ind1] = wtBuf[ind2] + area[b]; mrBuf[ind1] = mrBuf[ind2] + areaR[b]; mgBuf[ind1] = mgBuf[ind2] + areaG[b]; mbBuf[ind1] = mbBuf[ind2] + areaB[b]; m2Buf[ind1] = m2Buf[ind2] + area2[b]; } } } }
public override bool MoveNextRow() { if (!base.MoveNextRow()) { return(false); } Row = ((ManagedBitmapData <TColor, TRow>)BitmapData).Buffer[Index]; return(true); }
public void SliceTest() { ArraySection <int> section = Enumerable.Range(0, 10).ToArray(); ArraySection <int> subsection = section.Slice(1, 2); Assert.AreEqual(1, subsection[0]); Assert.AreEqual(2, subsection.Length); #if !(NETFRAMEWORK || NETSTANDARD2_0 || NETCOREAPP2_0) Span <int> span = section.AsSpan; Assert.AreEqual(span.Slice(1, 2).ToArray(), subsection); Assert.AreEqual(span[1..^ 1].ToArray(), section[1..^ 1]);
public State(State other) { _stack = new StackQueue <SSA.Value>(); for (int i = 0; i < other._stack.Count; ++i) { _stack.Push(other._stack.PeekBottom(i)); } _arguments = _stack.Section(other._arguments.Base, other._arguments.Len); _locals = _stack.Section(other._locals.Base, other._locals.Len); _bindings = new List <Nesting>(); _bindings.AddRange(other._bindings); }
public void EqualsTest() { ArraySection <int> section = null; Assert.IsTrue(section.Equals(null)); Assert.IsTrue(section.Equals((object)null)); section = Reflector.EmptyArray <int>(); Assert.IsTrue(section.Equals(Reflector.EmptyArray <int>())); Assert.IsTrue(section.Equals((object)Reflector.EmptyArray <int>())); Assert.AreNotEqual(ArraySection <_> .Null, ArraySection <_> .Empty); }
public void ConversionsNullAndEmptyTest() { ArraySection <int> section = null; Assert.IsTrue(section == null, "Compare with null works due to implicit operator and string comparison"); Assert.IsNotNull(section, "ArraySection is actually a value type"); Assert.IsTrue(section.IsNull); Assert.IsNull(section.ToArray()); section = Reflector.EmptyArray <int>(); Assert.IsTrue(section == Reflector.EmptyArray <int>()); Assert.IsFalse(section.IsNull); Assert.IsTrue(section.IsNullOrEmpty); Assert.IsTrue(section.Length == 0); Assert.AreEqual(Reflector.EmptyArray <int>(), section.ToArray()); }
public void SliceTest() { const int width = 4; const int height = 3; ArraySection <int> section = Enumerable.Range(0, width * height).ToArray(); Array2D <int> array = new Array2D <int>(section, height, width); Assert.AreEqual(1, array[0][1]); Assert.AreEqual(width, array[0].Length); #if !(NETFRAMEWORK || NETSTANDARD2_0 || NETCOREAPP2_0) Index from = 1; Index to = ^ 1; Span <int> span = section.AsSpan; Assert.AreEqual(span.Slice(1, 2).ToArray(), array[0].Slice(1, 2)); Assert.AreEqual(span[(from.Value * width)..^ (to.Value * width)].ToArray(), array[from..to].AsSpan.ToArray());
public override string Translate(SqlCompilerContext context, SqlArray node, ArraySection section) { switch (section) { case ArraySection.Entry: return("ARRAY["); case ArraySection.Exit: return("]"); case ArraySection.EmptyArray: return(string.Format("'{{}}'::{0}[]", TranslateClrType(node.ItemType))); default: throw new ArgumentOutOfRangeException("section"); } }
public Bitmap GetBitmap() { if (glyphs == null) { glyphs = Compressed.GetDecompressedData(); } PixelFormat pixelFormat = PixelFormats.Indexed8; Color[] palette = ImageHelper.GetGrayPalette(8); int stride = ImageHelper.GetStride(pixelFormat, Width); int imageWidth = Width * 16; int imageHeight = Height * (int)Math.Ceiling(glyphs.Count / 16d); int imageStride = ImageHelper.GetStride(pixelFormat, imageWidth); byte[] newData = new byte[imageStride * imageHeight]; for (int i = 0, offset = 0; i < glyphs.Count; i++) { ArraySection <byte> current = new ArraySection <byte>(glyphs[i], 6, Width * Height); // ArraySegment<byte> current = new ArraySegment<byte>(data[i], 6, width * height); // byte[] current = System.ArraySegment< data[i]; for (int y = 0; y < Height; y++) { for (int x = 0; x < stride; x++) { newData[offset + y * imageStride + x] = current[y * stride + x]; } } if ((i + 1) % 16 == 0) { offset += imageStride * (Height - 1) + stride; } else { offset += stride; } } return(new Bitmap(imageWidth, imageHeight, pixelFormat, newData, palette)); }
private void qSort(object obj) { Trace.Assert(obj is ArraySection); ArraySection asec = (ArraySection)obj; T[] arr = asec.arr; int L = asec.L; int R = asec.R; if (L < R) { int piv = L + (R - L) / 2; piv = Partition(arr, L, R, piv); Thread t = new Thread(qSort); t.Start(new ArraySection(arr, L, piv - 1)); qSort(new ArraySection(arr, piv + 1, R)); t.Join(); } }
/// <summary> /// Construct an ArrayBufferObjectInterleaved specifying its item layout on CPU side. /// </summary> /// <param name="arrayItemType"> /// A <see cref="Type"/> describing the type of the array item. /// </param> /// <param name="hint"> /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints. /// </param> public ArrayBufferObjectPacked(Type arrayItemType, BufferObjectHint hint) : base(arrayItemType, hint) { // Get fields for defining array item definition FieldInfo[] arrayItemTypeFields = arrayItemType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (arrayItemTypeFields.Length == 0) { throw new ArgumentException("no public fields", "arrayItemType"); } // Allocate type information arrays _FieldsSize = new uint[arrayItemTypeFields.Length]; _FieldsOffset = new IntPtr[arrayItemTypeFields.Length]; _ClientBufferOffsets = new IntPtr[arrayItemTypeFields.Length]; _BufferOffsets = new IntPtr[arrayItemTypeFields.Length]; // Determine array sections stride int structStride = Marshal.SizeOf(arrayItemType); for (int i = 0; i < arrayItemTypeFields.Length; i++) { FieldInfo arrayItemTypeField = arrayItemTypeFields[i]; ArraySection arraySection = new ArraySection(this, arrayItemTypeField.FieldType); // Store field size: used for re-computing section offsets _FieldsSize[i] = (uint)Marshal.SizeOf(arrayItemTypeField.FieldType); // Store field offset: used for locating field in input arrays _FieldsOffset[i] = Marshal.OffsetOf(arrayItemType, arrayItemTypeField.Name); // Array section offset is re-computed each time the item count is defined arraySection.ItemOffset = IntPtr.Zero; // Determine array section stride arraySection.ItemStride = new IntPtr(_FieldsSize[i]); // Mission Normalized property management: add attributes? arraySection.Normalized = false; ArraySections.Add(arraySection); } // Determine array item size ItemSize = (uint)structStride; }
public static unsafe string ToDecimalValuesString(this byte[] bytes, string separator = ", ") { if (bytes == null) { Throw.ArgumentNullException(Argument.bytes); } if (separator == null) { Throw.ArgumentNullException(Argument.separator); } if (separator.Length == 0 || separator.Any(c => c >= '0' && c <= '9')) { Throw.ArgumentException(Argument.separator, Res.ByteArrayExtensionsSeparatorInvalidDec); } var buf = new ArraySection <char>(bytes.Length * (3 + separator.Length), false); try { fixed(char *pBuf = buf) { var result = new MutableStringBuilder(pBuf, buf.Length); // ReSharper disable once ForCanBeConvertedToForeach - intended, performance for (int i = 0; i < bytes.Length; i++) { if (result.Length != 0) { result.Append(separator); } result.Append(bytes[i]); } return(result.ToString()); } } finally { buf.Release(); } }
public State(Mono.Cecil.MethodDefinition md, int level) { int args = 0; if (md.HasThis) { args++; } args += md.Parameters.Count; int locals = md.Body.Variables.Count; // Create a stack with variables, which will be // bound to phi functions. _stack = new StackQueue <SSA.Value>(); // Allocate parameters, even though we don't what they may be. _arguments = _stack.Section(_stack.Count, args); for (int i = 0; i < args; ++i) { _stack.Push(new SSA.Variable()); } // Allocate local variables. _locals = _stack.Section(_stack.Count, locals); for (int i = 0; i < locals; ++i) { _stack.Push(new SSA.Variable()); } for (int i = _stack.Size(); i < level; ++i) { _stack.Push(new SSA.Variable()); } _bindings = new List <Nesting>(); _bindings.Add(new Nesting()); }
static void Resize(ref ArraySection <T> arr, int new_length) { }
public LValue(StackQueue <ValueBase> stack) { _space = stack.Section(1); _relative = 0; _absolute = _space.Base + _relative; }
public LValue(ArraySection <ValueBase> section, int i) { _space = section; _relative = i; _absolute = _space.Base + _relative; }