Skip to content

Commit fcf1b0b

Browse files
committed
feat: add c implementation for blas/base/dsyr2
--- 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 ---
1 parent 9211c88 commit fcf1b0b

File tree

22 files changed

+3168
-7
lines changed

22 files changed

+3168
-7
lines changed

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

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,21 +193,74 @@ console.log( A );
193193
### Usage
194194

195195
```c
196-
TODO
196+
#include "stdlib/blas/base/dsyr2.h"
197197
```
198198

199-
#### TODO
199+
#### c_dsyr2( order, uplo, N, alpha, \*X, strideX, \*Y, strideY, \*A, LDA )
200200

201-
TODO.
201+
Performs the symmetric rank 2 operation `A = α*x*y^T + α*y*x^T + A`.
202202

203203
```c
204-
TODO
204+
#include "stdlib/blas/base/shared.h"
205+
206+
double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 };
207+
const double x[] = { 1.0, 2.0, 3.0 };
208+
const double y[] = { 1.0, 2.0, 3.0 };
209+
210+
c_dsyr2( CblasColMajor, CblasUpper, 3, 1.0, x, 1, y, 1, A, 3 );
211+
```
212+
213+
The function accepts the following arguments:
214+
215+
- **order**: `[in] CBLAS_LAYOUT` storage layout.
216+
- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced.
217+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
218+
- **alpha**: `[in] double` scalar.
219+
- **X**: `[in] double*` first input array.
220+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
221+
- **Y**: `[in] double*` second input array.
222+
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
223+
- **A**: `[inout] double*` input matrix.
224+
- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
225+
226+
```c
227+
void c_dsyr2( const CBLAS_LAYOUT order, const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY, double *A, const CBLAS_INT LDA )
228+
```
229+
230+
<!-- lint disable maximum-heading-length -->
231+
232+
#### c_dsyr2_ndarray( uplo, N, alpha, \*X, strideX, offsetX, \*Y, strideY, offsetY, \*A, sa1, sa2, oa )
233+
234+
Performs the symmetric rank 2 operation `A = α*x*y^T + α*y*x^T + A` using alternative indexing semantics.
235+
236+
```c
237+
#include "stdlib/blas/base/shared.h"
238+
239+
double A[] = { 1.0, 2.0, 3.0, 0.0, 1.0, 2.0, 0.0, 0.0, 1.0 };
240+
const double x[] = { 1.0, 2.0, 3.0 };
241+
const double y[] = { 1.0, 2.0, 3.0 };
242+
243+
c_dsyr2_ndarray( CblasUpper, 3, 1.0, x, 1, 0, y, 1, 0, A, 3, 1, 0 );
205244
```
206245
207-
TODO
246+
The function accepts the following arguments:
247+
248+
- **uplo**: `[in] CBLAS_UPLO` specifies whether the upper or lower triangular part of the symmetric matrix `A` should be referenced.
249+
- **N**: `[in] CBLAS_INT` number of elements along each dimension of `A`.
250+
- **alpha**: `[in] double` scalar.
251+
- **X**: `[in] double*` first input array.
252+
- **strideX**: `[in] CBLAS_INT` index increment for `X`.
253+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
254+
- **Y**: `[in] double` second input array.
255+
- **strideY**: `[in] CBLAS_INT` index increment for `Y`.
256+
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
257+
- **A**: `[inout] double*` input matrix.
258+
- **sa1**: `[in] CBLAS_INT` stride of the first dimension of `A`.
259+
- **sa2**: `[in] CBLAS_INT` stride of the second dimension of `A`.
260+
- **oa**: `[in] CBLAS_INT` starting index for `A`.
208261
209262
```c
210-
TODO
263+
void c_dsyr2_ndarray( const CBLAS_UPLO uplo, const CBLAS_INT N, const double alpha, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, CBLAS_INT strideY, const CBLAS_INT offsetY, double *A, const CBLAS_INT sa1, const CBLAS_INT sa2, const CBLAS_INT oa )
211264
```
212265

213266
</section>
@@ -229,7 +282,35 @@ TODO
229282
### Examples
230283

