Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 72 additions & 13 deletions lib/node_modules/@stdlib/blas/ext/base/gindex-of-row/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ limitations under the License.

> Return the index of the first row in an input matrix which has the same elements as a provided search vector.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage
Expand All @@ -30,7 +36,7 @@ limitations under the License.
var gindexOfRow = require( '@stdlib/blas/ext/base/gindex-of-row' );
```

#### gindexOfRow( order, M, N, A, LDA, x, strideX )
#### gindexOfRow( order, M, N, A, LDA, x, strideX, workspace, strideW )

Returns the index of the first row in an input matrix which has the same elements as a provided search vector.

Expand All @@ -45,7 +51,8 @@ Returns the index of the first row in an input matrix which has the same element
var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];

var x = [ 3.0, 4.0 ];
var out = gindexOfRow( 'row-major', 3, 2, A, 2, x, 1 );
var workspace = [ 0, 0, 0 ];
var out = gindexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
// returns 1
```

Expand All @@ -55,17 +62,38 @@ The function has the following parameters:
- **M**: number of rows in `A`.
- **N**: number of columns in `A`.
- **A**: input matrix as a linear array.
- **LDA**: stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **LDA**: stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **x**: search vector.
- **strideX**: stride length of `x`.
- **strideX**: stride length for `x`.
- **workspace**: workspace array for tracking row match candidates. This parameter is ignored if the input matrix is stored in row-major order.
- **strideW**: stride length for `workspace`.

When an input matrix is stored in row-major order, the workspace parameter is ignored, and, thus, one may provide an empty workspace array.

```javascript
/*
A = [
[ 1.0, 2.0 ],
[ 3.0, 4.0 ],
[ 0.0, 0.0 ]
]
*/
var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];

var x = [ 3.0, 4.0 ];
var workspace = [];
var out = gindexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
// returns 1
```

If the function is unable to find a matching row, the function returns `-1`.

```javascript
var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];

var x = [ -3.0, -4.0 ];
var out = gindexOfRow( 'row-major', 3, 2, A, 2, x, 1 );
var workspace = [ 0, 0, 0 ];
var out = gindexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
// returns -1
```

