Skip to content

Commit cd13567

Browse files
committed
feat: add blas/ext/base/dwxmy
--- 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_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - 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: passed - 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: passed - task: lint_c_examples status: passed - task: lint_c_benchmarks status: passed - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 7d69621 commit cd13567

33 files changed

Lines changed: 4628 additions & 0 deletions
Lines changed: 356 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,356 @@
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+
# dwxmy
22+
23+
> Perform the element-wise operation `w = x * y` for double-precision floating-point strided arrays.
24+
25+
<section class="intro">
26+
27+
This BLAS extension implements the operation
28+
29+
<!-- <equation class="equation" label="eq:wxmy" align="center" raw="\mathbf{w} = \mathbf{x} \odot \mathbf{y}" alt="Equation for wxmy operation."> -->
30+
31+
```math
32+
\mathbf{w} = \mathbf{x} \odot \mathbf{y}
33+
```
34+
35+
<!-- </equation> -->
36+
37+
where `⊙` denotes the [Hadamard product][hadamard-product].
38+
39+
</section>
40+
41+
<!-- /.intro -->
42+
43+
<section class="usage">
44+
45+
## Usage
46+
47+
```javascript
48+
var dwxmy = require( '@stdlib/blas/ext/base/dwxmy' );
49+
```
50+
51+
#### dwxmy( N, x, strideX, y, strideY, w, strideW )
52+
53+
Performs the element-wise operation `w = x * y` for double-precision floating-point strided arrays.
54+
55+
```javascript
56+
var Float64Array = require( '@stdlib/array/float64' );
57+
58+
var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
59+
var y = new Float64Array( [ 2.0, 3.0, 4.0, 5.0, 6.0 ] );
60+
var w = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
61+
62+
dwxmy( x.length, x, 1, y, 1, w, 1 );
63+
// w => <Float64Array>[ 2.0, 6.0, 12.0, 20.0, 30.0 ]
64+
```
65+
66+
The function has the following parameters:
67+
68+
- **N**: number of indexed elements.
69+
- **x**: first input [`Float64Array`][@stdlib/array/float64].
70+
- **strideX**: stride length for `x`.
71+
- **y**: second input [`Float64Array`][@stdlib/array/float64].
72+
- **strideY**: stride length for `y`.
73+
- **w**: output [`Float64Array`][@stdlib/array/float64].
74+
- **strideW**: stride length for `w`.
75+
76+
The `N` and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to multiply every other element of `x` by every other element of `y`:
77+
78+
```javascript
79+
var Float64Array = require( '@stdlib/array/float64' );
80+
81+
var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
82+
var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
83+
var w = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
84+
85+
dwxmy( 3, x, 2, y, 2, w, 2 );
86+
// w => <Float64Array>[ 1.0, 0.0, 9.0, 0.0, 25.0, 0.0 ]
87+
```
88+
89+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
90+
91+
```javascript
92+
var Float64Array = require( '@stdlib/array/float64' );
93+
94+
// Initial arrays...
95+
var x0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
96+
var y0 = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
97+
var w0 = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );
98+
99+
// Create offset views...
100+
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
101+
var y1 = new Float64Array( y0.buffer, y0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
102+
var w1 = new Float64Array( w0.buffer, w0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
103+
104+
dwxmy( 3, x1, 1, y1, 1, w1, 1 );
105+
// w0 => <Float64Array>[ 0.0, 4.0, 9.0, 16.0, 0.0, 0.0 ]
106+
```
107+
108+
<!-- lint disable maximum-heading-length -->
109+
110+
#### dwxmy.ndarray( N, x, strideX, offsetX, y, strideY, offsetY, w, strideW, offsetW )
111+
112+
<!-- lint enable maximum-heading-length -->
113+
114+
Performs the element-wise operation `w = x * y` for double-precision floating-point strided arrays using alternative indexing semantics.
115+
116+
```javascript
117+
var Float64Array = require( '@stdlib/array/float64' );
118+
119+
var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
120+
var y = new Float64Array( [ 2.0, 3.0, 4.0, 5.0, 6.0 ] );
121+
var w = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
122+
123+
dwxmy.ndarray( x.length, x, 1, 0, y, 1, 0, w, 1, 0 );
124+
// w => <Float64Array>[ 2.0, 6.0, 12.0, 20.0, 30.0 ]
125+
```
126+
127+
The function has the following additional parameters:
128+
129+
- **offsetX**: starting index for `x`.
130+
- **offsetY**: starting index for `y`.
131+
- **offsetW**: starting index for `w`.
132+
133+
While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to multiply the last three elements of `x` by the last three elements of `y` and assign to the last three elements of `w`:
134+
135+
```javascript
136+
var Float64Array = require( '@stdlib/array/float64' );
137+
138+
var x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
139+
var y = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] );
140+
var w = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
141+
142+
dwxmy.ndarray( 3, x, 1, x.length-3, y, 1, y.length-3, w, 1, w.length-3 );
143+
// w => <Float64Array>[ 0.0, 0.0, 9.0, 16.0, 25.0 ]
144+
```
145+
146+
</section>
147+
148+
<!-- /.usage -->
149+
150+
<section class="notes">
151+
152+
## Notes
153+
154+
- If `N <= 0`, both functions return `w` unchanged.
155+
156+
</section>
157+
158+
<!-- /.notes -->
159+
160+
<section class="examples">
161+
162+
## Examples
163+
164+
<!-- eslint no-undef: "error" -->
165+
166+
```javascript
167+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
168+
var dwxmy = require( '@stdlib/blas/ext/base/dwxmy' );
169+
170+
var x = discreteUniform( 10, -100, 100, {
171+
'dtype': 'float64'
172+
});
173+
console.log( x );
174+
175+
var y = discreteUniform( 10, -100, 100, {
176+
'dtype': 'float64'
177+
});
178+
console.log( y );
179+
180+
var w = discreteUniform( 10, -100, 100, {
181+
'dtype': 'float64'
182+
});
183+
console.log( w );
184+
185+
dwxmy( x.length, x, 1, y, 1, w, 1 );
186+
console.log( w );
187+
```
188+
189+
</section>
190+
191+
<!-- /.examples -->
192+
193+
<!-- C interface documentation. -->
194+
195+
* * *
196+
197+
<section class="c">
198+
199+
## C APIs
200+
201+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
202+
203+
<section class="intro">
204+
205+
</section>
206+
207+
<!-- /.intro -->
208+
209+
<!-- C usage documentation. -->
210+
211+
<section class="usage">
212+
213+
### Usage
214+
215+
```c
216+
#include "stdlib/blas/ext/base/dwxmy.h"
217+
```
218+
219+
#### stdlib_strided_dwxmy( N, \*X, strideX, \*Y, strideY, \*W, strideW )
220+
221+
Performs the element-wise operation `W = X * Y` for double-precision floating-point strided arrays.
222+
223+
```c
224+
const double x[] = { 1.0, 2.0, 3.0, 4.0 };
225+
const double y[] = { 2.0, 3.0, 4.0, 5.0 };
226+
double w[] = { 0.0, 0.0, 0.0, 0.0 };
227+
228+
stdlib_strided_dwxmy( 4, x, 1, y, 1, w, 1 );
229+
```
230+
231+
The function accepts the following arguments:
232+
233+
- **N**: `[in] CBLAS_INT` number of indexed elements.
234+
- **X**: `[in] double*` first input array.
235+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
236+
- **Y**: `[in] double*` second input array.
237+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
238+
- **W**: `[out] double*` output array.
239+
- **strideW**: `[in] CBLAS_INT` stride length for `W`.
240+
241+
```c
242+
void stdlib_strided_dwxmy( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const double *Y, const CBLAS_INT strideY, double *W, const CBLAS_INT strideW );
243+
```
244+
245+
<!-- lint disable maximum-heading-length -->
246+
247+
#### stdlib_strided_dwxmy_ndarray( N, \*X, strideX, offsetX, \*Y, strideY, offsetY, \*W, strideW, offsetW )
248+
249+
<!-- lint enable maximum-heading-length -->
250+
251+
Performs the element-wise operation `W = X * Y` for double-precision floating-point strided arrays using alternative indexing semantics.
252+
253+
```c
254+
const double x[] = { 1.0, 2.0, 3.0, 4.0 };
255+
const double y[] = { 2.0, 3.0, 4.0, 5.0 };
256+
double w[] = { 0.0, 0.0, 0.0, 0.0 };
257+
258+
stdlib_strided_dwxmy_ndarray( 4, x, 1, 0, y, 1, 0, w, 1, 0 );
259+
```
260+
261+
The function accepts the following arguments:
262+
263+
- **N**: `[in] CBLAS_INT` number of indexed elements.
264+
- **X**: `[in] double*` first input array.
265+
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
266+
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
267+
- **Y**: `[in] double*` second input array.
268+
- **strideY**: `[in] CBLAS_INT` stride length for `Y`.
269+
- **offsetY**: `[in] CBLAS_INT` starting index for `Y`.
270+
- **W**: `[out] double*` output array.
271+
- **strideW**: `[in] CBLAS_INT` stride length for `W`.
272+
- **offsetW**: `[in] CBLAS_INT` starting index for `W`.
273+
274+
```c
275+
void stdlib_strided_dwxmy_ndarray( const CBLAS_INT N, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const double *Y, const CBLAS_INT strideY, const CBLAS_INT offsetY, double *W, const CBLAS_INT strideW, const CBLAS_INT offsetW );
276+
```
277+
278+
</section>
279+
280+
<!-- /.usage -->
281+
282+
<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
283+
284+
<section class="notes">
285+
286+
</section>
287+
288+
<!-- /.notes -->
289+
290+
<!-- C API usage examples. -->
291+
292+
<section class="examples">
293+
294+
### Examples
295+
296+
```c
297+
#include "stdlib/blas/ext/base/dwxmy.h"
298+
#include <stdio.h>
299+
300+
int main( void ) {
301+
// Create strided arrays:
302+
const double x[] = { 1.0, -2.0, 3.0, -4.0, 5.0, -6.0, 7.0, -8.0 };
303+
const double y[] = { 2.0, 3.0, -1.0, 4.0, -2.0, 5.0, -3.0, 6.0 };
304+
double w[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
305+
306+
// Specify the number of indexed elements:
307+
const int N = 8;
308+
309+
// Specify strides:
310+
const int strideX = 1;
311+
const int strideY = 1;
312+
const int strideW = 1;
313+
314+
// Perform the element-wise operation `w = x * y`:
315+
stdlib_strided_dwxmy( N, x, strideX, y, strideY, w, strideW );
316+
317+
// Print the result:
318+
for ( int i = 0; i < 8; i++ ) {
319+
printf( "w[ %i ] = %lf\n", i, w[ i ] );
320+
}
321+
}
322+
```
323+
324+
</section>
325+
326+
<!-- /.examples -->
327+
328+
</section>
329+
330+
<!-- /.c -->
331+
332+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
333+
334+
<section class="related">
335+
336+
</section>
337+
338+
<!-- /.related -->
339+
340+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
341+
342+
<section class="links">
343+
344+
[@stdlib/array/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64
345+
346+
[hadamard-product]: https://en.wikipedia.org/wiki/Hadamard_product_(matrices)
347+
348+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
349+
350+
<!-- <related-links> -->
351+
352+
<!-- </related-links> -->
353+
354+
</section>
355+
356+
<!-- /.links -->

0 commit comments

Comments
 (0)