static void SubViewAccess(ArrayView <int> view) { // Creates a sub view that represents a view from index 10 to view.Length - 1 var subView = view.GetSubView(10); Debug.Assert(subView.Length == view.Length - 10); // Write value to sub view and output value subView[0] = 42; Console.WriteLine($"Value of sub view at index 0: {subView[0]} = value of view at index 10: {view[10]}"); // Creates a sub view that represents a view from index 10 with length 20 // (up to index 10 + 20) var subView2 = view.GetSubView(10, 20); Debug.Assert(subView2.Length == 20); Console.WriteLine($"Value of sub view 2 at index 0: {subView2[0]} = value of view at index 10: {view[10]}"); // Creates a sub view that represents a view from index 20 with length 2 var subView3 = subView2.GetSubView(10, 2); subView3[1] = 23; // An access of the form subView3[2] will trigger an OutOfBounds assertion Debug.Assert(subView3.Length == 2); Console.WriteLine($"Value of sub view 3 at index 1: {subView3[1]} = value of view at index 21: {view[21]}"); }
internal static void ArrayViewVectorizedIOKernel <T, T2>( Index1 index, ArrayView <T> source, ArrayView <T> target) where T : unmanaged where T2 : unmanaged { // Use compile-time known offsets to test the internal alignment rules var nonVectorAlignedSource = source.GetSubView(1, 2); var nonVectorAlignedCastedSource = nonVectorAlignedSource.Cast <T2>(); var nonVectorAlignedTarget = target.GetSubView(1, 2); var nonVectorAlignedTargetCasted = nonVectorAlignedTarget.Cast <T2>(); // Load from source and write to target T2 data = nonVectorAlignedCastedSource[index]; nonVectorAlignedTargetCasted[index] = data; // Perform the same operations with compile-time known offsets var vectorAlignedSource = source.GetSubView(2, 2); var vectorAlignedCastedSource = vectorAlignedSource.Cast <T2>(); var vectorAlignedTarget = target.GetSubView(2, 2); var vectorAlignedTargetCasted = vectorAlignedTarget.Cast <T2>(); // Load from source and write to target T2 data2 = vectorAlignedCastedSource[index]; vectorAlignedTargetCasted[index] = data2; }
internal static void ArrayViewGetSubViewImplicitLengthKernel( Index1 index, ArrayView <int> length, ArrayView <int> source, int subViewOffset) { var subView = source.GetSubView(subViewOffset); length[index] = subView.IntLength; }
internal static void ArrayViewGetSubViewKernel( Index1 index, ArrayView <int> data, ArrayView <int> length, ArrayView <int> source, int subViewOffset, int subViewLength) { var subView = source.GetSubView(subViewOffset, subViewLength); data[index] = subView[0]; length[index] = subView.IntLength; }
/// <summary> /// Returns a sub segment of an existing segment. /// </summary> public BinaryStringSegment Subsegment(int index, int length) { return(m_isAscii ? new BinaryStringSegment(m_value.GetSubView(index, length), m_isAscii) : new BinaryStringSegment(m_value.GetSubView(index * 2, length * 2), m_isAscii)); }
public PipDataEntryList GetSubView(int index) { return(new PipDataEntryList(m_bytes.GetSubView(index * PipDataEntry.BinarySize))); }