Skip to content

Latest commit

 

History

History
320 lines (205 loc) · 8.89 KB

File metadata and controls

320 lines (205 loc) · 8.89 KB

dcartesianSquare

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

Usage

var dcartesianSquare = require( '@stdlib/blas/ext/base/dcartesian-square' );

dcartesianSquare( order, N, x, strideX, out, LDO )

Computes the Cartesian square 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 );

dcartesianSquare( 'row-major', x.length, 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.
  • x: input Float64Array.
  • strideX: stride length for x.
  • out: output Float64Array.
  • LDO: stride length for the leading dimension of out.

The N and stride parameters determine which elements in the strided arrays are accessed at runtime. For example, to compute the Cartesian square 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 );

dcartesianSquare( 'row-major', 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 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 );

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

dcartesianSquare.ndarray( N, x, strideX, offsetX, out, strideOut1, strideOut2, offsetOut )

Computes the Cartesian square 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 );

dcartesianSquare.ndarray( x.length, 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 of the first dimension of out.
  • strideOut2: stride length of 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 access only the last two elements:

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

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

dcartesianSquare.ndarray( 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 ]

Notes

  • For an input array of length N, the output array must contain at least N * N * 2 indexed elements.
  • The LDO parameter must be greater than or equal to max(1,N).
  • If N <= 0, both functions return out unchanged.

Examples

var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Float64Array = require( '@stdlib/array/float64' );
var dcartesianSquare = require( '@stdlib/blas/ext/base/dcartesian-square' );

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

var out = new Float64Array( N * N * 2 );
dcartesianSquare( 'row-major', N, x, 1, out, 2 );
console.log( out );

C APIs

Usage

#include "stdlib/blas/ext/base/dcartesiansquare.h"

stdlib_strided_dcartesian_square( order, N, *X, strideX, *Out, LDO )

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

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

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

stdlib_strided_dcartesian_square( CblasRowMajor, 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.
  • X: [in] double* input array.
  • strideX: [in] CBLAS_INT stride length for X.
  • Out: [out] double* output array.
  • LDO: [in] CBLAS_INT stride length for the leading dimension of Out. Must be greater than or equal to max(1,N).
void stdlib_strided_dcartesian_square( const CBLAS_LAYOUT order, const CBLAS_INT N, const double *X, const CBLAS_INT strideX, double *Out, const CBLAS_INT LDO );

stdlib_strided_dcartesian_square_ndarray( N, *X, strideX, offsetX, *Out, strideOut1, strideOut2, offsetOut )

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

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

stdlib_strided_dcartesian_square_ndarray( 2, x, 1, 0, out, 2, 1, 0 );

The function accepts the following arguments:

  • N: [in] CBLAS_INT number of indexed elements.
  • 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.
void stdlib_strided_dcartesian_square_ndarray( const CBLAS_INT N, 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 );

Examples

#include "stdlib/blas/ext/base/dcartesiansquare.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:
    const int N = 2;

    // Create an output array (N*N pairs, each pair has 2 elements):
    double out[ 8 ];

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

    // Compute the Cartesian square:
    stdlib_strided_dcartesian_square( CblasRowMajor, N, 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 ] );
    }
}