Skip to content

Commit cf7f5a3

Browse files
committed
chore: add fortran and c implementation
--- 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: 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: 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: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 35c479c commit cf7f5a3

33 files changed

+4679
-50
lines changed

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

Lines changed: 132 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2025 The Stdlib Authors.
5+
Copyright (c) 2024 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -22,17 +22,23 @@ limitations under the License.
2222

2323
> Perform the rank 1 operation `A = α*x*y^T + A`.
2424
25-
<section class = "usage">
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
2632

2733
## Usage
2834

2935
```javascript
3036
var sger = require( '@stdlib/blas/base/sger' );
3137
```
3238

33-
#### sger( ord, M, N, α, x, sx, y, sy, A, lda )
39+
#### sger( order, M, N, α, x, sx, y, sy, A, lda )
3440

35-
Performs the rank 1 operation `A = α*x*y^T + A`, where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector and `A` is an `M` by `N` matrix.
41+
Performs the rank 1 operation `A = α*x*y^T + A`, where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector, and `A` is an `M` by `N` matrix.
3642

3743
```javascript
3844
var Float32Array = require( '@stdlib/array/float32' );
@@ -47,18 +53,18 @@ sger( 'row-major', 2, 3, 1.0, x, 1, y, 1, A, 3 );
4753

4854
The function has the following parameters:
4955

50-
- **ord**: storage layout.
56+
- **order**: storage layout.
5157
- **M**: number of rows in the matrix `A`.
5258
- **N**: number of columns in the matrix `A`.
5359
- **α**: scalar constant.
5460
- **x**: input [`Float32Array`][mdn-float32array].
55-
- **sx**: index increment for `x`.
61+
- **sx**: stride length for `x`.
5662
- **y**: output [`Float32Array`][mdn-float32array].
57-
- **sy**: index increment for `y`.
63+
- **sy**: stride length for `y`.
5864
- **A**: input matrix stored in linear memory as a [`Float32Array`][mdn-float32array].
5965
- **lda**: stride of the first dimension of `A` (leading dimension of `A`).
6066

61-
The stride parameters determine how operations are performed. For example, to iterate over every other element in `x` and `y`,
67+
The stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to iterate over every other element in `x` and `y`,
6268

6369
```javascript
6470
var Float32Array = require( '@stdlib/array/float32' );
@@ -93,7 +99,7 @@ sger( 'column-major', 2, 3, 1.0, x1, -1, y1, -1, A, 2 );
9399

94100
#### sger.ndarray( M, N, α, x, sx, ox, y, sy, oy, A, sa1, sa2, oa )
95101

96-
Performs the rank 1 operation `A = α*x*y^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector and `A` is an `M` by `N` matrix.
102+
Performs the rank 1 operation `A = α*x*y^T + A`, using alternative indexing semantics and where `α` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector, and `A` is an `M` by `N` matrix.
97103

98104
```javascript
99105
var Float32Array = require( '@stdlib/array/float32' );
@@ -119,12 +125,12 @@ While [`typed array`][mdn-typed-array] views mandate a view offset based on the
119125
```javascript
120126
var Float32Array = require( '@stdlib/array/float32' );
121127

122-
var A = new Float32Array( [ 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );
123-
var x = new Float32Array( [ 1.0, 0.0, 1.0, 0.0 ] );
124-
var y = new Float32Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
128+
var A = new Float32Array( [ 0.0, 0.0, 1.0, 4.0, 2.0, 5.0, 3.0, 6.0 ] );
129+
var x = new Float32Array( [ 0.0, 1.0, 0.0, 1.0, 0.0 ] );
130+
var y = new Float32Array( [ 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
125131

126-
sger.ndarray( 2, 3, 1.0, x, 2, 0, y, 2, 0, A, 1, 2, 0 );
127-
// A => <Float32Array>[ 2.0, 5.0, 3.0, 6.0, 4.0, 7.0 ]
132+
sger.ndarray( 2, 3, 1.0, x, 2, 1, y, 2, 1, A, 1, 2, 2 );
133+
// A => <Float32Array>[ 0.0, 0.0, 2.0, 5.0, 3.0, 6.0, 4.0, 7.0 ]
128134
```
129135

