Skip to content

Commit 264d34d

Browse files
feat add blas/ext/base/dapxsumors
1 parent 934c483 commit 264d34d

32 files changed

+4369
-2
lines changed

lib/node_modules/@stdlib/blas/ext/base/dapxsumors/manifest.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"options": {
3-
"task": "build"
3+
"task": "build",
4+
"wasm": false
45
},
56
"fields": [
67
{
@@ -27,6 +28,7 @@
2728
"confs": [
2829
{
2930
"task": "build",
31+
"wasm": false,
3032
"src": [
3133
"./src/main.c"
3234
],
@@ -48,6 +50,7 @@
4850
},
4951
{
5052
"task": "benchmark",
53+
"wasm": false,
5154
"src": [
5255
"./src/main.c"
5356
],
@@ -63,6 +66,24 @@
6366
},
6467
{
6568
"task": "examples",
69+
"wasm": false,
70+
"src": [
71+
"./src/main.c"
72+
],
73+
"include": [
74+
"./include"
75+
],
76+
"libraries": [],
77+
"libpath": [],
78+
"dependencies": [
79+
"@stdlib/math/base/special/abs",
80+
"@stdlib/blas/base/shared",
81+
"@stdlib/strided/base/stride2offset"
82+
]
83+
},
84+
{
85+
"task": "build",
86+
"wasm": true,
6687
"src": [
6788
"./src/main.c"
6889
],
Lines changed: 301 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,301 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# dapxsumors
22+
23+
> Add a scalar constant to each double-precision floating-point strided array element and compute the sum using ordinary recursive summation.
24+
25+
<section class="intro">
26+
27+
</section>
28+
29+
<!-- /.intro -->
30+
31+
<section class="usage">
32+
33+
## Usage
34+
35+
```javascript
36+
var dapxsumors = require( '@stdlib/blas/ext/base/wasm/dapxsumors' );
37+
```
38+
39+
#### dapxsumors.main( N, alpha, x, strideX )
40+
41+
Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using ordinary recursive summation.
42+
43+
```javascript
44+
var Float64Array = require( '@stdlib/array/float64' );
45+
46+
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
47+
48+
var v = dapxsumors( x.length, 5.0, x, 1 );
49+
// returns 16.0
50+
```
51+
52+
The function has the following parameters:
53+
54+
- **N**: number of indexed elements.
55+
- **alpha**: scalar constant.
56+
- **x**: input [`Float64Array`][@stdlib/array/float64].
57+
- **strideX**: stride length for `x`.
58+
59+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element in `x`,
60+
61+
```javascript
62+
var Float64Array = require( '@stdlib/array/float64' );
63+
64+
var x = new Float64Array( [ 1.0, 2.0, 2.0, -7.0, -2.0, 3.0, 4.0, 2.0 ] );
65+
66+
var v = dapxsumors( 4, 5.0, x, 2 );
67+
// returns 25.0
68+
```
69+
70+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
71+
72+
<!-- eslint-disable stdlib/capitalized-comments -->
73+
74+
```javascript
75+
var Float64Array = require( '@stdlib/array/float64' );
76+
77+
var x0 = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
78+
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
79+
80+
var v = dapxsumors( 4, 5.0, x1, 2 );
81+
// returns 25.0
82+
```
83+
84+
#### dapxsumors.ndarray( N, alpha, x, strideX, offsetX )
85+
86+
Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using ordinary recursive summation and alternative indexing semantics.
87+
88+
```javascript
89+
var Float64Array = require( '@stdlib/array/float64' );
90+
91+
var x = new Float64Array( [ 1.0, -2.0, 2.0 ] );
92+
93+
var v = dapxsumors.ndarray( x.length, 5.0, x, 1, 0 );
94+
// returns 16.0
95+
```
96+
97+
The function has the following additional parameters:
98+
99+
- **offsetX**: starting index for `x`.
100+
101+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access every other element starting from the second element:
102+
103+
```javascript
104+
var Float64Array = require( '@stdlib/array/float64' );
105+
106+
var x = new Float64Array( [ 2.0, 1.0, 2.0, -2.0, -2.0, 2.0, 3.0, 4.0 ] );
107+
108+
var v = dapxsumors.ndarray( 4, 5.0, x, 2, 1 );
109+
// returns 25.0
110+
```
111+
112+
* * *
113+
114+
### Module
115+
116+
#### dapxsumors.Module( memory )
117+
118+
Returns a new WebAssembly [module wrapper][@stdlib/wasm/module-wrapper] instance which uses the provided WebAssembly [memory][@stdlib/wasm/memory] instance as its underlying memory.
119+
120+
<!-- eslint-disable node/no-sync -->
121+
122+
```javascript
123+
var Memory = require( '@stdlib/wasm/memory' );
124+
125+
// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
126+
var mem = new Memory({
127+
'initial': 10,
128+
'maximum': 100
129+
});
130+
131+
// Create a BLAS routine:
132+
var mod = new dapxsumors.Module( mem );
133+
// returns <Module>
134+
135+
// Initialize the routine:
136+
mod.initializeSync();
137+
```
138+
139+
#### dapxsumors.Module.prototype.main( N, alpha, xp, sx )
140+
141+
Adds a scalar constant to each double-precision floating-point stridedarray element and computes the sum using ordinary recursive summation.
142+
143+
<!-- eslint-disable node/no-sync -->
144+
145+
```javascript
146+
var Memory = require( '@stdlib/wasm/memory' );
147+
var oneTo = require( '@stdlib/array/one-to' );
148+
var zeros = require( '@stdlib/array/zeros' );
149+
150+
// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
151+
var mem = new Memory({
152+
'initial': 10,
153+
'maximum': 100
154+
});
155+
156+
// Create a BLAS routine:
157+
var mod = new dapxsumors.Module( mem );
158+
// returns <Module>
159+
160+
// Initialize the routine:
161+
mod.initializeSync();
162+
163+
// Define a vector data type:
164+
var dtype = 'float64';
165+
166+
// Specify a vector length:
167+
var N = 3;
168+
169+
// Define a pointer (i.e., byte offset) for storing the input vector:
170+
var xptr = 0;
171+
172+
// Write vector values to module memory:
173+
mod.write( xptr, oneTo( N, dtype ) );
174+
175+
// Perform computation:
176+
var sum = mod.main( N, 5.0, xptr, 1 );
177+
// returns 21.0
178+
```
179+
180+
The function has the following parameters:
181+
182+
- **N**: number of indexed elements.
183+
- **alpha**: scalar constant.
184+
- **xp**: input [`Float64Array`][@stdlib/array/float64] pointer (i.e., byte offset).
185+
- **sx**: stride length for `x`.
186+
187+
#### dapxsumors.Module.prototype.ndarray( N, alpha, xp, sx, ox )
188+
189+
Adds a scalar constant to each double-precision floating-point strided array element and computes the sum using ordinary recursive summation and alternative indexing semantics.
190+
191+
<!-- eslint-disable node/no-sync -->
192+
193+
```javascript
194+
var Memory = require( '@stdlib/wasm/memory' );
195+
var oneTo = require( '@stdlib/array/one-to' );
196+
var zeros = require( '@stdlib/array/zeros' );
197+
198+
// Create a new memory instance with an initial size of 10 pages (640KiB) and a maximum size of 100 pages (6.4MiB):
199+
var mem = new Memory({
200+
'initial': 10,
201+
'maximum': 100
202+
});
203+
204+
// Create a BLAS routine:
205+
var mod = new dapxsumors.Module( mem );
206+
// returns <Module>
207+
208+
// Initialize the routine:
209+
mod.initializeSync();
210+
211+
// Define a vector data type:
212+
var dtype = 'float64';
213+
214+
// Specify a vector length:
215+
var N = 3;
216+
217+
// Define a pointer (i.e., byte offset) for storing the input vector:
218+
var xptr = 0;
219+
220+
// Write vector values to module memory:
221+
mod.write( xptr, oneTo( N, dtype ) );
222+
223+
// Perform computation:
224+
var sum = mod.main( N, 5.0, xptr, 1 );
225+
// returns 21.0
226+
```
227+
228+
The function has the following additional parameters:
229+
230+
- **ox**: starting index for `x`.
231+
232+
</section>
233+
234+
<!-- /.usage -->
235+
236+
<section class="notes">
237+
238+
* * *
239+
240+
## Notes
241+
242+
- If `N <= 0`, both `main` and `ndarray` methods return `0.0`.
243+
- This package implements routines using WebAssembly. When provided arrays which are not allocated on a `dapxsumors` module memory instance, data must be explicitly copied to module memory prior to computation. Data movement may entail a performance cost, and, thus, if you are using arrays external to module memory, you should prefer using [`@stdlib/blas/base/dapxsumors`][@stdlib/blas/ext/base/dapxsumors]. However, if working with arrays which are allocated and explicitly managed on module memory, you can achieve better performance when compared to the pure JavaScript implementations found in [`@stdlib/blas/base/dapxsumors`][@stdlib/blas/ext/base/dapxsumors]. Beware that such performance gains may come at the cost of additional complexity when having to perform manual memory management. Choosing between implementations depends heavily on the particular needs and constraints of your application, with no one choice universally better than the other.
244+
245+
</section>
246+
247+
<!-- /.notes -->
248+
249+
<section class="examples">
250+
251+
* * *
252+
253+
## Examples
254+
255+
<!-- eslint no-undef: "error" -->
256+
257+
```javascript
258+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
259+
var dapxsumors = require( '@stdlib/blas/ext/base/wasm/dapxsumors' );
260+
261+
var opts = {
262+
'dtype': 'float64'
263+
};
264+
var x = discreteUniform( 10, 0, 100, opts );
265+
console.log( x );
266+
267+
var sum = dapxsumkbn.ndarray( x.length, 5.0, x, 1, 0 );
268+
console.log( sum );
269+
```
270+
271+
</section>
272+
273+
<!-- /.examples -->
274+
275+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
276+
277+
<section class="related">
278+
279+
</section>
280+
281+
<!-- /.related -->
282+
283+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
284+
285+
<section class="links">
286+
287+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
288+
289+
[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64
290+
291+
[@stdlib/wasm/memory]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/wasm/memory
292+
293+
[@stdlib/wasm/module-wrapper]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/wasm/module-wrapper
294+
295+
[@stdlib/blas/ext/base/dapxsumors]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/dapxsumors
296+
297+
[l1norm]: https://en.wikipedia.org/wiki/Norm_%28mathematics%29
298+
299+
</section>
300+
301+
<!-- /.links -->

0 commit comments

Comments
 (0)