231284
```c
232-
TODO
285+
#include "stdlib/blas/base/dsyr2.h"
286+
#include "stdlib/blas/base/shared.h"
287+
#include <stdio.h>
288+
289+
int main( void ) {
290+
// Create strided arrays:
291+
double A[] = { 1.0, 0.0, 0.0, 2.0, 1.0, 0.0, 3.0, 2.0, 1.0 };
292+
const double x[] = { 1.0, 2.0, 3.0 };
293+
const double y[] = { 1.0, 2.0, 3.0 };
294+
295+
// Specify the number of elements along each dimension of `A`:
296+
const int N = 3;
297+
298+
// Perform the symmetric rank 1 operation `A = α*x*x^T + A`:
299+
c_dsyr2( CblasColMajor, CblasUpper, N, 1.0, x, 1, y, 1 A, N );
300+
301+
// Print the result:
302+
for ( int i = 0; i < N*N; i++ ) {
303+
printf( "A[ %i ] = %f\n", i, A[ i ] );
304+
}
305+
306+
// Perform the symmetric rank 1 operation `A = α*x*x^T + A`:
307+
c_dsyr2_ndarray( CblasUpper, N, 1.0, x, 1, 0, y, 1, 0, A, N, 1, 0 );
308+
309+
// Print the result:
310+
for ( int i = 0; i < N*N; i++ ) {
311+
printf( "A[ %i ] = %f\n", i, A[ i ] );
312+
}
313+
}
233314
```
234315
235316
</section>
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var ones = require( '@stdlib/array/ones' );
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 dsyr2 = tryRequire( resolve( __dirname, './../lib/dsyr2.native.js' ) );
36+
var opts = {
37+
'skip': ( dsyr2 instanceof Error )
38+
};
39+
var options = {
40+
'dtype': 'float64'
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 x = ones( N, options.dtype );
55+
var y = ones( N, options.dtype );
56+
var A = ones( N*N, options.dtype );
57+
return benchmark;
58+
59+
/**
60+
* Benchmark function.
61+
*
62+
* @private
63+
* @param {Benchmark} b - benchmark instance
64+
*/
65+
function benchmark( b ) {
66+
var z;
67+
var i;
68+
69+
b.tic();
70+
for ( i = 0; i < b.iterations; i++ ) {
71+
z = dsyr2( 'row-major', 'upper', N, 1.0, x, 1, y, 1, A, N );
72+
if ( isnan( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
}
76+
b.toc();
77+
if ( isnan( z[ i%z.length ] ) ) {
78+
b.fail( 'should not return NaN' );
79+
}
80+
b.pass( 'benchmark finished' );
81+
b.end();
82+
}
83+
}
84+
85+
86+
// MAIN //
87+
88+
/**
89+
* Main execution sequence.
90+
*
91+
* @private
92+
*/
93+
function main() {
94+
var min;
95+
var max;
96+
var N;
97+
var f;
98+
var i;
99+
100+
min = 1; // 10^min
101+
max = 6; // 10^max
102+
103+
for ( i = min; i <= max; i++ ) {
104+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
105+
f = createBenchmark( N );
106+
bench( pkg+'::native:size='+(N*N), opts, f );
107+
}
108+
}
109+
110+
main();
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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 isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var ones = require( '@stdlib/array/ones' );
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 dsyr2 = tryRequire( resolve( __dirname, './../lib/ndarray.native.js' ) );
36+
var opts = {
37+
'skip': ( dsyr2 instanceof Error )
38+
};
39+
var options = {
40+
'dtype': 'float64'
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 x = ones( N, options.dtype );
55+
var y = ones( N, options.dtype );
56+
var A = ones( N*N, options.dtype );
57+
return benchmark;
58+
59+
/**
60+
* Benchmark function.
61+
*
62+
* @private
63+
* @param {Benchmark} b - benchmark instance
64+
*/
65+
function benchmark( b ) {
66+
var z;
67+
var i;
68+
69+
b.tic();
70+
for ( i = 0; i < b.iterations; i++ ) {
71+
z = dsyr2( 'upper', N, 1.0, x, 1, 0, y, 1, 0, A, N, 1, 0 );
72+
if ( isnan( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
}
76+
b.toc();
77+
if ( isnan( z[ i%z.length ] ) ) {
78+
b.fail( 'should not return NaN' );
79+
}
80+
b.pass( 'benchmark finished' );
81+
b.end();
82+
}
83+
}
84+
85+
86+
// MAIN //
87+
88+
/**
89+
* Main execution sequence.
90+
*
91+
* @private
92+
*/
93+
function main() {
94+
var min;
95+
var max;
96+
var N;
97+
var f;
98+
var i;
99+
100+
min = 1; // 10^min
101+
max = 6; // 10^max
102+
103+
for ( i = min; i <= max; i++ ) {
104+
N = floor( pow( pow( 10, i ), 1.0/2.0 ) );
105+
f = createBenchmark( N );
106+
bench( pkg+'::native:ndarray:size='+(N*N), opts, f );
107+
}
108+
}
109+
110+
main();

0 commit comments

Comments
 (0)