130136
</section>
@@ -166,7 +172,7 @@ sger( 'row-major', M, N, 1.0, x, 1, y, 1, A, N );
166172
console.log( A );
167173

168174
sger.ndarray( M, N, 1.0, x, 1, 0, y, 1, 0, A, 1, M, 0 );
169-
console.log(A);
175+
console.log( A );
170176

171177
```
172178

@@ -200,18 +206,80 @@ console.log(A);
200206
#include "stdlib/blas/base/sger.h"
201207
```
202208

203-
#### TODO
209+
#### c_sger( layout, M, N, alpha, \*X, strideX, \*Y, strideY, \*A, LDA )
204210

205-
TODO.
211+
Performs the rank 1 operation `A = alpha*x*y^T + A`, where `alpha` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector, and `A` is an `M`-by-`N` matrix.
206212

207213
```c
208-
TODO
214+
#include "stdlib/blas/base/shared.h"
215+
216+
float A[ 3*4 ] = {
217+
0.0, 0.0, 0.0, 0.0,
218+
0.0, 0.0, 0.0, 0.0,
219+
0.0, 0.0, 0.0, 0.0
220+
};
221+
222+
const float x[ 3 ] = { 1.0, 4.0, 0.0 };
223+
const float y[ 4 ] = { 0.0, 1.0, 2.0, 3.0 };
224+
225+
c_sger( CblasRowMajor, 3, 4, 1.0, x, 1, y, 1, A, 4 );
209226
```
210227
211-
TODO
228+
The function accepts the following arguments:
229+
230+
- **layout**: `[in] CBLAS_LAYOUT` storage layout.
231+
- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`.
232+
- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`.
233+
- **alpha**: `[in] float` scalar constant.
234+
- **X**: `[in] float*` an `M` element vector.
235+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
236+
- **Y**: `[in] float*` an `N` element vector.
237+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
238+
- **A**: `[inout] float*` input matrix.
239+
- **LDA**: `[in] CBLAS_INT` stride of the first dimension of `A` (a.k.a., leading dimension of the matrix `A`).
212240
213241
```c
214-
TODO
242+
void c_sger( const CBLAS_LAYOUT layout, const CBLAS_INT M, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const float *Y, const CBLAS_INT strideY, float *A, const CBLAS_INT LDA );
243+
```
244+
245+
#### c_sger_ndarray( M, N, alpha, \*X, sx, ox, \*Y, sy, oy, \*A, sa1, sa2, oa )
246+
247+
Performs the rank 1 operation `A = alpha*x*y^T + A`, using alternative indexing semantics and where `alpha` is a scalar, `x` is an `M` element vector, `y` is an `N` element vector, and `A` is an `M`-by-`N` matrix.
248+
249+
```c
250+
#include "stdlib/blas/base/shared.h"
251+
252+
float A[ 3*4 ] = {
253+
0.0, 0.0, 0.0, 0.0,
254+
0.0, 0.0, 0.0, 0.0,
255+
0.0, 0.0, 0.0, 0.0
256+
};
257+
258+
const float x[ 3 ] = { 1.0, 4.0, 0.0 };
259+
const float y[ 4 ] = { 0.0, 1.0, 2.0, 3.0 };
260+
261+
c_sger_ndarray( 3, 4, 1.0, x, 1, 0, y, 1, 0, A, 4, 1, 0 );
262+
```
263+
264+
The function accepts the following arguments:
265+
266+
- **layout**: `[in] CBLAS_LAYOUT` storage layout.
267+
- **M**: `[in] CBLAS_INT` number of rows in the matrix `A`.
268+
- **N**: `[in] CBLAS_INT` number of columns in the matrix `A`.
269+
- **alpha**: `[in] float` scalar constant.
270+
- **X**: `[in] float*` an `M` element vector.
271+
- **sx**: `[in] CBLAS_INT` stride length for `X`.
272+
- **ox**: `[in] CBLAS_INT` starting index for `X`.
273+
- **Y**: `[in] float*` an `N` element vector.
274+
- **sy**: `[in] CBLAS_INT` stride length for `Y`.
275+
- **oy**: `[in] CBLAS_INT` starting index for `Y`.
276+
- **A**: `[inout] float*` input matrix.
277+
- **sa1**: `[in] CBLAS_INT` stride of the first dimension of `A`.
278+
- **sa2**: `[in] CBLAS_INT` stride of the second dimension of `A`.
279+
- **oa**: `[in] CBLAS_INT` starting index for `A`.
280+
281+
```c
282+
void c_sger( onst CBLAS_INT M, const CBLAS_INT N, const float alpha, const float *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const float *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, float *A, const CBLAS_INT strideA1, const CBLAS_INT strideA2, const CBLAS_INT offsetA );
215283
```
216284

