Skip to content

Commit d386c74

Browse files
committed
docs: update README and fix option handling
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent fad9cf7 commit d386c74

File tree

3 files changed

+37
-30
lines changed

3 files changed

+37
-30
lines changed

lib/node_modules/@stdlib/blas/ext/index-of/README.md

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# indexOf
2222

23-
> Return the first index of a specified search element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.
23+
> Return the first index of a specified search element along an [ndarray][@stdlib/ndarray/ctor] dimension.
2424
2525
<section class="usage">
2626

@@ -32,7 +32,7 @@ var indexOf = require( '@stdlib/blas/ext/index-of' );
3232

3333
#### indexOf( x, searchElement\[, fromIndex]\[, options] )
3434

35-
Returns the first index of a specified search element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.
35+
Returns the first index of a specified search element along an [ndarray][@stdlib/ndarray/ctor] dimension.
3636

3737
```javascript
3838
var array = require( '@stdlib/ndarray/array' );
@@ -51,18 +51,18 @@ var idx = out.get();
5151

5252
The function has the following parameters:
5353

54-
- **x**: input [ndarray][@stdlib/ndarray/ctor].
55-
- **searchElement**: element in an input [ndarray][@stdlib/ndarray/ctor] for which to find an index. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] same as the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. 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]`, the search element [ndarray][@stdlib/ndarray/ctor] 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], the search element [ndarray][@stdlib/ndarray/ctor] must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor].
56-
- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an `integer` 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] containing the index from which to begin searching 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] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the index from which to begin searching is `0`.
54+
- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension.
55+
- **searchElement**: search element. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`.
56+
- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index 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 non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). Default: `0`.
5757
- **options**: function options (_optional_).
5858

5959
The function accepts the following options:
6060

61-
- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be an integer or generic [data type][@stdlib/ndarray/dtypes].
62-
- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor].
61+
- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be an integer index or generic [data type][@stdlib/ndarray/dtypes].
62+
- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`.
6363
- **keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`.
6464

65-
If the function is unable to find a search element, the function returns `-1`.
65+
If the function is unable to find a search element along an [ndarray][@stdlib/ndarray/ctor], the corresponding element in the returned [ndarray][@stdlib/ndarray/ctor] is `-1`.
6666

6767
```javascript
6868
var array = require( '@stdlib/ndarray/array' );
@@ -79,7 +79,7 @@ var idx = out.get();
7979
// returns -1
8080
```
8181

82-
By default, the function uses `0` as the index from which to begin searching. To begin searching from a different index, provide the `fromIndex` argument.
82+
By default, the function begins searching from the first element along the reduction dimension. To begin searching from a different index, provide a `fromIndex` argument.
8383

8484
```javascript
8585
var array = require( '@stdlib/ndarray/array' );
@@ -96,7 +96,7 @@ var idx = out.get();
9696
// returns 4
9797
```
9898

99-
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.
99+
By default, the function performs the operation over elements in the last dimension. To perform the operation over a different dimension, provide a `dim` option.
100100

101101
```javascript
102102
var ndarray2array = require( '@stdlib/ndarray/to-array' );
@@ -105,30 +105,27 @@ var array = require( '@stdlib/ndarray/array' );
105105
var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] );
106106

107107
var out = indexOf( x, -3.0, {
108-
'dims': [ 0 ]
108+
'dim': 0
109109
});
110110
// returns <ndarray>
111111

112112
var idx = ndarray2array( out );
113113
// returns [ 1, -1 ]
114114
```
115115

116-
By default, the function returns an [`ndarray`][@stdlib/ndarray/ctor] having a shape matching only the non-reduced dimensions of the input [`ndarray`][@stdlib/ndarray/ctor] (i.e., the reduced dimensions are dropped). To include the reduced dimensions as singleton dimensions in the output [`ndarray`][@stdlib/ndarray/ctor], set the `keepdims` option to `true`.
116+
By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`.
117117

118118
```javascript
119119
var array = require( '@stdlib/ndarray/array' );
120120
var ndarray2array = require( '@stdlib/ndarray/to-array' );
121121

122-
// Create an input ndarray:
123122
var x = array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] );
124-
// returns <ndarray>
125123

126124
var opts = {
127-
'dims': [ 0 ],
125+
'dim': 0,
128126
'keepdims': true
129127
};
130128

131-
// Find index:
132129
var out = indexOf( x, -3.0, opts );
133130
// returns <ndarray>
134131

@@ -146,17 +143,17 @@ var array = require( '@stdlib/ndarray/array' );
146143
var x = array( [ 1.0, 2.0, 3.0, 4.0 ] );
147144

148145
var idx = indexOf( x, 2.0, {
149-
'dtype': 'int32'
146+
'dtype': 'generic'
150147
});
151148
// returns <ndarray>
152149

153150
var dt = dtype( idx );
154-
// returns 'int32'
151+
// returns 'generic'
155152
```
156153

