Compute the Cartesian power for a double-precision floating-point strided array.
var dcartesianPower = require( '@stdlib/blas/ext/base/dcartesian-power' );Computes the Cartesian power for a double-precision floating-point strided array.
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.
- N: number of indexed elements.
- k: power.
- x: input
Float64Array. - strideX: stride length for
x. - out: output
Float64Array. - LDO: stride length for the 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:
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 views.
var Float64Array = require( '@stdlib/array/float64' );
// Initial arrays...
var x0 = new Float64Array( [ 0.0, 1.0, 2.0 ] );
var out0 = new Float64Array( 8 );
// Create offset views...
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
dcartesianPower( 'row-major', 2, 2, x1, 1, out0, 2 );
// out0 => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]Computes the Cartesian power for a double-precision floating-point strided array using alternative indexing semantics.
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 additional parameters:
- offsetX: starting index for
x. - strideOut1: stride length for the first dimension of
out. - strideOut2: stride length for the second dimension of
out. - offsetOut: starting index for
out.
While 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 compute the Cartesian power of every other value in the strided input array starting from the second value:
var Float64Array = require( '@stdlib/array/float64' );
var x = new Float64Array( [ 0.0, 1.0, 2.0 ] );
var out = new Float64Array( 8 );
dcartesianPower.ndarray( 2, 2, x, 1, 1, out, 2, 1, 0 );
// out => <Float64Array>[ 1.0, 1.0, 1.0, 2.0, 2.0, 1.0, 2.0, 2.0 ]- If
N <= 0ork <= 0, both functions returnoutunchanged. - The output array must contain at least
N^k * kelements. - The
LDOparameter must be greater than or equal tomax(1, k).
var Float64Array = require( '@stdlib/array/float64' );
var dcartesianPower = require( '@stdlib/blas/ext/base/dcartesian-power' );
var x = new Float64Array( [ 1.0, 2.0 ] );
console.log( x );
var out = new Float64Array( 24 );
dcartesianPower( 'row-major', x.length, 3, x, 1, out, 3 );
console.log( out );#include "stdlib/blas/ext/base/dcartesianpower.h"Computes the Cartesian power for a double-precision floating-point strided array.
#include "stdlib/blas/base/shared.h"
const double X[] = { 1.0, 2.0 };
double Out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
stdlib_strided_dcartesian_power( CblasRowMajor, 2, 2, X, 1, Out, 2 );The function accepts the following arguments:
- order:
[in] CBLAS_LAYOUTstorage layout. - N:
[in] CBLAS_INTnumber of indexed elements. - k:
[in] CBLAS_INTpower. - X:
[in] double*input array. - strideX:
[in] CBLAS_INTstride length forX. - Out:
[out] double*output array. - LDO:
[in] CBLAS_INTstride length for the leading dimension ofOut.
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 );stdlib_strided_dcartesian_power_ndarray( N, k, *X, strideX, offsetX, *Out, strideOut1, strideOut2, offsetOut )
Computes the Cartesian power for a double-precision floating-point strided array using alternative indexing semantics.
const double X[] = { 1.0, 2.0 };
double Out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
stdlib_strided_dcartesian_power_ndarray( 2, 2, X, 1, 0, Out, 2, 1, 0 );The function accepts the following arguments:
- N:
[in] CBLAS_INTnumber of indexed elements. - k:
[in] CBLAS_INTpower. - X:
[in] double*input array. - strideX:
[in] CBLAS_INTstride length forX. - offsetX:
[in] CBLAS_INTstarting index forX. - Out:
[out] double*output array. - strideOut1:
[in] CBLAS_INTstride length for the first dimension ofOut. - strideOut2:
[in] CBLAS_INTstride length for the second dimension ofOut. - offsetOut:
[in] CBLAS_INTstarting index forOut.
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 );#include "stdlib/blas/ext/base/dcartesianpower.h"
#include "stdlib/blas/base/shared.h"
#include <stdio.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:
double out[ 8 ] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
// 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:
for ( int i = 0; i < N*N; i++ ) {
printf( "out[ %i ] = ( %lf, %lf )\n", i, out[ i*2 ], out[ i*2+1 ] );
}
}