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

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

-->

# dcartesianPower

> Compute the Cartesian power for a double-precision floating-point strided array.

<section class="usage">

## Usage

```javascript
var dcartesianPower = require( '@stdlib/blas/ext/base/dcartesian-power' );
```

#### dcartesianPower( order, N, k, x, strideX, out, LDO )

Computes the Cartesian power for a double-precision floating-point strided array.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 1.0, 2.0 ] );
var out = new Float64Array( 8 );

dcartesianPower( 'row-major', x.length, 2, x, 1, out, 2 );
// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
```

The function has the following parameters:

- **order**: storage layout. Must be either `'row-major'` or `'column-major'`.
- **N**: number of indexed elements.
- **k**: power.
- **x**: input [`Float64Array`][@stdlib/array/float64].
- **strideX**: stride length for `x`.
- **out**: output [`Float64Array`][@stdlib/array/float64].
- **LDO**: stride length between successive contiguous vectors of the matrix `out` (a.k.a., leading dimension of `out`).

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 1.0, 0.0, 2.0, 0.0 ] );
var out = new Float64Array( 8 );

dcartesianPower( 'row-major', 2, 2, x, 2, out, 2 );
// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
```

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

```javascript
var Float64Array = require( '@stdlib/array/float64' );

// Initial array:
var x0 = new Float64Array( [ 0.0, 1.0, 2.0, 3.0 ] );

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

// Output array:
var out = new Float64Array( 8 );

dcartesianPower( 'row-major', 2, 2, x1, 1, out, 2 );
// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
```

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

#### dcartesianPower.ndarray( N, k, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut )

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

Computes the Cartesian power for a double-precision floating-point strided array using alternative indexing semantics.

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 1.0, 2.0 ] );
var out = new Float64Array( 8 );

dcartesianPower.ndarray( x.length, 2, x, 1, 0, out, 2, 1, 0 );
// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
```

The function has the following parameters:

- **N**: number of indexed elements.
- **k**: power.
- **x**: input [`Float64Array`][@stdlib/array/float64].
- **strideX**: stride length for `x`.
- **offsetX**: starting index for `x`.
- **out**: output [`Float64Array`][@stdlib/array/float64].
- **strideOut1**: stride length of the first dimension of `out`.
- **strideOut2**: stride length of the second dimension of `out`.
- **offsetOut**: starting index for `out`.

While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameters support indexing semantics based on starting indices. For example, to access only the last two elements:

```javascript
var Float64Array = require( '@stdlib/array/float64' );

var x = new Float64Array( [ 0.0, 0.0, 1.0, 2.0 ] );
var out = new Float64Array( 8 );

dcartesianPower.ndarray( 2, 2, x, 1, 2, out, 2, 1, 0 );
// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]
```

</section>

<!-- /.usage -->

<section class="notes">

## Notes

- `k`-tuples are stored as rows in the output matrix, where the `j`-th column contains the `j`-th element of each tuple.
- For an input array of length `N`, the output array must contain at least `N^k * k` indexed elements.
- For row-major order, the `LDO` parameter must be greater than or equal to `max(1,k)`. For column-major order, the `LDO` parameter must be greater than or equal to `max(1,N^k)`.
- If `N <= 0` or `k <= 0`, both functions return `out` unchanged.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

```javascript
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var pow = require( '@stdlib/math/base/special/pow' );
var dcartesianPower = require( '@stdlib/blas/ext/base/dcartesian-power' );

var N = 2;
var k = 3;
var x = discreteUniform( N, 1, 10, {
'dtype': 'float64'
});
console.log( x );

var out = new Float64Array( pow( N, k ) * k );
dcartesianPower( 'row-major', N, k, x, 1, out, k );
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/dcartesianpower.h"
```

#### stdlib_strided_dcartesian_power( order, N, k, \*X, strideX, \*Out, LDO )

Computes the Cartesian power for a double-precision floating-point strided array.

```c
#include "stdlib/blas/base/shared.h"

const double x[] = { 1.0, 2.0 };
double out[ 8 ];

stdlib_strided_dcartesian_power( CblasRowMajor, 2, 2, x, 1, out, 2 );
```

The function accepts the following arguments:

- **order**: `[in] CBLAS_LAYOUT` storage layout.
- **N**: `[in] CBLAS_INT` number of indexed elements.
- **k**: `[in] CBLAS_INT` power.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **Out**: `[out] double*` output array.
- **LDO**: `[in] CBLAS_INT` stride length between successive contiguous vectors of the matrix `Out` (a.k.a., leading dimension of `Out`). For row-major order, must be greater than or equal to `max(1,k)`. For column-major order, must be greater than or equal to `max(1,N^k)`.

```c
void stdlib_strided_dcartesian_power( const CBLAS_LAYOUT order, const CBLAS_INT N, const CBLAS_INT k, const double *X, const CBLAS_INT strideX, double *Out, const CBLAS_INT LDO );
```

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

#### stdlib_strided_dcartesian_power_ndarray( N, k, \*X, strideX, offsetX, \*Out, strideOut1, strideOut2, offsetOut )

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

Computes the Cartesian power for a double-precision floating-point strided array using alternative indexing semantics.

```c
const double x[] = { 1.0, 2.0 };
double out[ 8 ];

stdlib_strided_dcartesian_power_ndarray( 2, 2, x, 1, 0, out, 2, 1, 0 );
```

The function accepts the following arguments:

- **N**: `[in] CBLAS_INT` number of indexed elements.
- **k**: `[in] CBLAS_INT` power.
- **X**: `[in] double*` input array.
- **strideX**: `[in] CBLAS_INT` stride length for `X`.
- **offsetX**: `[in] CBLAS_INT` starting index for `X`.
- **Out**: `[out] double*` output array.
- **strideOut1**: `[in] CBLAS_INT` stride length of the first dimension of `Out`.
- **strideOut2**: `[in] CBLAS_INT` stride length of the second dimension of `Out`.
- **offsetOut**: `[in] CBLAS_INT` starting index for `Out`.

```c
void stdlib_strided_dcartesian_power_ndarray( const CBLAS_INT N, const CBLAS_INT k, const double *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, double *Out, const CBLAS_INT strideOut1, const CBLAS_INT strideOut2, 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/dcartesianpower.h"
#include "stdlib/blas/base/shared.h"
#include <stdio.h>
#include <math.h>

int main( void ) {
// Create a strided input array:
const double x[] = { 1.0, 2.0 };

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

// Create an output array (N^k tuples, each tuple has k elements):
double out[ 8 ];

// Specify strides:
const int strideX = 1;
const int LDO = 2;

// Compute the Cartesian power:
stdlib_strided_dcartesian_power( CblasRowMajor, N, k, x, strideX, out, LDO );

// Print the result:
const int len = (int)pow( N, k );
for ( int i = 0; i < len; i++ ) {
printf( "out[ %i ] = ( %lf, %lf )\n", i, out[ i*2 ], out[ (i*2)+1 ] );
}
}
```

</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/float64]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/float64

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

</section>

<!-- /.links -->
Loading