157154
#### indexOf.assign( x, searchElement\[, fromIndex], out\[, options] )
158155

159-
Returns the first index of a specified search element along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor].
156+
Returns the first index of a specified search element along an [ndarray][@stdlib/ndarray/ctor] dimension and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor].
160157

161158
```javascript
162159
var array = require( '@stdlib/ndarray/array' );
@@ -179,15 +176,15 @@ var bool = ( out === y );
179176

180177
The method has the following parameters:
181178

182-
- **x**: input [ndarray][@stdlib/ndarray/ctor].
183-
- **searchElement**: element in an input [ndarray][@stdlib/ndarray/ctor] for which to find an index. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] same as the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. 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]`, the search element [ndarray][@stdlib/ndarray/ctor] 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] initial value must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor].
184-
- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an `integer` 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] containing the index from which to begin searching 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] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the index from which to begin searching is `0`.
185-
- **out**: output [ndarray][@stdlib/ndarray/ctor]. Must have an `integer` or `generic` [data type][@stdlib/ndarray/dtypes].
179+
- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension.
180+
- **searchElement**: search element. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`.
181+
- **fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index 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 non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). Default: `0`.
182+
- **out**: output [ndarray][@stdlib/ndarray/ctor].
186183
- **options**: function options (_optional_).
187184

188185
The method accepts the following options:
189186

190-
- **dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor].
187+
- **dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`.
191188

192189
</section>
193190

@@ -197,7 +194,8 @@ The method accepts the following options:
197194

198195
## Notes
199196

200-
- Both functions iterate 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 searching for an index.
197+
- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor].
198+
- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes].
201199

202200
</section>
203201

@@ -224,9 +222,9 @@ var xbuf = discreteUniform( 10, 0, 20, {
224222
var x = new ndarray( 'float64', xbuf, [ 5, 2 ], [ 2, 1 ], 0, 'row-major' );
225223
console.log( ndarray2array( x ) );
226224

227-
// Find index:
225+
// Perform operation:
228226
var idx = indexOf( x, 10.0, {
229-
'dims': [ 0 ]
227+
'dim': 0
230228
});
231229

232230
// Print the results:

lib/node_modules/@stdlib/blas/ext/index-of/docs/repl.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,16 @@
3030
the value must have a shape which is broadcast compatible with the non-
3131
reduced dimensions of the input ndarray. For example, given the input
3232
shape `[2, 3, 4]` and `options.dim=0`, a provided ndarray must have a
33-
shape which is broadcast-compatible with the shape `[3, 4]`. Default: 0.
33+
shape which is broadcast-compatible with the shape `[3, 4]`. If provided
34+
a negative integer, the index at which to begin searching along a
35+
dimension is determined by counting backward from the last element
36+
(where -1 refers to the last element). Default: 0.
3437

3538
options: Object (optional)
3639
Function options.
3740

3841
options.dtype: string (optional)
39-
Output array data type. Must be an integer or "generic" data type.
42+
Output array data type. Must be an integer index or "generic" data type.
4043

4144
options.dim: integer (optional)
4245
Dimension over which to perform a reduction. If provided a negative
@@ -92,7 +95,10 @@
9295
the value must have a shape which is broadcast compatible with the non-
9396
reduced dimensions of the input ndarray. For example, given the input
9497
shape `[2, 3, 4]` and `options.dim=0`, a provided ndarray must have a
95-
shape which is broadcast-compatible with the shape `[3, 4]`. Default: 0.
98+
shape which is broadcast-compatible with the shape `[3, 4]`. If provided
99+
a negative integer, the index at which to begin searching along a
100+
dimension is determined by counting backward from the last element
101+
(where -1 refers to the last element). Default: 0.
96102

97103
out: ndarray
98104
Output array.

lib/node_modules/@stdlib/blas/ext/index-of/lib/main.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ function indexOf( x, searchElement, fromIndex ) {
171171
if ( hasOwnProp( options, 'keepdims' ) ) {
172172
opts.keepdims = options.keepdims;
173173
}
174+
if ( hasOwnProp( options, 'dtype' ) ) {
175+
opts.dtype = options.dtype;
176+
}
174177
// Resolve the list of non-reduced dimensions:
175178
sh = getShape( x );
176179
if ( sh.length < 1 ) {

0 commit comments

Comments
 (0)