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
86 changes: 86 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,86 @@
<!--

@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.

## Usage

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

#### cfill( x, alpha )

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 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 = new Complex64( 10.0, 10.0 );

cfill( x, alpha );

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

var re = v.re;
// returns 10.0

var im = v.im;
// returns 10.0
```

## Examples

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
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 = new Complex64( 10.0, 10.0 );

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'
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @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 Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var ndarray = require( '@stdlib/ndarray/ctor' );
var isComplex64 = require( '@stdlib/assert/is-complex64' );
var pkg = require( './../package.json' ).name;
var cfill = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var alpha;
var buf;
var x;
var i;

buf = new Complex64Array( 100 );
x = new ndarray( 'complex64', buf, [ 100 ], [ 1 ], 0, 'row-major' );
alpha = new Complex64( 5.0, 5.0 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
cfill( x, alpha );
if ( !isComplex64( x.get( 0 ) ) ) {
b.fail( 'should return a Complex64' );
}
}
b.toc();
if ( !isComplex64( x.get( 0 ) ) ) {
b.fail( 'should return a Complex64' );
}
b.pass( 'benchmark finished' );
b.end();
});
38 changes: 38 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,38 @@

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

Parameters
----------
x: ndarray
Input ndarray.

alpha: ComplexLike
Scalar constant.

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

Examples
--------
> var buf = new {{alias:@stdlib/array/complex64}}( [ 1.0, 2.0, 3.0, 4.0 ] )
<Complex64Array>
> var x = {{alias:@stdlib/ndarray/ctor}}( 'complex64', buf, [ 2 ], [ 1 ], 0, 'row-major' )
<ndarray>
> var alpha = new {{alias:@stdlib/complex/float32/ctor}}( 10.0, 10.0 )
<Complex64>
> {{alias}}( x, alpha )
<ndarray>
> var v = x.get( 0 )
<Complex64>
> var re = v.re
10.0
> var im = v.im
10.0

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* @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';
import { Complex64 } from '@stdlib/types/complex';

/**
* Fills a complex single-precision floating-point ndarray with a specified scalar constant.
*
* @param x - input ndarray
* @param alpha - scalar constant
* @returns input ndarray
*
* @example
* var Complex64Array = require( '@stdlib/array/complex64' );
* var Complex64 = require( '@stdlib/complex/float32/ctor' );
* 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 = new Complex64( 10.0, 10.0 );
*
* cfill( x, alpha );
*
* var v = x.get( 0 );
* // returns <Complex64>
*/
declare function cfill( x: complex64ndarray, alpha: Complex64 ): complex64ndarray;


// EXPORTS //

export = cfill;
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* @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 Complex64Array = require( '@stdlib/array/complex64' );
import Complex64 = require( '@stdlib/complex/float32/ctor' );
import ndarray = require( '@stdlib/ndarray/ctor' );
import cfill = require( './index' );


// TESTS //

// The function returns an ndarray...
{
const buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
const x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' );
const alpha = new Complex64( 10.0, 10.0 );

cfill( x, alpha ); // $ExpectType complex64ndarray
}

// The compiler throws an error if the function is provided a first argument which is not an ndarray...
{
const alpha = new Complex64( 10.0, 10.0 );

cfill( '10', alpha ); // $ExpectError
cfill( 10, alpha ); // $ExpectError
cfill( true, alpha ); // $ExpectError
cfill( false, alpha ); // $ExpectError
cfill( null, alpha ); // $ExpectError
cfill( undefined, alpha ); // $ExpectError
cfill( [], alpha ); // $ExpectError
cfill( {}, alpha ); // $ExpectError
cfill( ( x: number ): number => x, alpha ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument which is not a complex number...
{
const buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
const x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' );

cfill( x, '10' ); // $ExpectError
cfill( x, 10 ); // $ExpectError
cfill( x, true ); // $ExpectError
cfill( x, false ); // $ExpectError
cfill( x, null ); // $ExpectError
cfill( x, undefined ); // $ExpectError
cfill( x, [] ); // $ExpectError
cfill( x, {} ); // $ExpectError
cfill( x, ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
const buffer = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
const x = new ndarray( 'complex64', buffer, [ 2 ], [ 1 ], 0, 'row-major' );
const alpha = new Complex64( 10.0, 10.0 );

cfill(); // $ExpectError
cfill( x ); // $ExpectError
cfill( x, alpha, 10 ); // $ExpectError
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/**
* @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';

var Complex64Array = require( '@stdlib/array/complex64' );
var Complex64 = require( '@stdlib/complex/float32/ctor' );
var ndarray = require( '@stdlib/ndarray/ctor' );
var realf = require( '@stdlib/complex/float32/real' );
var imagf = require( '@stdlib/complex/float32/imag' );
var cfill = require( './../lib' );

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 = new Complex64( 10.0, 10.0 );

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'
Loading