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
64 changes: 56 additions & 8 deletions lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ limitations under the License.
var gindexOfColumn = require( '@stdlib/blas/ext/base/gindex-of-column' );
```

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

Returns the index of the first column 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 column in an input matrix which has the same elem
var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];

var x = [ 2.0, 4.0, 0.0 ];
var out = gindexOfColumn( 'row-major', 3, 2, A, 2, x, 1 );
var workspace = [ 0, 0 ];
var out = gindexOfColumn( '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 column match candidates. This parameter is ignored if the input matrix is stored in column-major order.
- **strideW**: stride length for `workspace`.

When an input matrix is stored in column-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, 3.0, 0.0, 2.0, 4.0, 0.0 ];

var x = [ 2.0, 4.0, 0.0 ];
var workspace = [];
var out = gindexOfColumn( 'column-major', 3, 2, A, 3, x, 1, workspace, 1 );
// returns 1
```

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

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

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

Expand All @@ -94,13 +116,14 @@ var x0 = new Float64Array( [ 9999.0, 2.0, 4.0, 0.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 = gindexOfColumn( 'row-major', 3, 2, A1, 2, x1, 1 );
var workspace = [ 0, 0 ];
var out = gindexOfColumn( 'row-major', 3, 2, A1, 2, x1, 1, workspace, 1 );
// returns 1
```

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

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

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

Expand All @@ -117,7 +140,8 @@ Returns the index of the first column in an input matrix which has the same elem
var A = [ 1.0, 2.0, 3.0, 4.0, 0.0, 0.0 ];

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

Expand All @@ -132,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 column match candidates. This parameter is ignored if the input matrix is stored in column-major order.
- **strideW**: stride length for `workspace`.
- **offsetW**: starting index for `workspace`.

When an input matrix is stored in column-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, 3.0, 0.0, 2.0, 4.0, 0.0 ];

var x = [ 2.0, 4.0, 0.0 ];
var workspace = [];
var out = gindexOfColumn.ndarray( 3, 2, A, 1, 3, 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 @@ -146,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, 2.0, 4.0, 0.0 ];
var out = gindexOfColumn.ndarray( 3, 2, A, 2, 1, 1, x, 1, 1 );
var workspace = [ 0, 0 ];
var out = gindexOfColumn.ndarray( 3, 2, A, 2, 1, 1, x, 1, 1, workspace, 1, 0 );
// returns 1
```

Expand Down Expand Up @@ -193,7 +239,9 @@ console.log( ndarray2array( A, shape, strides, 0, order ) );
var x = [ 2.0, 5.0, 8.0 ];
console.log( x );

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

var out = gindexOfColumn( 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 = gindexOfColumn( order, N, N, A, N, x, 1 );
z = gindexOfColumn( 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 @@
* @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 @@
b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x[ N-1 ] += 1;
z = gindexOfColumn( N, N, A, sa1, sa2, 0, x, 1, 0 );
z = gindexOfColumn( N, N, A, sa1, sa2, 0, x, 1, 0, workspace, 1, 0 );

Check warning on line 81 in lib/node_modules/@stdlib/blas/ext/base/gindex-of-column/benchmark/benchmark.ndarray.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

This line has a length of 81. Maximum allowed is 80
if ( isnan( z ) ) {
b.fail( 'should not return NaN' );
}
Expand Down
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 column in an input matrix which has the same
elements as a provided search vector.

Expand Down Expand Up @@ -34,20 +34,28 @@
strideX: integer
Stride length for `x`.

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

strideW: integer
Stride length for `workspace`.

Returns
-------
out: integer
Column 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 ];
> var x = [ 2.0, 4.0 ];
> {{alias}}( 'row-major', 2, 2, A, 2, x, 1 )
> var w = [ 0, 0 ];
> {{alias}}( 'row-major', 2, 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 column 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: integer
sx: integer
Stride length for `x`.

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

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

sw: integer
Stride length for `w`.

ow: integer
Starting index for `w`.

Returns
-------
out: integer
Column 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 ];
> var x = [ 2.0, 4.0 ];
> {{alias}}.ndarray( 2, 2, A, 2, 1, 0, x, 1, 0 )
> var w = [ 0, 0 ];
> {{alias}}.ndarray( 2, 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 `gindexOfColumn`.
*/
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 column, the function returns `-1` (i.e., an invalid index).
* - The `workspace` array is only applicable when an input matrix is stored in row-major order. When the matrix is stored in column-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 column match candidates
* @param strideW - stride length for `workspace`
* @returns column 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 = [ 2.0, 4.0, 0.0 ];
* var workspace = [ 0, 0 ];
*
* var out = gindexOfColumn( 'row-major', 3, 2, A, 2, x, 1 );
* var out = gindexOfColumn( '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 column 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 column, the function returns `-1` (i.e., an invalid index).
* - The `workspace` array is only applicable when an input matrix is stored in row-major order. When the matrix is stored in column-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 column match candidates
* @param strideW - stride length for `workspace`
* @param offsetW - starting index for `workspace`
* @returns column 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 = [ 2.0, 4.0, 0.0 ];
* var workspace = [ 0, 0 ];
*
* var out = gindexOfColumn.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 );
* var out = gindexOfColumn.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 column, the function returns `-1` (i.e., an invalid index).
* - The `workspace` array is only applicable when an input matrix is stored in row-major order. When the matrix is stored in column-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 column match candidates
* @param strideW - stride length for `workspace`
* @returns column 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 = [ 2.0, 4.0, 0.0 ];
* var workspace = [ 0, 0 ];
*
* var out = gindexOfColumn( 'row-major', 3, 2, A, 2, x, 1 );
* var out = gindexOfColumn( '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 = [ 2.0, 4.0, 0.0 ];
* var workspace = [ 0, 0 ];
*
* var out = gindexOfColumn.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0 );
* var out = gindexOfColumn.ndarray( 3, 2, A, 2, 1, 0, x, 1, 0, workspace, 1, 0 );
* // returns 1
*/
declare var gindexOfColumn: Routine;
Expand Down
Loading
Loading