Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
119 changes: 119 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<!--

@license Apache-2.0

Copyright (c) 2025 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 complex single-precision floating-point ndarray with a specified scalar constant.

<section class="usage">

## Usage

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

#### cfill( arrays )

Fills a complex single-precision floating-point ndarray `x` with a specified scalar constant `alpha`.

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var ndarray = require( '@stdlib/ndarray/ctor' );

var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' );

var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), {
'dtype': 'complex64'
});

var out = cfill( [ x, alpha ] );
// returns <ndarray>

var arr = ndarray2array( out );
// returns [ <Complex64>[ 10.0, 10.0 ], <Complex64>[ 10.0, 10.0 ] ]
```

The function has the following parameters:

- **arrays**: array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant.

</section>

<!-- /.usage -->

<section class="examples">

## Examples

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var ndarray = require( '@stdlib/ndarray/ctor' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/imag' );
var cfill = require( '@stdlib/blas/ext/base/ndarray/cfill' );

var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var x = new ndarray( 'complex64', buffer, [ 3 ], [ 1 ], 0, 'row-major' );

var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), {
'dtype': 'complex64'
});

cfill( [ x, alpha ] );

var v = x.get( 0 );
console.log( 'x[0] = %d + %di', realf( v ), imagf( v ) );
// => 'x[0] = 10 + 10i'

v = x.get( 1 );
console.log( 'x[1] = %d + %di', realf( v ), imagf( v ) );
// => 'x[1] = 10 + 10i'

v = x.get( 2 );
console.log( 'x[2] = %d + %di', realf( v ), imagf( v ) );
// => 'x[2] = 10 + 10i'
```

</section>

<!-- /.examples -->

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

<section class="related">

</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">

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2025 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.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var uniform = require( '@stdlib/random/array/uniform' );
var pow = require( '@stdlib/math/base/special/pow' );
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
var format = require( '@stdlib/string/format' );
var ndarray = require( '@stdlib/ndarray/ctor' );
var pkg = require( './../package.json' ).name;
var cfill = require( './../lib' );


// VARIABLES //

var options = {
'dtype': 'complex64'
};


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var alpha;
var xbuf;
var buf;
var x;

buf = uniform( len*2, 0.0, 100.0, {
'dtype': 'float32'
});
xbuf = new Complex64Array( buf.buffer );
x = new ndarray( options.dtype, xbuf, [ len ], [ 1 ], 0, 'row-major' );

alpha = scalar2ndarray( new Complex64( 5.0, 5.0 ), options );

return benchmark;

function benchmark( b ) {
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = cfill( [ x, alpha ] );
if ( out !== out ) {
b.fail( 'should not return NaN' );
}
}
b.toc();
if ( out !== out ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( format( '%s:len=%d', pkg, len ), f );
}
}

main();
28 changes: 28 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/ndarray/cfill/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

{{alias}}( arrays )
Fills a complex single-precision floating-point ndarray with a specified
scalar constant.

Parameters
----------
arrays: ArrayLikeObject<ndarray>
Array-like object containing a single one-dimensional input ndarray
and a zero-dimensional ndarray containing a scalar constant.

Returns
-------
out: ndarray
Input ndarray.

Examples
--------
> var buf = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] );
> var x = {{alias:@stdlib/ndarray/ctor}}( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' );
> var C64 = {{alias:@stdlib/complex/float32/ctor}};
> var s2n = {{alias:@stdlib/ndarray/from-scalar}};
> var alpha = s2n( new C64( 10.0, 10.0 ), { 'dtype': 'complex64' } );
> {{alias}}( [ x, alpha ] )
<ndarray>[ <Complex64>[ 10.0, 10.0 ], <Complex64>[ 10.0, 10.0 ] ]

See Also
--------
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2025 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.
*/

// TypeScript Version: 4.1

/// <reference types="@stdlib/types"/>

import { complex64ndarray } from '@stdlib/types/ndarray';

/**
* Fills a complex single-precision floating-point ndarray with a specified scalar constant.
*
* @param arrays - array-like object containing a single one-dimensional input ndarray and a zero-dimensional ndarray containing a scalar constant
* @returns input ndarray
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
* var scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
* var ndarray2array = require( '@stdlib/ndarray/to-array' );
* var ndarray = require( '@stdlib/ndarray/ctor' );
*
* var buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
* var x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' );
*
* var alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), {
* 'dtype': 'complex64'
* });
*
* var out = cfill( [ x, alpha ] );
* // returns <ndarray>
*
* var arr = ndarray2array( out );
* // returns [ <Complex64>[ 10.0, 10.0 ], <Complex64>[ 10.0, 10.0 ] ]
*/
declare function cfill( arrays: [ complex64ndarray, complex64ndarray ] ): complex64ndarray;


// EXPORTS //

export = cfill;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2025 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.
*/

import zeros = require( '@stdlib/ndarray/base/zeros' );
import scalar2ndarray = require( '@stdlib/ndarray/from-scalar' );
import Complex64 = require( '@stdlib/complex/float32/ctor' );
import cfill = require( './index' );


// TESTS //

// The function returns an ndarray...
{
const x = zeros( 'complex64', [ 10 ], 'row-major' );
const alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), {
'dtype': 'complex64'
});
cfill( [ x, alpha ] ); // $ExpectType complex64ndarray
}

// The compiler throws an error if the function is provided a first argument which is not an array-like object...
{
cfill( 'abc' ); // $ExpectError
cfill( 5 ); // $ExpectError
cfill( true ); // $ExpectError
cfill( false ); // $ExpectError
cfill( null ); // $ExpectError
cfill( undefined ); // $ExpectError
cfill( {} ); // $ExpectError
cfill( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an insufficient number of arguments...
{
cfill(); // $ExpectError
}

// The compiler throws an error if the function is provided too many arguments...
{
const x = zeros( 'complex64', [ 10 ], 'row-major' );
const alpha = scalar2ndarray( new Complex64( 10.0, 10.0 ), {
'dtype': 'complex64'
});
cfill( [ x, alpha ], 10 ); // $ExpectError
}
Loading