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
68 changes: 60 additions & 8 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 @@ -40,7 +40,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 @@ -55,7 +55,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 @@ -68,14 +69,35 @@ The function has the following parameters:
- **LDA**: stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
- **x**: search vector.
- **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 @@ -94,11 +116,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 @@ -113,7 +140,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 @@ -128,6 +156,27 @@ The function has the following parameters:
- **x**: search vector.
- **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 @@ -142,7 +191,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 Down Expand Up @@ -189,7 +239,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
41 changes: 30 additions & 11 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 Down Expand Up @@ -31,9 +31,16 @@
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
sa1: integer
Stride length for the first dimension of `A`.

strideA2: integer
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import { Layout } from '@stdlib/types/blas';
*/
type InputArray = Collection<unknown> | AccessorArrayLike<unknown>;

/**
* Workspace array.
*/
type WorkspaceArray = Collection<unknown> | AccessorArrayLike<unknown>;

/**
* Interface describing `gindexOfRow`.
*/
Expand All @@ -38,6 +43,7 @@ interface Routine {
* ## Notes
*
* - If the function is provided an empty matrix or if the function is unable to find a matching row, the function returns `-1` (i.e., an invalid index).
* - The `workspace` array is only applicable when an input matrix is stored in column-major order. When the matrix is stored in row-major order, the workspace array is ignored.
*
* @param order - storage layout
* @param M - number of rows in `A`
Expand All @@ -46,23 +52,27 @@ interface Routine {
* @param LDA - stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
* @param x - search vector
* @param strideX - stride length for `x`
* @param workspace - workspace array for tracking row match candidates
* @param strideW - stride length for `workspace`
* @returns row index
*
* @example
* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ]
* var x = [ 3.0, 4.0 ];
* var workspace = [ 0, 0, 0 ];
*
* var out = gindexOfRow( 'row-major', 3, 2, A, 2, x, 1 );
* var out = gindexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
* // returns 1
*/
( order: Layout, M: number, N: number, A: InputArray, LDA: number, x: InputArray, strideX: number ): number;
( order: Layout, M: number, N: number, A: InputArray, LDA: number, x: InputArray, strideX: number, workspace: WorkspaceArray, strideW: number ): number;

/**
* 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.
*
* ## Notes
*
* - If the function is provided an empty matrix or if the function is unable to find a matching row, the function returns `-1` (i.e., an invalid index).
* - The `workspace` array is only applicable when an input matrix is stored in column-major order. When the matrix is stored in row-major order, the workspace array is ignored.
*
* @param M - number of rows in `A`
* @param N - number of columns in `A`
Expand All @@ -73,16 +83,20 @@ interface Routine {
* @param x - search vector
* @param strideX - stride length for `x`
* @param offsetX - starting index for `x`
* @param workspace - workspace array for tracking row match candidates
* @param strideW - stride length for `workspace`
* @param offsetW - starting index for `workspace`
* @returns row index
*
* @example
* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ]
* var x = [ 3.0, 4.0 ];
* var workspace = [ 0, 0, 0 ];
*
* var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 );
* var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
* // returns 1
*/
ndarray( M: number, N: number, A: InputArray, strideA1: number, strideA2: number, offsetA: number, x: InputArray, strideX: number, offsetX: number ): number;
ndarray( M: number, N: number, A: InputArray, strideA1: number, strideA2: number, offsetA: number, x: InputArray, strideX: number, offsetX: number, workspace: WorkspaceArray, strideW: number, offsetW: number ): number;
}

/**
Expand All @@ -91,6 +105,7 @@ interface Routine {
* ## Notes
*
* - If the function is provided an empty matrix or if the function is unable to find a matching row, the function returns `-1` (i.e., an invalid index).
* - The `workspace` array is only applicable when an input matrix is stored in column-major order. When the matrix is stored in row-major order, the workspace array is ignored.
*
* @param order - storage layout
* @param M - number of rows in `A`
Expand All @@ -99,20 +114,24 @@ interface Routine {
* @param LDA - stride length for the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
* @param x - search vector
* @param strideX - stride length for `x`
* @param workspace - workspace array for tracking row match candidates
* @param strideW - stride length for `workspace`
* @returns row index
*
* @example
* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ]
* var x = [ 3.0, 4.0 ];
* var workspace = [ 0, 0, 0 ];
*
* var out = gindexOfRow( 'row-major', 3, 2, A, 2, x, 1 );
* var out = gindexOfRow( 'row-major', 3, 2, A, 2, x, 1, workspace, 1 );
* // returns 1
*
* @example
* var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ]; // => [ [ 1.0, 2.0 ], [ 3.0, 4.0 ], [ 0.0, 0.0 ] ]
* var x = [ 3.0, 4.0 ];
* var workspace = [ 0, 0, 0 ];
*
* var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 );
* var out = gindexOfRow.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
* // returns 1
*/
declare var gindexOfRow: Routine;
Expand Down
Loading
Loading