Expand All @@ -84,11 +112,16 @@ var x0 = new Float64Array( [ 9999.0, 3.0, 4.0 ] );
var A1 = new Float64Array( A0.buffer, A0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var out = gindexOfRow( 'row-major', 3, 2, A1, 2, x1, 1 );
var workspace = [ 0, 0, 0 ];
var out = gindexOfRow( 'row-major', 3, 2, A1, 2, x1, 1, workspace, 1 );
// returns 1
```

#### gindexOfRow.ndarray( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX )
<!-- lint disable maximum-heading-length -->

#### gindexOfRow.ndarray( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX, workspace, strideW, offsetW )

<!-- lint enable maximum-heading-length -->

Returns the index of the first row in an input matrix which has the same elements as a provided search vector using alternative indexing semantics.

Expand All @@ -103,7 +136,8 @@ Returns the index of the first row in an input matrix which has the same element
var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];

var x = [ 3.0, 4.0 ];
var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 );
var workspace = [ 0, 0, 0 ];
var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
// returns 1
```

Expand All @@ -112,12 +146,33 @@ The function has the following parameters:
- **M**: number of rows in `A`.
- **N**: number of columns in `A`.
- **A**: input matrix as a linear array.
- **strideA1**: stride of the first dimension of `A`.
- **strideA2**: stride of the second dimension of `A`.
- **strideA1**: stride length for the first dimension of `A`.
- **strideA2**: stride length for the second dimension of `A`.
- **offsetA**: starting index for `A`.
- **x**: search vector.
- **strideX**: stride length of `x`.
- **strideX**: stride length for `x`.
- **offsetX**: starting index for `x`.
- **workspace**: workspace array for tracking row match candidates. This parameter is ignored if the input matrix is stored in row-major order.
- **strideW**: stride length for `workspace`.
- **offsetW**: starting index for `workspace`.

When an input matrix is stored in row-major order, the workspace parameter is ignored, and, thus, one may provide an empty workspace array.

```javascript
/*
A = [
[ 1.0, 2.0 ],
[ 3.0, 4.0 ],
[ 0.0, 0.0 ]
]
*/
var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];

var x = [ 3.0, 4.0 ];
var workspace = [];
var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
// returns 1
```

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,

Expand All @@ -132,7 +187,8 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the
var A = [ 9999.0, 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];

var x = [ 9999.0, 3.0, 4.0 ];
var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 1, x, 1, 1 );
var workspace = [ 0, 0, 0 ];
var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 1, x, 1, 1, workspace, 1, 0 );
// returns 1
```

Expand All @@ -144,6 +200,7 @@ var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 1, x, 1, 1 );

## Notes

- If `M <= 0` or `N <= 0`, both functions return `-1`.
- 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.
- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).

Expand Down Expand Up @@ -174,7 +231,9 @@ console.log( ndarray2array( A, shape, strides, 0, order ) );
var x = [ 4.0, 5.0, 6.0 ];
console.log( x );

var out = gindexOfRow( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], x, 1, 0 );
var workspace = [ 0, 0, 0 ];

var out = gindexOfRow( order, shape[ 0 ], shape[ 1 ], A, strides[ 0 ], x, 1, workspace, 1 );
console.log( out );
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var LAYOUTS = [
* @returns {Function} benchmark function
*/
function createBenchmark( order, N ) {
var workspace = zeros( N, 'generic' );
var A = zeros( N*N, 'generic' );
var x = zeros( N, 'generic' );
return benchmark;
Expand All @@ -66,7 +67,7 @@ function createBenchmark( order, N ) {
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x[ N-1 ] += 1;
z = gindexOfRow( order, N, N, A, N, x, 1 );
z = gindexOfRow( order, N, N, A, N, x, 1, workspace, 1 );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var LAYOUTS = [
* @returns {Function} benchmark function
*/
function createBenchmark( order, N ) {
var workspace = zeros( N, 'generic' );
var A = zeros( N*N, 'generic' );
var x = zeros( N, 'generic' );
return benchmark;
Expand Down Expand Up @@ -77,7 +78,7 @@ function createBenchmark( order, N ) {
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x[ N-1 ] += 1;
z = gindexOfRow( N, N, A, sa1, sa2, 0, x, 1, 0 );
z = gindexOfRow( N, N, A, sa1, sa2, 0, x, 1, 0, workspace, 1, 0 );
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
49 changes: 34 additions & 15 deletions lib/node_modules/@stdlib/blas/ext/base/gindex-of-row/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

{{alias}}( order, M, N, A, LDA, x, strideX )
{{alias}}( order, M, N, A, LDA, x, strideX, workspace, strideW )
Returns the index of the first row in an input matrix which has the same
elements as a provided search vector.

Expand All @@ -25,15 +25,22 @@
Input matrix `A`.

LDA: integer
Stride of the first dimension of `A` (a.k.a., leading dimension of the
matrix `A`).
Stride length for the first dimension of `A` (a.k.a., leading dimension
of the matrix `A`).

x: Array|TypedArray
Search vector.

strideX:
strideX: integer
Stride length for `x`.

workspace: Array|TypedArray
Workspace array for tracking row match candidates. This parameter is
ignored if the input matrix is stored in row-major order.

strideW: integer
Stride length for `workspace`.

Returns
-------
out: integer
Expand All @@ -43,11 +50,12 @@
--------
> var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];
> var x = [ 3.0, 4.0 ];
> {{alias}}( 'row-major', 2, 2, A, 2, x, 1 )
> var w = [ 0, 0, 0 ];
> {{alias}}( 'row-major', 3, 2, A, 2, x, 1, w, 1 )
1


{{alias}}.ndarray( M, N, A, strideA1, strideA2, offsetA, x, strideX, offsetX )
{{alias}}.ndarray( M, N, A, sa1, sa2, oa, x, sx, ox, w, sw, ow )
Returns the index of the first row in an input matrix which has the same
elements as a provided search vector using alternative indexing semantics.

Expand All @@ -69,34 +77,45 @@
A: Array|TypedArray
Input matrix `A`.

strideA1: integer
Stride of the first dimension of `A`.
sa1: integer
Stride length for the first dimension of `A`.

strideA2: integer
Stride of the second dimension of `A`.
sa2: integer
Stride length for the second dimension of `A`.

offsetA: integer
oa: integer
Starting index for `A`.

x: Array|TypedArray
Search vector.

strideX:
sx: integer
Stride length for `x`.

offsetX:
ox: integer
Starting index for `x`.

w: Array|TypedArray
Workspace array for tracking row match candidates. This parameter is
ignored if the input matrix is stored in row-major order.

sw: integer
Stride length for `w`.

ow: integer
Starting index for `w`.

Returns
-------
out: integer
Row index.

Examples
--------
> var A =[ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];
> var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];
> var x = [ 3.0, 4.0 ];
> {{alias}}.ndarray( 2, 2, A, 2, 1, 0, x, 1, 0 )
> var w = [ 0, 0, 0 ];
> {{alias}}.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, w, 1, 0 )
1

See Also
Expand Down
Loading
Loading