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
327 changes: 327 additions & 0 deletions lib/node_modules/@stdlib/blas/ext/base/creplicate/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,327 @@
<!--

@license Apache-2.0

Copyright (c) 2026 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.

-->

# creplicate

> Replicate each element in a single-precision complex floating-point strided array a specified number of times.

<section class="intro">

</section>

<!-- /.intro -->

<section class="usage">

## Usage

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

#### creplicate( N, k, x, strideX, out, strideOut )

Replicates each element in a single-precision complex floating-point strided array a specified number of times.

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var out = new Complex64Array( 4 );

creplicate( x.length, 2, x, 1, out, 1 );
// out => <Complex64Array>[ 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
```

The function has the following parameters:

- **N**: number of indexed elements.
- **k**: number of times to replicate each element.
- **x**: input [`Complex64Array`][@stdlib/array/complex64].
- **strideX**: stride length for `x`.
- **out**: output [`Complex64Array`][@stdlib/array/complex64].
- **strideOut**: stride length for `out`.

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

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var out = new Complex64Array( 4 );

creplicate( 2, 2, x, 2, out, 1 );
// out => <Complex64Array>[ 1.0, 2.0, 1.0, 2.0, 5.0, 6.0, 5.0, 6.0 ]
```

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

<!-- eslint-disable stdlib/capitalized-comments -->

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

// Initial arrays...
var x0 = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0 ] );
var out0 = new Complex64Array( 3 );

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

creplicate( 1, 2, x1, 2, out1, 1 );
// out0 => <Complex64Array>[ 0.0, 0.0, 3.0, 4.0, 3.0, 4.0 ]
```

#### creplicate.ndarray( N, k, x, strideX, offsetX, out, strideOut, offsetOut )

Replicates each element in a single-precision complex floating-point strided array a specified number of times using alternative indexing semantics.

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var out = new Complex64Array( 4 );

creplicate.ndarray( x.length, 2, x, 1, 0, out, 1, 0 );
// out => <Complex64Array>[ 1.0, 2.0, 1.0, 2.0, 3.0, 4.0, 3.0, 4.0 ]
```

The function has the following additional parameters:

- **offsetX**: starting index for `x`.
- **offsetOut**: starting index for `out`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, offset parameters support indexing semantics based on starting indices. For example, to replicate every element starting from the second element and to store in the last `N*k` elements of the output array starting from the last element:

```javascript
var Complex64Array = require( '@stdlib/array/complex64' );

var x = new Complex64Array( [ 1.0, 2.0, 3.0, 4.0 ] );
var out = new Complex64Array( 2 );

creplicate.ndarray( 1, 2, x, 1, 1, out, 1, 0 );
// out => <Complex64Array>[ 3.0, 4.0, 3.0, 4.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- If `N <= 0` or `k <= 0`, both functions return `out` unchanged.
- Both functions assume that the output array supports `N*k` indexed elements.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Complex64Array = require( '@stdlib/array/complex64' );
var creplicate = require( '@stdlib/blas/ext/base/creplicate' );

var xbuf = discreteUniform( 10, -100, 100, {
'dtype': 'float32'
});
var x = new Complex64Array( xbuf.buffer );
console.log( x );

var out = new Complex64Array( x.length * 5 );
console.log( out );

creplicate( x.length, 5, x, 1, out, 1 );
console.log( out );
```

</section>

<!-- /.examples -->

<!-- C interface documentation. -->

* * *

<section class="c">

## C APIs

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- C usage documentation. -->

<section class="usage">

### Usage

```c
#include "stdlib/blas/ext/base/creplicate.h"
```

#### stdlib_strided_creplicate( N, k, \*X, strideX, \*Out, strideOut )

Replicates each element in a single-precision complex floating-point strided array a specified number of times.

```c
#include "stdlib/complex/float32/ctor.h"

const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };

stdlib_strided_creplicate( 2, 2, (stdlib_complex64_t *)x, 1, (stdlib_complex64_t *)out, 1 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **k**: `[in] CBLAS_INT` number of times to replicate each element.
- **X**: `[in] stdlib_complex64_t*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Out**: `[out] stdlib_complex64_t*` output array.
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.

```c
void stdlib_strided_creplicate( const CBLAS_INT N, const CBLAS_INT k, const stdlib_complex64_t *X, const CBLAS_INT strideX, stdlib_complex64_t *Out, const CBLAS_INT strideOut );
```

<!-- lint disable maximum-heading-length -->

#### stdlib_strided_creplicate_ndarray( N, k, \*X, strideX, offsetX, \*Out, strideOut, offsetOut )

<!-- lint enable maximum-heading-length -->

Replicates each element in a single-precision complex floating-point strided array a specified number of times using alternative indexing semantics.

```c
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };

stdlib_strided_creplicate_ndarray( 2, 2, (stdlib_complex64_t *)x, 1, 0, (stdlib_complex64_t *)out, 1, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **k**: `[in] CBLAS_INT` number of times to replicate each element.
- **X**: `[in] stdlib_complex64_t*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Out**: `[out] stdlib_complex64_t*` output array.
- **strideOut**: `[in] CBLAS_INT` stride length for `Out`.
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.

```c
void stdlib_strided_creplicate_ndarray( const CBLAS_INT N, const CBLAS_INT k, const stdlib_complex64_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, stdlib_complex64_t *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut );
```

</section>

<!-- /.usage -->

<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- C API usage examples. -->

<section class="examples">

### Examples

```c
#include "stdlib/blas/ext/base/creplicate.h"
#include "stdlib/complex/float32/ctor.h"
#include <stdio.h>

int main( void ) {
// Create strided arrays:
const float x[] = { 1.0f, 2.0f, 3.0f, 4.0f };
float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };

// Specify the number of indexed elements:
const int N = 2;

// Specify the number of times to replicate each element:
const int k = 2;

// Specify strides:
const int strideX = 1;
const int strideOut = 1;

// Replicate each element:
stdlib_strided_creplicate( N, k, (stdlib_complex64_t *)x, strideX, (stdlib_complex64_t *)out, strideOut );

// Print the results:
for ( int i = 0; i < 8; i++ ) {
printf( "out[ %i ] = %f\n", i, out[ i ] );
}
}
```

</section>

<!-- /.examples -->

</section>

<!-- /.c -->

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

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

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

</section>

<!-- /.links -->
Loading