Skip to content

Commit 34551e9

Browse files
committed
feat: add blas/ext/base/dindex-of-row
--- 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: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 13cf096 commit 34551e9

53 files changed

Lines changed: 4913 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 327 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,327 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# dindexOfRow
22+
23+
> Return the index of the first row in a double-precision floating-point input matrix which has the same elements as a provided search vector.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var dindexOfRow = require( '@stdlib/blas/ext/base/dindex-of-row' );
31+
```
32+
33+
#### dindexOfRow( order, M, N, A, LDA, x, strideX, workspace, strideW )
34+
35+
Returns the index of the first row in a double-precision floating-point input matrix which has the same elements as a provided search vector.
36+
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
var Uint8Array = require( '@stdlib/array/uint8' );
40+
41+
/*
42+
A = [
43+
[ 1.0, 2.0 ],
44+
[ 3.0, 4.0 ],
45+
[ 0.0, 0.0 ]
46+
]
47+
*/
48+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] );
49+
50+
var x = new Float64Array( [ 3.0, 4.0 ] );
51+
var workspace = new Uint8Array( 3 );
52+
var out = dindexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
53+
// returns 1
54+
```
55+
56+
The function has the following parameters:
57+
58+
- **order**: storage layout.
59+
- **M**: number of rows in `A`.
60+
- **N**: number of columns in `A`.
61+
- **A**: input matrix stored as a [`Float64Array`][mdn-float64array].
62+
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
63+
- **x**: search vector stored as a [`Float64Array`][mdn-float64array].
64+
- **strideX**: stride length of `x`.
65+
- **workspace**: workspace array stored as a [`Uint8Array`][mdn-uint8array] for tracking row match candidates.
66+
- **strideW**: stride length of `workspace`.
67+
68+
If the function is unable to find a matching row, the function returns `-1`.
69+
70+
```javascript
71+
var Float64Array = require( '@stdlib/array/float64' );
72+
var Uint8Array = require( '@stdlib/array/uint8' );
73+
74+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] );
75+
76+
var x = new Float64Array( [ -3.0, -4.0 ] );
77+
var workspace = new Uint8Array( 3 );
78+
var out = dindexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
79+
// returns -1
80+
```
81+
82+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
83+
84+
<!-- eslint-disable stdlib/capitalized-comments -->
85+
86+
```javascript
87+
var Float64Array = require( '@stdlib/array/float64' );
88+
var Uint8Array = require( '@stdlib/array/uint8' );
89+
90+
// Initial arrays:
91+
var A0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] );
92+
var x0 = new Float64Array( [ 0.0, 3.0, 4.0 ] );
93+
94+
// Create offset views:
95+
var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
96+
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
97+
98+
var workspace = new Uint8Array( 3 );
99+
var out = dindexOfRow( 'row-major', 3, 2, A1, 2, x1, 1, workspace, 1 );
100+
// returns 1
101+
```
102+
103+
<!-- lint disable maximum-heading-length -->
104+
105+
#### dindexOfRow.ndarray( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX, workspace, strideW, offsetW )
106+
107+
<!-- lint enable maximum-heading-length -->
108+
109+
Returns the index of the first row in a double-precision floating-point input matrix which has the same elements as a provided search vector using alternative indexing semantics.
110+
111+
```javascript
112+
var Float64Array = require( '@stdlib/array/float64' );
113+
var Uint8Array = require( '@stdlib/array/uint8' );
114+
115+
/*
116+
A = [
117+
[ 1.0, 2.0 ],
118+
[ 3.0, 4.0 ],
119+
[ 0.0, 0.0 ]
120+
]
121+
*/
122+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] );
123+
124+
var x = new Float64Array( [ 3.0, 4.0 ] );
125+
var workspace = new Uint8Array( 3 );
126+
var out = dindexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
127+
// returns 1
128+
```
129+
130+
The function has the following parameters:
131+
132+
- **M**: number of rows in `A`.
133+
- **N**: number of columns in `A`.
134+
- **A**: input matrix stored as a [`Float64Array`][mdn-float64array].
135+
- **strideA1**: stride of the first dimension of `A`.
136+
- **strideA2**: stride of the second dimension of `A`.
137+
- **offsetA**: starting index for `A`.
138+
- **x**: search vector stored as a [`Float64Array`][mdn-float64array].
139+
- **strideX**: stride length of `x`.
140+
- **offsetX**: starting index for `x`.
141+
- **workspace**: workspace array stored as a [`Uint8Array`][mdn-uint8array] for tracking row match candidates.
142+
- **strideW**: stride length of `workspace`.
143+
- **offsetW**: starting index for `workspace`.
144+
145+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example,
146+
147+
```javascript
148+
var Float64Array = require( '@stdlib/array/float64' );
149+
var Uint8Array = require( '@stdlib/array/uint8' );
150+
151+
/*
152+
A = [
153+
[ 1.0, 2.0 ],
154+
[ 3.0, 4.0 ],
155+
[ 0.0, 0.0 ]
156+
]
157+
*/
158+
var A = new Float64Array( [ 0.0, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ] );
159+
160+
var x = new Float64Array( [ 0.0, 3.0, 4.0 ] );
161+
var workspace = new Uint8Array( 3 );
162+
var out = dindexOfRow.ndarray( 3, 2, A, 2, 1, 1, x, 1, 1, workspace, 1, 0 );
163+
// returns 1
164+
```
165+
166+
</section>
167+
168+
<!-- /.usage -->
169+
170+
<section class="notes">
171+
172+
## Notes
173+
174+
- When searching for a matching row, the function checks for equality using the strict equality operator `===`. As a consequence, `NaN` values are considered distinct, and `-0` and `+0` are considered the same.
175+
176+
</section>
177+
178+
<!-- /.notes -->
179+
180+
<section class="examples">
181+
182+
## Examples
183+
184+
<!-- eslint-disable max-len -->
185+
186+
<!-- eslint no-undef: "error" -->
187+
188+
```javascript
189+
var Float64Array = require( '@stdlib/array/float64' );
190+
var Uint8Array = require( '@stdlib/array/uint8' );
191+
var ndarray2array = require( '@stdlib/ndarray/base/to-array' );
192+
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' );
193+
var dindexOfRow = require( '@stdlib/blas/ext/base/dindex-of-row' );
194+
195+
var shape = [ 3, 3 ];
196+
var order = 'row-major';
197+
var strides = shape2strides( shape, order );
198+
199+
var A = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 0.0, 0.0, 0.0 ] );
200+
console.log( ndarray2array( A, shape, strides, 0, order ) );
201+
202+
var x = new Float64Array( [ 4.0, 5.0, 6.0 ] );
203+
console.log( x );
204+
205+
var workspace = new Uint8Array( shape[ 0 ] );
206+
207+
var out = dindexOfRow( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], x, 1, workspace, 1 );
208+
console.log( out );
209+
```
210+
211+
</section>
212+
213+
<!-- /.examples -->
214+
215+
<!-- C interface documentation. -->
216+
217+
<section class="C">
218+
219+
## C APIs
220+
221+
### Usage
222+
223+
```c
224+
#include "stdlib/blas/ext/base/dindex_of_row.h"
225+
```
226+
227+
<!-- lint disable maximum-heading-length -->
228+
229+
#### stdlib_strided_dindex_of_row( order, M, N, \*A, LDA, \*X, strideX, \*workspace, strideW )
230+
231+
<!-- lint enable maximum-heading-length -->
232+
233+
Returns the index of the first row in a double-precision floating-point input matrix which has the same elements as a provided search vector.
234+
235+
```c
236+
#include "stdlib/blas/base/shared.h"
237+
#include <stdint.h>
238+
239+
const double A[] = { 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 };
240+
const double x[] = { 3.0, 4.0 };
241+
uint8_t workspace[ 3 ];
242+
243+
int idx = stdlib_strided_dindex_of_row( CblasRowMajor, 3, 2, A, 2, x, 1, workspace, 1 );
244+
// returns 1
245+
```
246+
247+
The function accepts the following arguments:
248+
249+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
250+
- **M**: `[in] CBLAS_INT` number of rows in `A`.
251+
- **N**: `[in] CBLAS_INT` number of columns in `A`.
252+
- **A**: `[in] double*` input matrix.
253+
- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
254+
- **X**: `[in] double*` search vector.
255+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
256+
- **workspace**: `[inout] uint8_t*` workspace array for tracking row match candidates.
257+
- **strideW**: `[in] CBLAS_INT` stride length for `workspace`.
258+
259+
```c
260+
CBLAS_INT stdlib_strided_dindex_of_row( const CBLAS_LAYOUT order, const CBLAS_INT M, const CBLAS_INT N, const double *A, const CBLAS_INT LDA, const double *X, const CBLAS_INT strideX, uint8_t *workspace, const CBLAS_INT strideW );
261+
```
262+
263+
<!-- lint disable maximum-heading-length -->
264+
265+
#### stdlib_strided_dindex_of_row_ndarray( M, N, \*A, strideA1, strideA2, offsetA, \*X, strideX, offsetX, \*workspace, strideW, offsetW )
266+
267+
<!-- lint enable maximum-heading-length -->
268+
269+
Returns the index of the first row in a double-precision floating-point input matrix which has the same elements as a provided search vector using alternative indexing semantics.
270+
271+
```c
272+
#include <stdint.h>
273+
274+
const double A[] = { 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 };
275+
const double x[] = { 3.0, 4.0 };
276+
uint8_t workspace[ 3 ];
277+
278+
int idx = stdlib_strided_dindex_of_row_ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
279+
// returns 1
280+
```
281+
282+
The function accepts the following arguments:
283+
284+
- **M**: `[in] CBLAS_INT` number of rows in `A`.
285+
- **N**: `[in] CBLAS_INT` number of columns in `A`.
286+
- **A**: `[in] double*` input matrix.
287+
- **strideA1**: `[in] CBLAS_INT` stride of the first dimension of `A`.
288+
- **strideA2**: `[in] CBLAS_INT` stride of the second dimension of `A`.
289+
- **offsetA**: `[in] CBLAS_INT` index offset for `A`.
290+
- **X**: `[in] double*` search vector.
291+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
292+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
293+
- **workspace**: `[inout] uint8_t*` workspace array for tracking row match candidates.
294+
- **strideW**: `[in] CBLAS_INT` stride length for `workspace`.
295+
- **offsetW**: `[in] CBLAS_INT` starting index for `workspace`.
296+
297+
```c
298+
CBLAS_INT stdlib_strided_dindex_of_row_ndarray( const CBLAS_INT M, const CBLAS_INT N, const double *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, uint8_t *workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW );
299+
```
300+
301+
</section>
302+
303+
<!-- /.C -->
304+
305+
<!-- /.examples -->
306+
307+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
308+
309+
<section class="related">
310+
311+
</section>
312+
313+
<!-- /.related -->
314+
315+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
316+
317+
<section class="links">
318+
319+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
320+
321+
[mdn-float64array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float64Array
322+
323+
[mdn-uint8array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array
324+
325+
</section>
326+
327+
<!-- /.links -->

0 commit comments

Comments
 (0)