Skip to content

Commit 543b5ae

Browse files
committed
feat: add blas/base/ndarray/ssyr
--- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - 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: passed - task: lint_license_headers status: passed ---
1 parent 6b79aec commit 543b5ae

10 files changed

Lines changed: 910 additions & 0 deletions

File tree

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# ssyr
22+
23+
> Perform the symmetric rank 1 operation `A = alpha*x*x^T + A`.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var ssyr = require( '@stdlib/blas/base/ndarray/ssyr' );
37+
```
38+
39+
#### ssyr( arrays )
40+
41+
Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an `N` by `N` symmetric matrix.
42+
43+
```javascript
44+
var Float32Vector = require( '@stdlib/ndarray/vector/float32' );
45+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
46+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
47+
var Float32Array = require( '@stdlib/array/float32' );
48+
49+
var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] );
50+
var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' );
51+
52+
var alpha = scalar2ndarray( 2.0, {
53+
'dtype': 'float32'
54+
});
55+
56+
var out = ssyr( [ x, A, alpha ] );
57+
// returns <ndarray>[ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.0 ] ]
58+
59+
var bool = ( out === A );
60+
// returns true
61+
```
62+
63+
The function has the following parameters:
64+
65+
- **arrays**: array-like object containing the following ndarrays:
66+
67+
- a one-dimensional input ndarray.
68+
- a two-dimensional input/output ndarray.
69+
- a zero-dimensional ndarray containing a scalar constant.
70+
71+
</section>
72+
73+
<!-- /.usage -->
74+
75+
<section class="notes">
76+
77+
</section>
78+
79+
<!-- /.notes -->
80+
81+
<section class="examples">
82+
83+
## Examples
84+
85+
<!-- eslint no-undef: "error" -->
86+
87+
```javascript
88+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
89+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
90+
var Float32Array = require( '@stdlib/array/float32' );
91+
var Float32Vector = require( '@stdlib/ndarray/vector/float32' );
92+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
93+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
94+
var ssyr = require( '@stdlib/blas/base/ndarray/ssyr' );
95+
96+
var opts = {
97+
'dtype': 'float32'
98+
};
99+
100+
var x = new Float32Vector( discreteUniform( 3, 0, 10, opts ) );
101+
var A = new ndarray( 'float32', new Float32Array( discreteUniform( 9, 0, 10, opts ) ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' );
102+
103+
var alpha = scalar2ndarray( 1.0, opts );
104+
105+
var out = ssyr( [ x, A, alpha ] );
106+
console.log( ndarray2array( out ) );
107+
```
108+
109+
</section>
110+
111+
<!-- /.examples -->
112+
113+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
114+
115+
<section class="related">
116+
117+
</section>
118+
119+
<!-- /.related -->
120+
121+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
122+
123+
<section class="links">
124+
125+
</section>
126+
127+
<!-- /.links -->
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
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 bench = require( '@stdlib/bench' );
24+
var uniform = require( '@stdlib/random/uniform' );
25+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
28+
var format = require( '@stdlib/string/format' );
29+
var pkg = require( './../package.json' ).name;
30+
var ssyr = require( './../lib' );
31+
32+
33+
// VARIABLES //
34+
35+
var options = {
36+
'dtype': 'float32'
37+
};
38+
39+
40+
// FUNCTIONS //
41+
42+
/**
43+
* Creates a benchmark function.
44+
*
45+
* @private
46+
* @param {PositiveInteger} len - array length
47+
* @returns {Function} benchmark function
48+
*/
49+
function createBenchmark( len ) {
50+
var alpha;
51+
var x;
52+
var A;
53+
54+
x = uniform( [ len ], -100.0, 100.0, options );
55+
A = uniform( [ len, len ], -100.0, 100.0, options );
56+
57+
alpha = scalar2ndarray( 1.0, options );
58+
59+
return benchmark;
60+
61+
/**
62+
* Benchmark function.
63+
*
64+
* @private
65+
* @param {Benchmark} b - benchmark instance
66+
*/
67+
function benchmark( b ) {
68+
var z;
69+
var i;
70+
71+
b.tic();
72+
for ( i = 0; i < b.iterations; i++ ) {
73+
z = ssyr( [ x, A, alpha ] );
74+
if ( typeof z !== 'object' ) {
75+
b.fail( 'should return an ndarray' );
76+
}
77+
}
78+
b.toc();
79+
if ( isnanf( z.get( 0, i%len ) ) ) {
80+
b.fail( 'should not return NaN' );
81+
}
82+
b.pass( 'benchmark finished' );
83+
b.end();
84+
}
85+
}
86+
87+
88+
// MAIN //
89+
90+
/**
91+
* Main execution sequence.
92+
*
93+
* @private
94+
*/
95+
function main() {
96+
var len;
97+
var min;
98+
var max;
99+
var f;
100+
var i;
101+
102+
min = 1; // 10^min
103+
max = 3; // 10^max
104+
105+
for ( i = min; i <= max; i++ ) {
106+
len = pow( 10, i );
107+
f = createBenchmark( len );
108+
bench( format( '%s:len=%d', pkg, len ), f );
109+
}
110+
}
111+
112+
main();
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
{{alias}}( arrays )
3+
Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where
4+
`alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an
5+
`N` by `N` symmetric matrix.
6+
7+
Parameters
8+
----------
9+
arrays: ArrayLikeObject<ndarray>
10+
Array-like object containing the following ndarrays:
11+
12+
- a one-dimensional input ndarray.
13+
- a two-dimensional input/output ndarray.
14+
- a zero-dimensional ndarray containing a scalar constant.
15+
16+
Returns
17+
-------
18+
out: ndarray
19+
Output ndarray.
20+
21+
Examples
22+
--------
23+
> var x = new {{alias:@stdlib/ndarray/vector/float32}}( [ 1.0, 2.0 ] );
24+
> var buf = new {{alias:@stdlib/array/float32}}( [ 1.0, 2.0, 2.0, 1.0 ] );
25+
> var sh = [ 2, 2 ];
26+
> var st = [ 2, 1 ];
27+
> var A = new {{alias:@stdlib/ndarray/base/ctor}}( 'float32', buf, sh, st, 0, 'row-major' );
28+
> var alpha = {{alias:@stdlib/ndarray/from-scalar}}( 2.0, { 'dtype': 'float32' });
29+
30+
> {{alias}}( [ x, A, alpha ] );
31+
> A
32+
<ndarray>[ [ 3.0, 6.0 ], [ 2.0, 9.0 ] ]
33+
34+
See Also
35+
--------
36+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { float32ndarray } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Performs the symmetric rank 1 operation `A = alpha*x*x^T + A`, where `alpha` is a scalar, `x` is an `N` element ndarray, and `A` is an `N` by `N` symmetric matrix.
27+
*
28+
* ## Notes
29+
*
30+
* - The function expects the following ndarrays:
31+
*
32+
* - a one-dimensional input ndarray.
33+
* - a two-dimensional input/output ndarray.
34+
* - a zero-dimensional ndarray containing a scalar constant.
35+
*
36+
* @param arrays - array-like object containing ndarrays
37+
* @returns output ndarray
38+
*
39+
* @example
40+
* var Float32Vector = require( '@stdlib/ndarray/vector/float32' );
41+
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
42+
* var ndarray = require( '@stdlib/ndarray/base/ctor' );
43+
* var Float32Array = require( '@stdlib/array/float32' );
44+
*
45+
* var x = new Float32Vector( [ 1.0, 2.0, 3.0 ] );
46+
* var A = new ndarray( 'float32', new Float32Array( [ 1.0, 2.0, 3.0, 2.0, 1.0, 2.0, 3.0, 2.0, 1.0 ] ), [ 3, 3 ], [ 3, 1 ], 0, 'row-major' );
47+
*
48+
* var alpha = scalar2ndarray( 2.0, {
49+
* 'dtype': 'float32'
50+
* });
51+
*
52+
* var out = ssyr( [ x, A, alpha ] );
53+
* // returns <ndarray>[ [ 3.0, 6.0, 9.0 ], [ 2.0, 9.0, 14.0 ], [ 3.0, 2.0, 19.0 ] ]
54+
*
55+
* var bool = ( out === A );
56+
* // returns true
57+
*/
58+
declare function ssyr( arrays: [ float32ndarray, float32ndarray, float32ndarray ] ): float32ndarray;
59+
60+
61+
// EXPORTS //
62+
63+
export = ssyr;

0 commit comments

Comments
 (0)