You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/NumSharp.Core/View/Shape.cs
+29-4Lines changed: 29 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -389,6 +389,12 @@ public int TransformOffset(int offset)
389
389
390
390
/// <summary>
391
391
/// Get offset index out of coordinate indices.
392
+
///
393
+
/// The offset is the absolute offset in memory for the given coordinates.
394
+
/// Even for shapes that were sliced and reshaped after slicing and sliced again (and so forth)
395
+
/// this returns the absolute memory offset.
396
+
///
397
+
/// Note: the inverse operation to this is GetCoordinatesFromAbsoluteIndex
392
398
/// </summary>
393
399
/// <param name="indices">The coordinates to turn into linear offset</param>
394
400
/// <returns>The index in the memory block that refers to a specific value.</returns>
@@ -878,9 +884,14 @@ private int GetOffset_broadcasted_1D(int index)
878
884
}
879
885
880
886
/// <summary>
881
-
/// Transforms offset index in this shape into coordinates that matches this shape.
887
+
/// Gets coordinates in this shape from index in this shape (slicing is ignored).
888
+
/// Example: Shape (2,3)
889
+
/// 0 => [0, 0]
890
+
/// 1 => [0, 1]
891
+
/// ...
892
+
/// 6 => [1, 2]
882
893
/// </summary>
883
-
/// <param name="offset"></param>
894
+
/// <param name="offset">the index if you would iterate from 0 to shape.size in row major order</param>
884
895
/// <returns></returns>
885
896
[MethodImpl((MethodImplOptions)768)]
886
897
publicint[]GetCoordinates(intoffset)
@@ -930,8 +941,22 @@ public int[] GetCoordinates(int offset)
930
941
returncoords;
931
942
}
932
943
933
-
/// <summary>
934
-
/// Retrievs the coordinates in current shape (potentially sliced and reshaped) from index in original array
944
+
/// <summary>
945
+
/// Retrievs the coordinates in current shape (potentially sliced and reshaped) from index in original array.
946
+
/// Note: this is the inverse operation of GetOffset
947
+
/// Example: Shape a (2,3) => sliced to b (2,2) by a[:, 1:]
948
+
/// The absolute indices in a are:
949
+
/// [0, 1, 2,
950
+
/// 3, 4, 5]
951
+
/// The absolute indices in b are:
952
+
/// [1, 2,
953
+
/// 4, 5]
954
+
/// Note: due to slicing the absolute indices (offset in memory) are different from what GetCoordinates would return, which are relative indices in the shape.
0 commit comments