Skip to content

Commit b267c91

Browse files
authored
Merge branch 'develop' into c-lint-error
2 parents c3e7558 + 0cf9821 commit b267c91

24 files changed

Lines changed: 2853 additions & 0 deletions

File tree

lib/node_modules/@stdlib/array/docs/types/index.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ import mskreject = require( '@stdlib/array/mskreject' );
6262
import nans = require( '@stdlib/array/nans' );
6363
import nansLike = require( '@stdlib/array/nans-like' );
6464
import nextDataType = require( '@stdlib/array/next-dtype' );
65+
import nulls = require( '@stdlib/array/nulls' );
6566
import oneTo = require( '@stdlib/array/one-to' );
6667
import oneToLike = require( '@stdlib/array/one-to-like' );
6768
import ones = require( '@stdlib/array/ones' );
@@ -1008,6 +1009,27 @@ interface Namespace {
10081009
*/
10091010
nextDataType: typeof nextDataType;
10101011

1012+
/**
1013+
* Creates an array filled with nulls and having a specified length.
1014+
*
1015+
* The function recognizes the following data types:
1016+
*
1017+
* - `generic`: generic JavaScript values
1018+
*
1019+
* @param length - array length
1020+
* @param dtype - data type (default: 'generic')
1021+
* @returns filled array
1022+
*
1023+
* @example
1024+
* var arr = ns.nulls( 2 );
1025+
* // returns [ null, null ]
1026+
*
1027+
* @example
1028+
* var arr = ns.nulls( 2, 'generic' );
1029+
* // returns [ null, null ]
1030+
*/
1031+
nulls: typeof nulls;
1032+
10111033
/**
10121034
* Generates a linearly spaced numeric array whose elements increment by 1 starting from one.
10131035
*

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ The namespace exposes the following APIs:
4848
- <span class="signature">[`dasum( arrays )`][@stdlib/blas/base/ndarray/dasum]</span><span class="delimiter">: </span><span class="description">calculate the sum of absolute values for all elements in a one-dimensional double-precision floating-point ndarray.</span>
4949
- <span class="signature">[`ddot( arrays )`][@stdlib/blas/base/ndarray/ddot]</span><span class="delimiter">: </span><span class="description">calculate the dot product of two one-dimensional double-precision floating-point ndarrays.</span>
5050
- <span class="signature">[`gdot( arrays )`][@stdlib/blas/base/ndarray/gdot]</span><span class="delimiter">: </span><span class="description">calculate the dot product of two one-dimensional ndarrays.</span>
51+
- <span class="signature">[`sasum( arrays )`][@stdlib/blas/base/ndarray/sasum]</span><span class="delimiter">: </span><span class="description">calculate the sum of absolute values for all elements in a one-dimensional single-precision floating-point ndarray.</span>
5152
- <span class="signature">[`sdot( arrays )`][@stdlib/blas/base/ndarray/sdot]</span><span class="delimiter">: </span><span class="description">calculate the dot product of two one-dimensional single-precision floating-point ndarrays.</span>
5253

5354
</div>
@@ -97,6 +98,8 @@ console.log( objectKeys( ns ) );
9798

9899
[@stdlib/blas/base/ndarray/gdot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/ndarray/gdot
99100

101+
[@stdlib/blas/base/ndarray/sasum]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/ndarray/sasum
102+
100103
[@stdlib/blas/base/ndarray/sdot]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/base/ndarray/sdot
101104

102105
<!-- </toc-links> -->
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
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+
# gasum
22+
23+
> Calculate the sum of absolute values for all elements in a one-dimensional ndarray.
24+
25+
<section class="intro">
26+
27+
The [_L1_ norm][l1norm] is defined as
28+
29+
<!-- <equation class="equation" label="eq:l1norm" align="center" raw="\|\mathbf{x}\|_1 = \sum_{i=0}^{n-1} \vert x_i \vert" alt="L1 norm definition."> -->
30+
31+
```math
32+
\|\mathbf{x}\|_1 = \sum_{i=0}^{n-1} \vert x_i \vert
33+
```
34+
35+
<!-- <div class="equation" align="center" data-raw-text="\|\mathbf{x}\|_1 = \sum_{i=0}^{n-1} \vert x_i \vert" data-equation="eq:l1norm">
36+
<img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@30de397fadee10fa175a8332ae1447737f201818/lib/node_modules/@stdlib/blas/base/gasum/docs/img/equation_l1norm.svg" alt="L1 norm definition.">
37+
<br>
38+
</div> -->
39+
40+
<!-- </equation> -->
41+
42+
</section>
43+
44+
<!-- /.intro -->
45+
46+
<section class="usage">
47+
48+
## Usage
49+
50+
```javascript
51+
var gasum = require( '@stdlib/blas/base/ndarray/gasum' );
52+
```
53+
54+
#### gasum( arrays )
55+
56+
Computes the sum of absolute values for all elements in a one-dimensional ndarray.
57+
58+
```javascript
59+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
60+
61+
var xbuf = [ 1.0, -2.0, 3.0, -4.0, 5.0 ];
62+
var x = new ndarray( 'generic', xbuf, [ 5 ], [ 1 ], 0, 'row-major' );
63+
64+
var y = gasum( [ x ] );
65+
// returns 15.0
66+
```
67+
68+
The function has the following parameters:
69+
70+
- **arrays**: array-like object containing a one-dimensional input ndarray.
71+
72+
</section>
73+
74+
<!-- /.usage -->
75+
76+
<section class="notes">
77+
78+
</section>
79+
80+
<!-- /.notes -->
81+
82+
<section class="examples">
83+
84+
## Examples
85+
86+
<!-- eslint no-undef: "error" -->
87+
88+
```javascript
89+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
90+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
91+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
92+
var gasum = require( '@stdlib/blas/base/ndarray/gasum' );
93+
94+
var opts = {
95+
'dtype': 'generic'
96+
};
97+
98+
var xbuf = discreteUniform( 10, -500, 500, opts );
99+
var x = new ndarray( opts.dtype, xbuf, [ xbuf.length ], [ 1 ], 0, 'row-major' );
100+
console.log( ndarray2array( x ) );
101+
102+
var out = gasum( [ x ] );
103+
console.log( out );
104+
```
105+
106+
</section>
107+
108+
<!-- /.examples -->
109+
110+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
111+
112+
<section class="related">
113+
114+
</section>
115+
116+
<!-- /.related -->
117+
118+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
119+
120+
<section class="links">
121+
122+
[l1norm]: https://en.wikipedia.org/wiki/Norm_%28mathematics%29
123+
124+
</section>
125+
126+
<!-- /.links -->
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) 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/array/uniform' );
25+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
26+
var pow = require( '@stdlib/math/base/special/pow' );
27+
var ndarray = require( '@stdlib/ndarray/base/ctor' );
28+
var format = require( '@stdlib/string/format' );
29+
var pkg = require( './../package.json' ).name;
30+
var gasum = require( './../lib' );
31+
32+
33+
// VARIABLES //
34+
35+
var options = {
36+
'dtype': 'generic'
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 xbuf;
51+
var x;
52+
53+
xbuf = uniform( len, -100.0, 100.0, options );
54+
x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' );
55+
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 = gasum( [ x ] );
71+
if ( isnan( z ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
}
75+
b.toc();
76+
if ( isnan( z ) ) {
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 = pow( 10, i );
104+
f = createBenchmark( len );
105+
bench( format( '%s:len=%d', pkg, len ), f );
106+
}
107+
}
108+
109+
main();
Lines changed: 44 additions & 0 deletions
Loading
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
{{alias}}( arrays )
3+
Computes the sum of absolute values for all elements in a one-dimensional
4+
ndarray.
5+
6+
If provided an empty input ndarray, the function returns `0.0`.
7+
8+
Parameters
9+
----------
10+
arrays: ArrayLikeObject<ndarray>
11+
Array-like object containing a one-dimensional input ndarray.
12+
13+
Returns
14+
-------
15+
out: number
16+
The sum of absolute values.
17+
18+
Examples
19+
--------
20+
> var xbuf = [ 1.0, -2.0, 3.0, -4.0, 5.0 ];
21+
> var dt = 'generic';
22+
> var sh = [ xbuf.length ];
23+
> var st = [ 1 ];
24+
> var oo = 0;
25+
> var ord = 'row-major';
26+
> var x = new {{alias:@stdlib/ndarray/ctor}}( dt, xbuf, sh, st, oo, ord );
27+
> {{alias}}( [ x ] )
28+
15.0
29+
30+
See Also
31+
--------
32+

0 commit comments

Comments
 (0)