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: lib/node_modules/@stdlib/blas/ext/sorthp/README.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ var bool = ( x === y );
53
53
The function has the following parameters:
54
54
55
55
-**x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a numeric or "generic" [data type][@stdlib/ndarray/dtypes].
56
-
-**sortOrder**: sort order (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a real or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] sort order must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] sort order must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the sort order is `1` (i.e., increasing order).
56
+
-**sortOrder**: sort order (_optional_). May be either a scalar value, string, or an [ndarray][@stdlib/ndarray/ctor] having a real or "generic" [data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor] sort order must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] sort order must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the sort order is `1` (i.e., increasing order).
57
57
-**options**: function options (_optional_).
58
58
59
59
The function accepts the following options:
@@ -75,6 +75,29 @@ var arr = ndarray2array( y );
75
75
// returns [ 2.0, -1.0, -3.0 ]
76
76
```
77
77
78
+
Alternatively, you can also provide a string literal to specify the sort order.
79
+
80
+
```javascript
81
+
var ndarray2array =require( '@stdlib/ndarray/to-array' );
82
+
var array =require( '@stdlib/ndarray/array' );
83
+
84
+
var x =array( [ -1.0, 2.0, -3.0 ] );
85
+
86
+
// Sort in ascending order:
87
+
var y =sorthp( x, 'asc' );
88
+
// returns <ndarray>
89
+
90
+
var arr =ndarray2array( y );
91
+
// returns [ -3.0, -1.0, 2.0 ]
92
+
93
+
// Sort in descending order:
94
+
y =sorthp( x, 'descending' );
95
+
// returns <ndarray>
96
+
97
+
arr =ndarray2array( y );
98
+
// returns [ 2.0, -1.0, -3.0 ]
99
+
```
100
+
78
101
By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option.
79
102
80
103
```javascript
@@ -108,6 +131,7 @@ v = ndarray2array( y );
108
131
109
132
- The input [ndarray][@stdlib/ndarray/ctor] is sorted **in-place** (i.e., the input [ndarray][@stdlib/ndarray/ctor] is **mutated**).
110
133
- If `sortOrder < 0.0`, the input [ndarray][@stdlib/ndarray/ctor] is sorted in **decreasing** order. If `sortOrder > 0.0`, the input [ndarray][@stdlib/ndarray/ctor] is sorted in **increasing** order. If `sortOrder == 0.0`, the input [ndarray][@stdlib/ndarray/ctor] is left unchanged.
134
+
- If `sortOrder === asc` or `sortOrder === ascending`, the input [ndarray][@stdlib/ndarray/ctor] is sorted in **increasing** order. If `sortOrder === desc` or `sortOrder === descending`, the input [ndarray][@stdlib/ndarray/ctor] is sorted in **decreasing** order.
111
135
- The function iterates over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before sorting.
thrownewTypeError(format('invalid argument. Second argument must be a valid sort order. Value: `%s`.',o));
154
+
}
155
+
if(hasOwnProp(opts,'dims')){
156
+
sh=nonCoreShape(getShape(x),opts.dims);
157
+
}else{
158
+
sh=[];
159
+
}
160
+
o=broadcastScalar(o,'generic',sh,getOrder(x));
133
161
}else{
134
-
thrownewTypeError(format('invalid argument. Second argument must be either an ndarray or a numeric scalar value. Value: `%s`.',o));
162
+
thrownewTypeError(format('invalid argument. Second argument must be either an ndarray, a numeric scalar value, or a valid sort order string. Value: `%s`.',o));
0 commit comments