217285
</section>
@@ -233,7 +301,49 @@ TODO
233301
### Examples
234302

235303
```c
236-
TODO
304+
#include "stdlib/blas/base/sger.h"
305+
#include "stdlib/blas/base/shared.h"
306+
#include <stdio.h>
307+
308+
int main( void ) {
309+
// Define a 3x4 matrix stored in row-major order:
310+
float A[ 3*4 ] = {
311+
0.0, 0.0, 0.0, 0.0,
312+
0.0, 0.0, 0.0, 0.0,
313+
0.0, 0.0, 0.0, 0.0
314+
};
315+
// Define `x` and `y^T` vectors:
316+
const float x[ 3 ] = { 1.0, 4.0, 0.0 }; // M
317+
const float y[ 4 ] = { 0.0, 1.0, 2.0, 3.0 }; // N
318+
319+
// Specify the number of rows and columns:
320+
const int M = 3;
321+
const int N = 4;
322+
323+
// Specify stride lengths:
324+
const int strideX = 1;
325+
const int strideY = 1;
326+
327+
// Perform operation:
328+
c_sger( CblasRowMajor, M, N, 1.0, x, strideX, y, strideY, A, N );
329+
330+
// Print the result:
331+
for ( int i = 0; i < M; i++ ) {
332+
for ( int j = 0; j < N; j++ ) {
333+
printf( "A[%i,%i] = %f\n", i, j, A[ (i*N)+j ] );
334+
}
335+
}
336+
337+
// Perform operation using alterntive indexing semantics:
338+
c_sger( CblasRowMajor, M, N, 1.0, x, strideX, 0, y, 0, strideY, A, N, 1, 0 );
339+
340+
// Print the result:
341+
for ( int i = 0; i < M; i++ ) {
342+
for ( int j = 0; j < N; j++ ) {
343+
printf( "A[%i,%i] = %f\n", i, j, A[ (i*N)+j ] );
344+
}
345+
}
346+
}
237347
```
238348
239349
</section>
@@ -258,7 +368,7 @@ TODO
258368
259369
[blas]: http://www.netlib.org/blas
260370
261-
[blas-sger]: https://www.netlib.org/lapack/explore-html/d8/d75/group__ger_ga95baec6bb0a84393d7bc67212b566ab0.html#ga95baec6bb0a84393d7bc67212b566ab0
371+
[blas-sger]: https://www.netlib.org/lapack/explore-html/d8/d75/group__ger_ga95baec6bb0a84393d7bc67212b566ab0.html
262372
263373
[mdn-float32array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Float32Array
264374
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 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 sger = tryRequire( resolve( __dirname, './../lib/sger.native.js' ) );
36+
var opts = {
37+
'skip': ( sger 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 - array dimension size
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark( N ) {
54+
var x = uniform( N, -10.0, 10.0, options );
55+
var y = uniform( N, -10.0, 10.0, options );
56+
var A = uniform( N*N, -10.0, 10.0, options );
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 = sger( 'row-major', N, N, 1.0, x, 1, y, 1, A, N );
72+
if ( isnanf( z[ i%z.length ] ) ) {
73+
b.fail( 'should not return NaN' );
74+
}
75+
}
76+
b.toc();
77+
if ( isnanf( 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 len;
95+
var min;
96+
var max;
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+
len = floor( pow( pow( 10, i ), 1.0/2.0 ) );
105+
f = createBenchmark( len );
106+
bench( pkg+'::native:size='+(len*len), opts, f );
107+
}
108+
}
109+
110+
main();

0 commit comments

Comments
 (0)