Skip to content

Commit 3bf074f

Browse files
committed
feat: add jas warppers for native bindings
--- 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: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 42d84a8 commit 3bf074f

3 files changed

Lines changed: 258 additions & 0 deletions

File tree

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var isLayout = require( '@stdlib/blas/base/assert/is-layout' );
24+
var isMatrixTranspose = require( '@stdlib/blas/base/assert/is-transpose-operation' );
25+
var isColumnMajor = require( '@stdlib/ndarray/base/assert/is-column-major-string' );
26+
var max = require( '@stdlib/math/base/special/fast/max' );
27+
var resolveOrder = require( '@stdlib/blas/base/layout-resolve-enum' );
28+
var resolveTrans = require( '@stdlib/blas/base/transpose-operation-resolve-enum' );
29+
var format = require( '@stdlib/string/format' );
30+
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
31+
var addon = require( './../src/addon.node' );
32+
33+
34+
// MAIN //
35+
36+
/**
37+
* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` or `y = α*A^H*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.
38+
*
39+
* @param {string} order - storage layout
40+
* @param {string} trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed
41+
* @param {NonNegativeInteger} M - number of rows in the matrix `A`
42+
* @param {NonNegativeInteger} N - number of columns in the matrix `A`
43+
* @param {number} alpha - scalar constant
44+
* @param {Complex64Array} A - input matrix
45+
* @param {PositiveInteger} LDA - stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`)
46+
* @param {Complex64Array} x - first input vector
47+
* @param {integer} strideX - `x` stride length
48+
* @param {number} beta - scalar constant
49+
* @param {Complex64Array} y - second input vector
50+
* @param {integer} strideY - `y` stride length
51+
* @throws {TypeError} first argument must be a valid order
52+
* @throws {TypeError} second argument must be a valid transpose operation
53+
* @throws {RangeError} third argument must be a nonnegative integer
54+
* @throws {RangeError} fourth argument must be a nonnegative integer
55+
* @throws {RangeError} seventh argument must be a valid stride
56+
* @throws {RangeError} ninth argument must be non-zero
57+
* @throws {RangeError} twelfth argument must be non-zero
58+
* @returns {Complex64Array} `y`
59+
*
60+
* @example
61+
* var Complex64Array = require( '@stdlib/array/complex64' );
62+
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
63+
*
64+
* var A = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0 ] );
65+
* var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0 ] );
66+
* var y = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] );
67+
* var alpha = new Complex64( 0.5, 0.5 );
68+
* var beta = new Complex64( 0.5, -0.5 );
69+
*
70+
* cgemv( 'column-major', 'no-transpose', 4, 2, alpha, A, 4, x, 1, beta, y, 1 );
71+
* // y => <Complex64Array>[ -10.0, 11.0, -12.0, 14.0, -14.0, 17.0, -16.0, 20.0 ]
72+
*/
73+
function cgemv( order, trans, M, N, alpha, A, LDA, x, strideX, beta, y, strideY ) { // eslint-disable-line max-params, max-len
74+
var viewA;
75+
var viewX;
76+
var viewY;
77+
var vala;
78+
79+
if ( !isLayout( order ) ) {
80+
throw new TypeError( format( 'invalid argument. First argument must be a valid order. Value: `%s`.', order ) );
81+
}
82+
if ( !isMatrixTranspose( trans ) ) {
83+
throw new TypeError( format( 'invalid argument. Second argument must be a valid transpose operation. Value: `%s`.', trans ) );
84+
}
85+
if ( M < 0 ) {
86+
throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', M ) );
87+
}
88+
if ( N < 0 ) {
89+
throw new RangeError( format( 'invalid argument. Fourth argument must be a nonnegative integer. Value: `%d`.', N ) );
90+
}
91+
if ( strideX === 0 ) {
92+
throw new RangeError( format( 'invalid argument. Ninth argument must be non-zero. Value: `%d`.', strideX ) );
93+
}
94+
if ( strideY === 0 ) {
95+
throw new RangeError( format( 'invalid argument. Twelfth argument must be non-zero. Value: `%d`.', strideY ) );
96+
}
97+
if ( isColumnMajor( order ) ) {
98+
vala = M;
99+
} else {
100+
vala = N;
101+
}
102+
if ( LDA < max( 1, vala ) ) {
103+
throw new RangeError( format( 'invalid argument. Seventh argument must be greater than or equal to max(1,%d). Value: `%d`.', vala, LDA ) );
104+
}
105+
// Check if we can early return...
106+
if ( M === 0 || N === 0 ) {
107+
return y;
108+
}
109+
viewA = reinterpret( A, 0 );
110+
viewX = reinterpret( x, 0 );
111+
viewY = reinterpret( y, 0 );
112+
addon( resolveOrder( order ), resolveTrans( trans ), M, N, alpha, viewA, LDA, viewX, strideX, beta, viewY, strideY ); // eslint-disable-line max-len
113+
return y;
114+
}
115+
116+
117+
// EXPORTS //
118+
119+
module.exports = cgemv;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24+
var cgemv = require( './cgemv.native.js' );
25+
var ndarray = require( './ndarray.native.js' );
26+
27+
28+
// MAIN //
29+
30+
setReadOnly( cgemv, 'ndarray', ndarray );
31+
32+
33+
// EXPORTS //
34+
35+
module.exports = cgemv;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var isMatrixTranspose = require( '@stdlib/blas/base/assert/is-transpose-operation' );
24+
var resolveTrans = require( '@stdlib/blas/base/transpose-operation-resolve-enum' );
25+
var format = require( '@stdlib/string/format' );
26+
var reinterpret = require( '@stdlib/strided/base/reinterpret-complex64' );
27+
var addon = require( './../src/addon.node' );
28+
29+
30+
// MAIN //
31+
32+
/**
33+
* Performs one of the matrix-vector operations `y = α*A*x + β*y` or `y = α*A^T*x + β*y` or `y = α*A^H*x + β*y`, where `α` and `β` are scalars, `x` and `y` are vectors, and `A` is an `M` by `N` matrix.
34+
*
35+
* @param {string} trans - specifies whether `A` should be transposed, conjugate-transposed, or not transposed
36+
* @param {NonNegativeInteger} M - number of rows in the matrix `A`
37+
* @param {NonNegativeInteger} N - number of columns in the matrix `A`
38+
* @param {Complex64} alpha - scalar constant
39+
* @param {Complex64Array} A - input matrix
40+
* @param {integer} strideA1 - stride of the first dimension of `A`
41+
* @param {integer} strideA2 - stride of the second dimension of `A`
42+
* @param {NonNegativeInteger} offsetA - starting index for `A`
43+
* @param {Complex64Array} x - first input vector
44+
* @param {integer} strideX - `x` stride length
45+
* @param {NonNegativeInteger} offsetX - starting index for `x`
46+
* @param {Complex64} beta - scalar constant
47+
* @param {Complex64Array} y - second input vector
48+
* @param {integer} strideY - `y` stride length
49+
* @param {NonNegativeInteger} offsetY - starting index for `y`
50+
* @throws {TypeError} first argument must be a valid transpose operation
51+
* @throws {RangeError} second argument must be a nonnegative integer
52+
* @throws {RangeError} third argument must be a nonnegative integer
53+
* @throws {RangeError} tenth argument must be non-zero
54+
* @throws {RangeError} fourteenth argument must be non-zero
55+
* @returns {Complex64Array} `y`
56+
*
57+
* @example
58+
* var Complex64Array = require( '@stdlib/array/complex64' );
59+
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
60+
*
61+
* var A = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0, 5.0, 5.0, 6.0, 6.0, 7.0, 7.0, 8.0, 8.0 ] );
62+
* var x = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0 ] );
63+
* var y = new Complex64Array( [ 1.0, 1.0, 2.0, 2.0, 3.0, 3.0, 4.0, 4.0 ] );
64+
* var alpha = new Complex64( 0.5, 0.5 );
65+
* var beta = new Complex64( 0.5, -0.5 );
66+
*
67+
* cgemv( 'no-transpose', 4, 2, alpha, A, 1, 4, 0, x, 1, 0, beta, y, 1, 0 );
68+
* // y => <Complex64Array>[ -10.0, 11.0, -12.0, 14.0, -14.0, 17.0, -16.0, 20.0 ]
69+
*/
70+
function cgemv( trans, M, N, alpha, A, strideA1, strideA2, offsetA, x, strideX, offsetX, beta, y, strideY, offsetY ) { // eslint-disable-line max-params, max-len
71+
var viewA;
72+
var viewX;
73+
var viewY;
74+
75+
if ( !isMatrixTranspose( trans ) ) {
76+
throw new TypeError( format( 'invalid argument. First argument must be a valid transpose operation. Value: `%s`.', trans ) );
77+
}
78+
if ( M < 0 ) {
79+
throw new RangeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%d`.', M ) );
80+
}
81+
if ( N < 0 ) {
82+
throw new RangeError( format( 'invalid argument. Third argument must be a nonnegative integer. Value: `%d`.', N ) );
83+
}
84+
if ( strideX === 0 ) {
85+
throw new RangeError( format( 'invalid argument. Tenth argument must be non-zero. Value: `%d`.', strideX ) );
86+
}
87+
if ( strideY === 0 ) {
88+
throw new RangeError( format( 'invalid argument. Fourteenth argument must be non-zero. Value: `%d`.', strideY ) );
89+
}
90+
// Check if we can early return...
91+
if ( M === 0 || N === 0 ) {
92+
return y;
93+
}
94+
viewA = reinterpret( A, 0 );
95+
viewX = reinterpret( x, 0 );
96+
viewY = reinterpret( y, 0 );
97+
addon.ndarray( resolveTrans( trans ), M, N, alpha, viewA, strideA1, strideA2, offsetA, viewX, strideX, offsetX, beta, viewY, strideY, offsetY ); // eslint-disable-line max-len
98+
return y;
99+
}
100+
101+
102+
// EXPORTS //
103+
104+
module.exports = cgemv;

0 commit comments

Comments
 (0)