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
* Normalizes a list of indices to the interval `[0,max]`.
1874
+
*
1875
+
* ## Notes
1876
+
*
1877
+
* - If provided an out-of-bounds index, the function returns `null`.
1878
+
* - The function mutates the input array, even when provided an out-of-bounds index.
1879
+
*
1880
+
* @param indices - indices
1881
+
* @param max - maximum index
1882
+
* @returns normalized indices or null
1883
+
*
1884
+
* @example
1885
+
* var indices = ns.normalizeIndices( [ -2, 5 ], 10 );
1886
+
* // returns [ 9, 5 ]
1887
+
*
1888
+
* indices = ns.normalizeIndices( [ -2, 15 ], 10 );
1889
+
* // returns null
1890
+
*/
1891
+
normalizeIndices: typeofnormalizeIndices;
1892
+
1868
1893
/**
1869
1894
* Applies a nullary callback and assigns results to elements in an output ndarray.
1870
1895
*
@@ -2662,6 +2687,48 @@ interface Namespace {
2662
2687
*/
2663
2688
sliceTo: typeofsliceTo;
2664
2689
2690
+
/**
2691
+
* Expands the shape of an array to a specified dimensionality by spreading its dimensions to specified dimension indices and inserting dimensions of size one for the remaining dimensions.
2692
+
*
2693
+
* ## Notes
2694
+
*
2695
+
* - Each provided dimension index must reside on the interval `[-ndims, ndims-1]`. If provided a negative dimension index, the position at which to place a respective dimension is computed as `ndims + index`.
2696
+
* - Provided dimension indices must resolve to normalized dimension indices arranged in ascending order.
2697
+
*
2698
+
* @param ndims - number of dimensions in the output array
2699
+
* @param x - input array
2700
+
* @param dims - dimension indices
2701
+
* @returns output array
2702
+
*
2703
+
* @example
2704
+
* var array = require( '@stdlib/ndarray-array' );
2705
+
*
2706
+
* var x = array( [ [ 1, 2 ], [ 3, 4 ] ] );
2707
+
* // returns <ndarray>
2708
+
*
2709
+
* var shx = x.shape;
2710
+
* // returns [ 2, 2 ]
2711
+
*
2712
+
* var y = ns.spreadDimensions( 5, x, [ 1, 3 ] );
2713
+
* // returns <ndarray>
2714
+
*
2715
+
* var shy = y.shape;
2716
+
* // returns [ 1, 2, 1, 2, 1 ]
2717
+
*
2718
+
* var v = y.get( 0, 0, 0, 0, 0 );
2719
+
* // returns 1
2720
+
*
2721
+
* v = y.get( 0, 0, 0, 1, 0 );
2722
+
* // returns 2
2723
+
*
2724
+
* v = y.get( 0, 1, 0, 0, 0 );
2725
+
* // returns 3
2726
+
*
2727
+
* v = y.get( 0, 1, 0, 1, 0 );
2728
+
* // returns 4
2729
+
*/
2730
+
spreadDimensions: typeofspreadDimensions;
2731
+
2665
2732
/**
2666
2733
* Returns the stride along a specified dimension for a provided ndarray.
2667
2734
*
@@ -2865,6 +2932,26 @@ interface Namespace {
2865
2932
*/
2866
2933
ndarray2array: typeofndarray2array;
2867
2934
2935
+
/**
2936
+
* Normalizes a list of indices to the interval `[0,max]`.
2937
+
*
2938
+
* ## Notes
2939
+
*
2940
+
* - If provided an out-of-bounds index, the function normalizes the index to `-1`.
2941
+
*
2942
+
* @param indices - indices
2943
+
* @param max - maximum index
2944
+
* @returns normalized indices
2945
+
*
2946
+
* @example
2947
+
* var indices = ns.toNormalizedIndices( [ -2, 5 ], 10 );
2948
+
* // returns [ 9, 5 ]
2949
+
*
2950
+
* indices = ns.toNormalizedIndices( [ -2, 15 ], 10 );
2951
+
* // returns [ 9, -1 ]
2952
+
*/
2953
+
toNormalizedIndices: typeoftoNormalizedIndices;
2954
+
2868
2955
/**
2869
2956
* Returns a new ndarray where the order of elements of an input ndarray is reversed along each dimension.
2870
2957
*
@@ -2901,6 +2988,26 @@ interface Namespace {
2901
2988
*/
2902
2989
toReversed: typeoftoReversed;
2903
2990
2991
+
/**
2992
+
* Returns a list of unique indices after normalizing to the interval `[0,max]`.
2993
+
*
2994
+
* ## Notes
2995
+
*
2996
+
* - If provided an out-of-bounds index, the function returns `null`.
2997
+
*
2998
+
* @param indices - indices
2999
+
* @param max - maximum index
3000
+
* @returns normalized indices (or null)
3001
+
*
3002
+
* @example
3003
+
* var indices = ns.toUniqueNormalizedIndices( [ -2, 5 ], 10 );
3004
+
* // returns [ 9, 5 ]
3005
+
*
3006
+
* indices = ns.toUniqueNormalizedIndices( [ -2, 15 ], 10 );
0 commit comments