Skip to content

Commit 20c20a8

Browse files
committed
fix: apply suggestions from code review
--- 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: na - 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: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: na - 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 a7893c2 commit 20c20a8

11 files changed

Lines changed: 207 additions & 95 deletions

File tree

lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/benchmark/c/benchmark.length.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,26 +93,23 @@ static double rand_double( void ) {
9393
* Runs a benchmark.
9494
*
9595
* @param iterations number of iterations
96-
* @param len array length
96+
* @param N number of elements along each dimension
9797
* @return elapsed time in seconds
9898
*/
99-
static double benchmark1( int iterations, int len ) {
99+
static double benchmark1( int iterations, int N ) {
100100
uint8_t *workspace;
101101
double elapsed;
102102
double *A;
103103
double *x;
104104
double t;
105105
int idx;
106-
int N;
107106
int i;
108107
int j;
109108

110-
N = (int)sqrt( (double)len );
111-
112-
A = (double *)malloc( (size_t)len * sizeof( double ) );
109+
A = (double *)malloc( (size_t)( N*N ) * sizeof( double ) );
113110
x = (double *)malloc( (size_t)N * sizeof( double ) );
114111
workspace = (uint8_t *)malloc( (size_t)N * sizeof( uint8_t ) );
115-
for ( i = 0; i < len; i++ ) {
112+
for ( i = 0; i < N*N; i++ ) {
116113
A[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
117114
}
118115
for ( j = 0; j < N; j++ ) {
@@ -142,26 +139,23 @@ static double benchmark1( int iterations, int len ) {
142139
* Runs a benchmark.
143140
*
144141
* @param iterations number of iterations
145-
* @param len array length
142+
* @param N number of elements along each dimension
146143
* @return elapsed time in seconds
147144
*/
148-
static double benchmark2( int iterations, int len ) {
145+
static double benchmark2( int iterations, int N ) {
149146
uint8_t *workspace;
150147
double elapsed;
151148
double *A;
152149
double *x;
153150
double t;
154151
int idx;
155-
int N;
156152
int i;
157153
int j;
158154

159-
N = (int)sqrt( (double)len );
160-
161-
A = (double *)malloc( (size_t)len * sizeof( double ) );
155+
A = (double *)malloc( (size_t)( N*N ) * sizeof( double ) );
162156
x = (double *)malloc( (size_t)N * sizeof( double ) );
163157
workspace = (uint8_t *)malloc( (size_t)N * sizeof( uint8_t ) );
164-
for ( i = 0; i < len; i++ ) {
158+
for ( i = 0; i < N*N; i++ ) {
165159
A[ i ] = ( rand_double() * 20000.0 ) - 10000.0;
166160
}
167161
for ( j = 0; j < N; j++ ) {
@@ -195,6 +189,7 @@ int main( void ) {
195189
int count;
196190
int iter;
197191
int len;
192+
int N;
198193
int i;
199194
int j;
200195

@@ -205,18 +200,19 @@ int main( void ) {
205200
count = 0;
206201
for ( i = MIN; i <= MAX; i++ ) {
207202
len = pow( 10, i );
203+
N = (int)sqrt( (double)len );
208204
iter = ITERATIONS / pow( 10, i-1 );
209205
for ( j = 0; j < REPEATS; j++ ) {
210206
count += 1;
211-
printf( "# c::%s:len=%d\n", NAME, len );
212-
elapsed = benchmark1( iter, len );
207+
printf( "# c::native::%s:square_matrix:order=row-major,size=%d\n", NAME, N*N );
208+
elapsed = benchmark1( iter, N );
213209
print_results( iter, elapsed );
214210
printf( "ok %d benchmark finished\n", count );
215211
}
216212
for ( j = 0; j < REPEATS; j++ ) {
217213
count += 1;
218-
printf( "# c::%s:ndarray:len=%d\n", NAME, len );
219-
elapsed = benchmark2( iter, len );
214+
printf( "# c::native::%s:ndarray:square_matrix:order=row-major,size=%d\n", NAME, N*N );
215+
elapsed = benchmark2( iter, N );
220216
print_results( iter, elapsed );
221217
printf( "ok %d benchmark finished\n", count );
222218
}

lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/docs/repl.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
Stride length for `x`.
3636

3737
workspace: Uint8Array
38-
Workspace array for tracking row match candidates.
38+
Workspace array for tracking row match candidates. This parameter
39+
is ignored if the input matrix is stored in row-major order.
3940

4041
strideW: integer
4142
Stride length for `workspace`.
@@ -96,7 +97,8 @@
9697
Starting index for `x`.
9798

9899
w: Uint8Array
99-
Workspace array for tracking row match candidates.
100+
Workspace array for tracking row match candidates. This parameter
101+
is ignored if the input matrix is stored in row-major order.
100102

101103
sw: integer
102104
Stride length for `w`.

lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/docs/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ interface Routine {
3232
* ## Notes
3333
*
3434
* - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index).
35+
* - 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 is not accessed.
3536
*
3637
* @param order - storage layout
3738
* @param M - number of rows in `A`
@@ -63,6 +64,7 @@ interface Routine {
6364
* ## Notes
6465
*
6566
* - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index).
67+
* - 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 is not accessed.
6668
*
6769
* @param M - number of rows in `A`
6870
* @param N - number of columns in `A`

lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/lib/dindex_of_row.js

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,75 @@
2020

2121
// MODULES //
2222

23-
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24-
var main = require( './main.js' );
23+
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
24+
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
25+
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
26+
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
27+
var max = require( '@stdlib/math/base/special/fast/max' );
28+
var format = require( '@stdlib/string/format' );
2529
var ndarray = require( './ndarray.js' );
2630

2731

2832
// MAIN //
2933

30-
setReadOnly( main, 'ndarray', ndarray );
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+
* ## Notes
38+
*
39+
* - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index).
40+
* - 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 is not accessed.
41+
*
42+
* @param {string} order - storage layout
43+
* @param {PositiveInteger} M - number of rows in `A`
44+
* @param {PositiveInteger} N - number of columns in `A`
45+
* @param {Float64Array} A - input matrix
46+
* @param {integer} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
47+
* @param {Float64Array} x - search vector
48+
* @param {integer} strideX - stride length for `x`
49+
* @param {Uint8Array} workspace - workspace array for tracking row match candidates
50+
* @param {integer} strideW - stride length for `workspace`
51+
* @throws {TypeError} first argument must be a valid order
52+
* @throws {RangeError} fifth argument must be greater than or equal to max(1,N)
53+
* @returns {integer} row index
54+
*
55+
* @example
56+
* var Float64Array = require( '@stdlib/array/float64' );
57+
* var Uint8Array = require( '@stdlib/array/uint8' );
58+
*
59+
* var A = new Float64Array( [ 1.0, 2.0, 0.0, 3.0, 4.0, 0.0 ] ); // => [ [ 1.0, 3.0 ], [ 2.0, 4.0 ], [ 0.0, 0.0 ] ]
60+
* var x = new Float64Array( [ 2.0, 4.0 ] );
61+
* var workspace = new Uint8Array( 3 );
62+
*
63+
* var out = dindexOfRow( 'column-major', 3, 2, A, 3, x, 1, workspace, 1 );
64+
* // returns 1
65+
*/
66+
function dindexOfRow( order, M, N, A, LDA, x, strideX, workspace, strideW ) {
67+
var sa1;
68+
var sa2;
69+
var s;
70+
if ( !isLayout( order ) ) {
71+
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
72+
}
73+
if ( isRowMajor( order ) ) {
74+
s = N;
75+
} else {
76+
s = M;
77+
}
78+
if ( LDA < max( 1, s ) ) {
79+
throw new RangeError( format( 'invalid argument. Fifth argument must be greater than or equal to max(1,%d). Value: `%d`.', s, LDA ) );
80+
}
81+
if ( isColumnMajor( order ) ) {
82+
sa1 = 1;
83+
sa2 = LDA;
84+
} else { // order === 'row-major'
85+
sa1 = LDA;
86+
sa2 = 1;
87+
}
88+
return ndarray( M, N, A, sa1, sa2, 0, x, strideX, stride2offset( N, strideX ), workspace, strideW, stride2offset( M, strideW ) ); // eslint-disable-line max-len
89+
}
3190

3291

3392
// EXPORTS //
3493

35-
module.exports = main;
94+
module.exports = dindexOfRow;

lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
var join = require( 'path' ).join;
5454
var tryRequire = require( '@stdlib/utils/try-require' );
5555
var isError = require( '@stdlib/assert/is-error' );
56-
var main = require( './dindex_of_row.js' );
56+
var main = require( './main.js' );
5757

5858

5959
// MAIN //

lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/lib/main.js

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -20,72 +20,14 @@
2020

2121
// MODULES //
2222

23-
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
24-
var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major-string' );
25-
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
26-
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
27-
var max = require( '@stdlib/math/base/special/fast/max' );
28-
var format = require( '@stdlib/string/format' );
23+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24+
var dindexOfRow = require( './dindex_of_row.js' );
2925
var ndarray = require( './ndarray.js' );
3026

3127

3228
// MAIN //
3329

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-
* ## Notes
38-
*
39-
* - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index).
40-
*
41-
* @param {string} order - storage layout
42-
* @param {PositiveInteger} M - number of rows in `A`
43-
* @param {PositiveInteger} N - number of columns in `A`
44-
* @param {Float64Array} A - input matrix
45-
* @param {integer} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
46-
* @param {Float64Array} x - search vector
47-
* @param {integer} strideX - stride length for `x`
48-
* @param {Uint8Array} workspace - workspace array for tracking row match candidates
49-
* @param {integer} strideW - stride length for `workspace`
50-
* @throws {TypeError} first argument must be a valid order
51-
* @throws {RangeError} fifth argument must be greater than or equal to max(1,N)
52-
* @returns {integer} row index
53-
*
54-
* @example
55-
* var Float64Array = require( '@stdlib/array/float64' );
56-
* var Uint8Array = require( '@stdlib/array/uint8' );
57-
*
58-
* var A = new Float64Array( [ 1.0, 2.0, 0.0, 3.0, 4.0, 0.0 ] ); // => [ [ 1.0, 3.0 ], [ 2.0, 4.0 ], [ 0.0, 0.0 ] ]
59-
* var x = new Float64Array( [ 2.0, 4.0 ] );
60-
* var workspace = new Uint8Array( 3 );
61-
*
62-
* var out = dindexOfRow( 'column-major', 3, 2, A, 3, x, 1, workspace, 1 );
63-
* // returns 1
64-
*/
65-
function dindexOfRow( order, M, N, A, LDA, x, strideX, workspace, strideW ) {
66-
var sa1;
67-
var sa2;
68-
var s;
69-
if ( !isLayout( order ) ) {
70-
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
71-
}
72-
if ( isRowMajor( order ) ) {
73-
s = N;
74-
} else {
75-
s = M;
76-
}
77-
if ( LDA < max( 1, s ) ) {
78-
throw new RangeError( format( 'invalid argument. Fifth argument must be greater than or equal to max(1,%d). Value: `%d`.', s, LDA ) );
79-
}
80-
if ( isColumnMajor( order ) ) {
81-
sa1 = 1;
82-
sa2 = LDA;
83-
} else { // order === 'row-major'
84-
sa1 = LDA;
85-
sa2 = 1;
86-
}
87-
return ndarray( M, N, A, sa1, sa2, 0, x, strideX, stride2offset( N, strideX ), workspace, strideW, stride2offset( M, strideW ) ); // eslint-disable-line max-len
88-
}
30+
setReadOnly( dindexOfRow, 'ndarray', ndarray );
8931

9032

9133
// EXPORTS //

lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/lib/ndarray.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var isRowMajor = require( '@stdlib/ndarray/base/assert/is-row-major' );
3333
* ## Notes
3434
*
3535
* - If the function is provided an empty matrix or if the function is unable to find a search vector, the function returns `-1` (i.e., an invalid index).
36+
* - 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 is not accessed.
3637
*
3738
* @param {PositiveInteger} M - number of rows in `A`
3839
* @param {PositiveInteger} N - number of columns in `A`

lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/src/main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
/**
2525
* 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.
2626
*
27-
* @param order storage layout
28-
* @param M number of rows in `A`
29-
* @param N number of columns in `A`
30-
* @param A input matrix
31-
* @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
32-
* @param X search vector
33-
* @param strideX stride length for `X`
27+
* @param order storage layout
28+
* @param M number of rows in `A`
29+
* @param N number of columns in `A`
30+
* @param A input matrix
31+
* @param LDA stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
32+
* @param X search vector
33+
* @param strideX stride length for `X`
3434
* @param workspace workspace array for tracking row match candidates
35-
* @param strideW stride length for `workspace`
36-
* @return row index
35+
* @param strideW stride length for `workspace`
36+
* @return row index
3737
*/
3838
CBLAS_INT API_SUFFIX(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 ) {
3939
CBLAS_INT sa1;

lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/test/test.main.js renamed to lib/node_modules/@stdlib/blas/ext/base/dindex-of-row/test/test.dindex_of_row.js

File renamed without changes.

0 commit comments

Comments
 (0)