Skip to content

Commit 28daa29

Browse files
committed
feat: add C implementation for sspr
--- 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: passed - task: lint_package_json status: passed - 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: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: missing_dependencies - task: lint_c_examples status: missing_dependencies - task: lint_c_benchmarks status: missing_dependencies - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent aa6e636 commit 28daa29

File tree

25 files changed

+2834
-11
lines changed

25 files changed

+2834
-11
lines changed

lib/node_modules/@stdlib/blas/base/sspr/README.md

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,21 +183,60 @@ console.log( AP );
183183
### Usage
184184

185185
```c
186-
TODO
186+
#include "stdlib/blas/base/sspr.h"
187+
#include "stdlib/blas/base/shared.h"
187188
```
188189

189-
#### TODO
190+
#### c_sspr( order, uplo, N, alpha, \*X, strideX, \*AP )
190191

191-
TODO.
192+
Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form.
193+
194+
```c
195+
float AP[] = { 1.0f, 2.0f, 3.0f, 1.0f, 2.0f, 1.0f };
196+
const float x[] = { 1.0f, 2.0f, 3.0f };
197+
198+
c_sspr( CblasColMajor, CblasUpper, 3, 1.0f, x, 1, AP );
199+
```
200+
201+
The function accepts the following arguments:
202+
203+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
204+
- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced.
205+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
206+
- **alpha**: `[in] float` scalar.
207+
- **X**: `[in] float*` first input array.
208+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
209+
- **AP**: `[inout] float*` packed form of a symmetric matrix `A`.
192210
193211
```c
194-
TODO
212+
void c_sspr( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, float *AP )
195213
```
196214

197-
TODO
215+
#### c_sspr_ndarray( order, uplo, N, alpha, \*X, strideX, \*AP, strideAP, offsetAP )
216+
217+
Performs the symmetric rank 1 operation `A = α*x*x^T + A` where `α` is a scalar, `x` is an `N` element vector, and `A` is an `N` by `N` symmetric matrix supplied in packed form using alternative indexing semantics.
218+
219+
```c
220+
float AP[] = { 1.0f, 2.0f, 3.0f, 1.0f, 2.0f, 1.0f };
221+
const float x[] = { 1.0f, 2.0f, 3.0f };
222+
223+
c_sspr_ndarray( CblasColMajor, CblasUpper, 3, 1.0f, x, 1, AP, 1, 0 );
224+
```
225+
226+
The function accepts the following arguments:
227+
228+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
229+
- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced.
230+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
231+
- **alpha**: `[in] float` scalar.
232+
- **X**: `[in] float*` first input array.
233+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
234+
- **AP**: `[inout] float*` packed form of a symmetric matrix `A`.
235+
- **strideAP**: `[in] CBLAS_INT` `AP` stride length.
236+
- **offsetAP**: `[in] CBLAS_INT` starting index for `AP`.
198237
199238
```c
200-
TODO
239+
void c_sspr_ndarray( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, float *AP, const CBLAS_INT strideAP, const CBLAS_INT offsetAP )
201240
```
202241

203242
</section>
@@ -219,7 +258,34 @@ TODO
219258
### Examples
220259

