Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
293 changes: 293 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/cfill/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@
<!--

@license Apache-2.0

Copyright (c) 2024 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# cfill

> Fill a single-precision complex floating-point strided array with a specified complex floating-point constant.

<section class="usage">

## Usage

```javascript
var cfill = require( '@stdlib/blas/ext/base/cfill' );
```

#### cfill( N, alpha, x, stride )

Fills a single-precision complex floating-point strided array `x` with a specified complex floating-point constant `alpha`.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/imag' );

var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var x = new Complex64Array( arr );
var alpha = new Complex64( 10.0, 10.0 );

cfill( x.length, alpha, x, 1 );

var y = x.get( 0 );
// returns <Complex64>

var re = realf( y );
// returns 10.0

var im = imagf( y );
// returns 10.0
```

The function has the following parameters:

- **N**: number of indexed elements.
- **alpha**: complex constant.
- **x**: input [`Complex64Array`][@stdlib/array/complex64].
- **stride**: index increment.

The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to fill every other element

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/imag' );

var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var x = new Complex64Array( arr );
var alpha = new Complex64( 10.0, 10.0 );

cfill( 2, alpha, x, 2 );

var y = x.get( 0 );
// returns <Complex64>

var re = realf( y );
// returns 10.0

var im = imagf( y );
// returns 10.0

y = x.get( 1 );
// returns <Complex64>

re = realf( y );
// returns 3.0

im = imagf( y );
// returns 4.0
```

Note that indexing is relative to the first index. To introduce an offset, use [`typed array`][mdn-typed-array] views.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/imag' );

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

// Initial array...
var x0 = new Complex64Array( arr );

// Create an offset view...
var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

// Define the complex constant
var alpha = new Complex64( 10.0, 10.0 );

// Fill every other element...
cfill( 2, alpha, x1, 2 );

var y = x0.get( 0 );
// returns <Complex64>

var re = realf( y );
// returns 1.0

var im = imagf( y );
// returns 2.0

y = x0.get( 1 );
// returns <Complex64>

re = realf( y );
// returns 10.0

im = imagf( y );
// returns 10.0
```

#### cfill.ndarray( N, alpha, x, stride, offset )

Fills a single-precision complex floating-point strided array `x` with a specified complex floating-point constant `alpha` using alternative indexing semantics.

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/imag' );

var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] );
var x = new Complex64Array( arr );
var alpha = new Complex64( 10.0, 10.0 );

cfill.ndarray( x.length, alpha, x, 1, 0 );

var y = x.get( 0 );
// returns <Complex64>

var re = realf( y );
// returns 10.0

var im = imagf( y );
// returns 10.0
```

The function has the following additional parameters:

- **offset**: starting index.

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

```javascript
var Float32Array = require( '@stdlib/array/float32' );
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/imag' );

var arr = new Float32Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x = new Complex64Array( arr );
var alpha = new Complex64( 10.0, 10.0 );

cfill.ndarray( 2, alpha, x, 1, x.length-2 );

var y = x.get( 0 );
// returns <Complex64>

var re = realf( y );
// returns 1.0

var im = imagf( y );
// returns 2.0

y = x.get( 1 );
// returns <Complex64>

re = realf( y );
// returns 10.0

im = imagf( y );
// returns 10.0

y = x.get( 2 );
// returns <Complex64>

re = realf( y );
// returns 10.0

im = imagf( y );
// returns 10.0
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N <= 0`, both functions return the strided array unchanged.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```javascript
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var cfill = require( '@stdlib/blas/ext/base/cfill' );

function rand() {
return new Complex64( discreteUniform( 0, 10 ), discreteUniform( -5, 5 ) );
}

var x = filledarrayBy( 10, 'complex64', rand );

var alpha = new Complex64( 10.0, 10.0 );

cfill( x.length, alpha, x, 1 );
console.log( x.get( 0 ).toString() );
```

</section>

<!-- /.examples -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/blas/ext/base/dfill`][@stdlib/blas/ext/base/dfill]</span><span class="delimiter">: </span><span class="description">fill a double-precision floating-point strided array with a specified scalar constant.</span>
- <span class="package-name">[`@stdlib/blas/ext/base/gfill`][@stdlib/blas/ext/base/gfill]</span><span class="delimiter">: </span><span class="description">fill a strided array with a specified scalar constant.</span>

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/array/complex64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/complex64

[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray

<!-- <related-links> -->

[@stdlib/blas/ext/base/dfill]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/dfill

[@stdlib/blas/ext/base/gfill]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/blas/ext/base/gfill

<!-- </related-links> -->

</section>

<!-- /.links -->
Loading
Loading