Skip to content

Commit 7e11338

Browse files
headlessNodekgryte
andauthored
feat: add blas/ext/base/zfill
PR-URL: #2907 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 8499db6 commit 7e11338

36 files changed

+3789
-16
lines changed

lib/node_modules/@stdlib/blas/ext/base/cfill/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ var Complex64 = require( '@stdlib/complex/float32/ctor' );
109109
var realf = require( '@stdlib/complex/float32/real' );
110110
var imagf = require( '@stdlib/complex/float32/imag' );
111111

112-
// Create the underlying floating-point array
112+
// Create the underlying floating-point array:
113113
var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
114114

115115
// Initial array:

lib/node_modules/@stdlib/blas/ext/base/cfill/docs/repl.txt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@
4343
-5.0
4444

4545
// Using `N` and stride parameters:
46-
> var x = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
47-
> var alpha = new {{alias:@stdlib/complex/float32/ctor}}( 5.0, -5.0 );
46+
> x = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
47+
> alpha = new {{alias:@stdlib/complex/float32/ctor}}( 5.0, -5.0 );
4848
> {{alias}}( 2, alpha, x, 2 );
49-
> var z = x.get( 0 );
50-
> var re = {{alias:@stdlib/complex/float32/real}}( z )
49+
> z = x.get( 0 );
50+
> re = {{alias:@stdlib/complex/float32/real}}( z )
5151
5.0
52-
> var im = {{alias:@stdlib/complex/float32/imag}}( z )
52+
> im = {{alias:@stdlib/complex/float32/imag}}( z )
5353
-5.0
5454
> z = x.get( 1 );
5555
> re = {{alias:@stdlib/complex/float32/real}}( z )
@@ -60,12 +60,12 @@
6060
// Using view offsets:
6161
> var x0 = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
6262
> var x1 = new {{alias:@stdlib/array/complex64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
63-
> var alpha = new {{alias:@stdlib/complex/float32/ctor}}( 5.0, -5.0 );
63+
> alpha = new {{alias:@stdlib/complex/float32/ctor}}( 5.0, -5.0 );
6464
> {{alias}}( 2, alpha, x1, 1 );
65-
> var z = x0.get( 0 );
66-
> var re = {{alias:@stdlib/complex/float32/real}}( z )
65+
> z = x0.get( 0 );
66+
> re = {{alias:@stdlib/complex/float32/real}}( z )
6767
1.0
68-
> var im = {{alias:@stdlib/complex/float32/imag}}( z )
68+
> im = {{alias:@stdlib/complex/float32/imag}}( z )
6969
2.0
7070
> z = x0.get( 1 );
7171
> re = {{alias:@stdlib/complex/float32/real}}( z )
@@ -117,13 +117,13 @@
117117
2.0
118118

119119
// Using an index offset:
120-
> var x = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
121-
> var alpha = new {{alias:@stdlib/complex/float32/ctor}}( 5.0, -5.0 );
120+
> x = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
121+
> alpha = new {{alias:@stdlib/complex/float32/ctor}}( 5.0, -5.0 );
122122
> {{alias}}.ndarray( 2, alpha, x, 2, 1 );
123-
> var z = x.get( 0 );
124-
> var re = {{alias:@stdlib/complex/float32/real}}( z )
123+
> z = x.get( 0 );
124+
> re = {{alias:@stdlib/complex/float32/real}}( z )
125125
1.0
126-
> var im = {{alias:@stdlib/complex/float32/imag}}( z )
126+
> im = {{alias:@stdlib/complex/float32/imag}}( z )
127127
2.0
128128
> z = x.get( 1 );
129129
> re = {{alias:@stdlib/complex/float32/real}}( z )

lib/node_modules/@stdlib/blas/ext/base/cfill/lib/ndarray.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var addon = require( './cfill.native.js' );
3131
* Fills a single-precision complex floating-point strided array with a specified scalar constant.
3232
*
3333
* @param {PositiveInteger} N - number of indexed elements
34-
* @param {number} alpha - scalar constant
34+
* @param {ComplexLike} alpha - scalar constant
3535
* @param {Complex64Array} x - input array
3636
* @param {integer} stride - index increment
3737
* @param {NonNegativeInteger} offset - starting index
Lines changed: 281 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 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+
# zfill
22+
23+
> Fill a double-precision complex floating-point strided array with a specified scalar constant.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var zfill = require( '@stdlib/blas/ext/base/zfill' );
31+
```
32+
33+
#### zfill( N, alpha, x, stride )
34+
35+
Fills a double-precision complex floating-point strided array `x` with a specified scalar constant `alpha`.
36+
37+
```javascript
38+
var Float64Array = require( '@stdlib/array/float64' );
39+
var Complex128Array = require( '@stdlib/array/complex128' );
40+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
41+
var real = require( '@stdlib/complex/float64/real' );
42+
var imag = require( '@stdlib/complex/float64/imag' );
43+
44+
var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
45+
var x = new Complex128Array( arr );
46+
47+
var alpha = new Complex128( 10.0, 10.0 );
48+
49+
zfill( x.length, alpha, x, 1 );
50+
51+
var y = x.get( 0 );
52+
// returns <Complex128>
53+
54+
var re = real( y );
55+
// returns 10.0
56+
57+
var im = imag( y );
58+
// returns 10.0
59+
```
60+
61+
The function has the following parameters:
62+
63+
- **N**: number of indexed elements.
64+
- **alpha**: scalar constant.
65+
- **x**: input [`Complex128Array`][@stdlib/array/complex128].
66+
- **stride**: index increment.
67+
68+
The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to fill every other element
69+
70+
```javascript
71+
var Float64Array = require( '@stdlib/array/float64' );
72+
var Complex128Array = require( '@stdlib/array/complex128' );
73+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
74+
var real = require( '@stdlib/complex/float64/real' );
75+
var imag = require( '@stdlib/complex/float64/imag' );
76+
77+
var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
78+
var x = new Complex128Array( arr );
79+
80+
var alpha = new Complex128( 10.0, 10.0 );
81+
82+
zfill( 2, alpha, x, 2 );
83+
84+
var y = x.get( 0 );
85+
// returns <Complex128>
86+
87+
var re = real( y );
88+
// returns 10.0
89+
90+
var im = imag( y );
91+
// returns 10.0
92+
93+
y = x.get( 1 );
94+
// returns <Complex128>
95+
96+
re = real( y );
97+
// returns 3.0
98+
99+
im = imag( y );
100+
// returns 4.0
101+
```
102+
103+
Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.
104+
105+
```javascript
106+
var Float64Array = require( '@stdlib/array/float64' );
107+
var Complex128Array = require( '@stdlib/array/complex128' );
108+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
109+
var real = require( '@stdlib/complex/float64/real' );
110+
var imag = require( '@stdlib/complex/float64/imag' );
111+
112+
// Create the underlying floating-point array:
113+
var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
114+
115+
// Initial array:
116+
var x0 = new Complex128Array( arr );
117+
118+
// Create an offset view:
119+
var x1 = new Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
120+
121+
// Define a scalar constant:
122+
var alpha = new Complex128( 10.0, 10.0 );
123+
124+
// Fill every other element:
125+
zfill( 2, alpha, x1, 2 );
126+
127+
var y = x0.get( 0 );
128+
// returns <Complex128>
129+
130+
var re = real( y );
131+
// returns 1.0
132+
133+
var im = imag( y );
134+
// returns 2.0
135+
136+
y = x0.get( 1 );
137+
// returns <Complex128>
138+
139+
re = real( y );
140+
// returns 10.0
141+
142+
im = imag( y );
143+
// returns 10.0
144+
```
145+
146+
#### zfill.ndarray( N, alpha, x, stride, offset )
147+
148+
Fills a double-precision complex floating-point strided array `x` with a specified scalar constant `alpha` using alternative indexing semantics.
149+
150+
```javascript
151+
var Float64Array = require( '@stdlib/array/float64' );
152+
var Complex128Array = require( '@stdlib/array/complex128' );
153+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
154+
var real = require( '@stdlib/complex/float64/real' );
155+
var imag = require( '@stdlib/complex/float64/imag' );
156+
157+
var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
158+
var x = new Complex128Array( arr );
159+
160+
var alpha = new Complex128( 10.0, 10.0 );
161+
162+
zfill.ndarray( x.length, alpha, x, 1, 0 );
163+
164+
var y = x.get( 0 );
165+
// returns <Complex128>
166+
167+
var re = real( y );
168+
// returns 10.0
169+
170+
var im = imag( y );
171+
// returns 10.0
172+
```
173+
174+
The function has the following additional parameters:
175+
176+
- **offset**: starting index.
177+
178+
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 only the last two elements of the strided array
179+
180+
```javascript
181+
var Float64Array = require( '@stdlib/array/float64' );
182+
var Complex128Array = require( '@stdlib/array/complex128' );
183+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
184+
var real = require( '@stdlib/complex/float64/real' );
185+
var imag = require( '@stdlib/complex/float64/imag' );
186+
187+
var arr = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
188+
var x = new Complex128Array( arr );
189+
190+
var alpha = new Complex128( 10.0, 10.0 );
191+
192+
zfill.ndarray( 2, alpha, x, 1, x.length-2 );
193+
194+
var y = x.get( 0 );
195+
// returns <Complex128>
196+
197+
var re = real( y );
198+
// returns 1.0
199+
200+
var im = imag( y );
201+
// returns 2.0
202+
203+
y = x.get( 1 );
204+
// returns <Complex128>
205+
206+
re = real( y );
207+
// returns 10.0
208+
209+
im = imag( y );
210+
// returns 10.0
211+
212+
y = x.get( 2 );
213+
// returns <Complex128>
214+
215+
re = real( y );
216+
// returns 10.0
217+
218+
im = imag( y );
219+
// returns 10.0
220+
```
221+
222+
</section>
223+
224+
<!-- /.usage -->
225+
226+
<section class="notes">
227+
228+
## Notes
229+
230+
- If `N <= 0`, both functions return the strided array unchanged.
231+
232+
</section>
233+
234+
<!-- /.notes -->
235+
236+
<section class="examples">
237+
238+
## Examples
239+
240+
<!-- eslint no-undef: "error" -->
241+
242+
```javascript
243+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
244+
var filledarrayBy = require( '@stdlib/array/filled-by' );
245+
var Complex128 = require( '@stdlib/complex/float64/ctor' );
246+
var zfill = require( '@stdlib/blas/ext/base/zfill' );
247+
248+
function rand() {
249+
return new Complex128( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
250+
}
251+
252+
var x = filledarrayBy( 10, 'complex128', rand );
253+
var alpha = new Complex128( 10.0, 10.0 );
254+
255+
zfill( x.length, alpha, x, 1 );
256+
console.log( x.get( 0 ).toString() );
257+
```
258+
259+
</section>
260+
261+
<!-- /.examples -->
262+
263+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
264+
265+
<section class="related">
266+
267+
</section>
268+
269+
<!-- /.related -->
270+
271+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
272+
273+
<section class="links">
274+
275+
[@stdlib/array/complex128]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex128
276+
277+
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
278+
279+
</section>
280+
281+
<!-- /.links -->

0 commit comments

Comments
 (0)