221260
```c
222-
TODO
261+
#include "stdlib/blas/base/sspr.h"
262+
#include "stdlib/blas/base/shared.h"
263+
#include <stdio.h>
264+
265+
int main( void ) {
266+
// Create strided arrays:
267+
float AP[] = { 1.0f, 2.0f, 3.0f, 1.0f, 2.0f, 1.0f };
268+
const float x[] = { 1.0f, 2.0f, 3.0f };
269+
270+
// Specify the number of elements:
271+
const int N = 3;
272+
273+
// Perform the symmetric rank 1 operation `A = α*x*x^T + A`:
274+
c_sspr( CblasRowMajor, CblasUpper, N, 1.0f, x, 1, AP );
275+
276+
// Print the result:
277+
for ( int i = 0; i < N*(N+1)/2; i++ ) {
278+
printf( "AP[ %i ] = %f\n", i, AP[ i ] );
279+
}
280+
281+
// Perform the symmetric rank 1 operation `A = α*x*x^T + A` using alternative indexing semantics:
282+
c_sspr_ndarray( CblasRowMajor, CblasUpper, N, 1.0f, x, 1, 0, AP, 1, 0 );
283+
284+
// Print the result:
285+
for ( int i = 0; i < N*(N+1)/2; i++ ) {
286+
printf( "AP[ %i ] = %f\n", i, AP[ i ] );
287+
}
288+
}
223289
```
224290
225291
</section>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var floor = require( '@stdlib/math/base/special/floor' );
29+
var tryRequire = require( '@stdlib/utils/try-require' );
30+
var pkg = require( './../package.json' ).name;
31+
32+
33+
// VARIABLES //
34+
35+
var sspr = tryRequire( resolve( __dirname, './../lib/sspr.native.js' ) );
36+
var opts = {
37+
'skip': ( sspr instanceof Error )
38+
};
39+
var options = {
40+
'dtype': 'float32'
41+
};
42+
43+
44+
// FUNCTIONS //
45+
46+
/**
47+
* Creates a benchmark function.
48+
*
49+
* @private
50+
* @param {PositiveInteger} N - number of elements along each dimension
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark( N ) {
54+
var AP = uniform( N * ( N + 1 ) / 2, -10.0, 10.0, options );
55+
var x = uniform( N, -10.0, 10.0, options );
56+
return benchmark;
57+
58+
/**
59+
* Benchmark function.
60+
*
61+
* @private
62+
* @param {Benchmark} b - benchmark instance
63+
*/
64+
function benchmark( b ) {
65+
var z;
66+
var i;
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
z = sspr( 'row-major', 'upper', N, 1.0, x, 1, AP );
71+
if ( isnanf( z[ i%z.length ] ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
}
75+
b.toc();
76+
if ( isnanf( z[ i%z.length ] ) ) {
77+
b.fail( 'should not return NaN' );
78+
}
79+
b.pass( 'benchmark finished' );
80+
b.end();
81+
}
82+
}
83+
84+
85+
// MAIN //
86+
87+
/**
88+
* Main execution sequence.
89+
*
90+
* @private
91+
*/
92+
function main() {
93+
var len;
94+
var min;
95+
var max;
96+
var f;
97+
var i;
98+
99+
min = 1; // 10^min
100+
max = 6; // 10^max
101+
102+
for ( i = min; i <= max; i++ ) {
103+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
104+
f = createBenchmark( len );
105+
bench( pkg+'::native:size='+( len * ( len + 1 ) / 2 ), opts, f );
106+
}
107+
}
108+
109+
main();
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var uniform = require( '@stdlib/random/array/uniform' );
26+
var isnanf = require( '@stdlib/math/base/assert/is-nanf' );
27+
var pow = require( '@stdlib/math/base/special/pow' );
28+
var floor = require( '@stdlib/math/base/special/floor' );
29+
var tryRequire = require( '@stdlib/utils/try-require' );
30+
var pkg = require( './../package.json' ).name;
31+
32+
33+
// VARIABLES //
34+
35+
var sspr = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
36+
var opts = {
37+
'skip': ( sspr instanceof Error )
38+
};
39+
var options = {
40+
'dtype': 'float32'
41+
};
42+
43+
44+
// FUNCTIONS //
45+
46+
/**
47+
* Creates a benchmark function.
48+
*
49+
* @private
50+
* @param {PositiveInteger} N - number of elements along each dimension
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark( N ) {
54+
var AP = uniform( N * ( N + 1 ) / 2, -10.0, 10.0, options );
55+
var x = uniform( N, -10.0, 10.0, options );
56+
return benchmark;
57+
58+
/**
59+
* Benchmark function.
60+
*
61+
* @private
62+
* @param {Benchmark} b - benchmark instance
63+
*/
64+
function benchmark( b ) {
65+
var z;
66+
var i;
67+
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
z = sspr( 'row-major', 'upper', N, 1.0, x, 1, 0, AP, 1, 0 );
71+
if ( isnanf( z[ i%z.length ] ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
}
75+
b.toc();
76+
if ( isnanf( z[ i%z.length ] ) ) {
77+
b.fail( 'should not return NaN' );
78+
}
79+
b.pass( 'benchmark finished' );
80+
b.end();
81+
}
82+
}
83+
84+
85+
// MAIN //
86+
87+
/**
88+
* Main execution sequence.
89+
*
90+
* @private
91+
*/
92+
function main() {
93+
var len;
94+
var min;
95+
var max;
96+
var f;
97+
var i;
98+
99+
min = 1; // 10^min
100+
max = 6; // 10^max
101+
102+
for ( i = min; i <= max; i++ ) {
103+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
104+
f = createBenchmark( len );
105+
bench( pkg+'::native:ndarray:size='+( len * ( len + 1 ) / 2 ), opts, f );
106+
}
107+
}
108+
109+
main();

0 commit comments

Comments
 (0)