Calculate the k-th discrete forward difference of a single-precision complex floating-point strided array.
var cdiff = require( '@stdlib/blas/ext/base/cdiff' );cdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW )
Calculates the k-th discrete forward difference of a single-precision complex floating-point strided array.
var Complex64Array = require( '@stdlib/array/complex64' );
var x = new Complex64Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 ] );
var p = new Complex64Array( [ 1.0, -1.0 ] );
var a = new Complex64Array( [ 11.0, -11.0 ] );
var out = new Complex64Array( 6 );
var w = new Complex64Array( 6 );
cdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 );
// out => <Complex64Array>[ 1.0, -1.0, 2.0, -2.0, 2.0, -2.0, 2.0, -2.0, 2.0, -2.0, 1.0, -1.0 ]The function has the following parameters:
- N: number of indexed elements.
- k: number of times to recursively compute differences.
- x: input
Complex64Array. - strideX: stride length for
x. - N1: number of indexed elements to
prepend. - prepend: a
Complex64Arraycontaining values to prepend prior to computing differences. - strideP: stride length for
prepend. - N2: number of indexed elements to
append. - append: a
Complex64Arraycontaining values to append prior to computing differences. - strideA: stride length for
append. - out: output
Complex64Array. Must haveN + N1 + N2 - kelements. - strideOut: stride length for
out. - workspace: workspace
Complex64Array. Must haveN + N1 + N2 - 1elements. - strideW: stride length for
workspace.
The N and stride parameters determine which elements in the strided array are accessed at runtime. For example, to compute differences of every other element:
var Complex64Array = require( '@stdlib/array/complex64' );
var x = new Complex64Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 ] );
var p = new Complex64Array( [ 1.0, -1.0 ] );
var a = new Complex64Array( [ 11.0, -11.0 ] );
var out = new Complex64Array( 4 );
var w = new Complex64Array( 4 );
cdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 );
// out => <Complex64Array>[ 1.0, -1.0, 4.0, -4.0, 4.0, -4.0, 1.0, -1.0 ]Note that indexing is relative to the first index. To introduce an offset, use typed array views.
var Complex64Array = require( '@stdlib/array/complex64' );
// Initial array...
var x0 = new Complex64Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 ] );
// Create an offset view...
var x1 = new Complex64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
var p = new Complex64Array( [ 1.0, -1.0 ] );
var a = new Complex64Array( [ 11.0, -11.0 ] );
var out = new Complex64Array( 5 );
var w = new Complex64Array( 5 );
cdiff( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 );
// out => <Complex64Array>[ 3.0, -3.0, 2.0, -2.0, 2.0, -2.0, 2.0, -2.0, 1.0, -1.0 ]cdiff.ndarray( N, k, x, strideX, offsetX, N1, prepend, strideP, offsetP, N2, append, strideA, offsetA, out, strideOut, offsetOut, workspace, strideW, offsetW )
Calculates the k-th discrete forward difference of a single-precision complex floating-point strided array using alternative indexing semantics.
var Complex64Array = require( '@stdlib/array/complex64' );
var x = new Complex64Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 ] );
var p = new Complex64Array( [ 1.0, -1.0 ] );
var a = new Complex64Array( [ 11.0, -11.0 ] );
var out = new Complex64Array( 6 );
var w = new Complex64Array( 6 );
cdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 );
// out => <Complex64Array>[ 1.0, -1.0, 2.0, -2.0, 2.0, -2.0, 2.0, -2.0, 2.0, -2.0, 1.0, -1.0 ]The function has the following additional parameters:
- offsetX: starting index for
x. - offsetP: starting index for
prepend. - offsetA: starting index for
append. - offsetOut: starting index for
out. - offsetW: starting index for
workspace.
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 three elements:
var Complex64Array = require( '@stdlib/array/complex64' );
var x = new Complex64Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 ] );
var p = new Complex64Array( [ 1.0, -1.0 ] );
var a = new Complex64Array( [ 11.0, -11.0 ] );
var out = new Complex64Array( 4 );
var w = new Complex64Array( 4 );
cdiff.ndarray( 3, 1, x, 1, x.length-3, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 );
// out => <Complex64Array>[ 5.0, -5.0, 2.0, -2.0, 2.0, -2.0, 1.0, -1.0 ]- When
k <= 1, the workspace array is unused and thus ignored. - If
N + N1 + N2 <= 1ork >= N + N1 + N2, both functions return the output array unchanged.
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
var Complex64Array = require( '@stdlib/array/complex64' );
var cdiff = require( '@stdlib/blas/ext/base/cdiff' );
var xbuf = discreteUniform( 20, -100, 100, {
'dtype': 'float32'
});
var x = new Complex64Array( xbuf.buffer );
console.log( 'Input array: ', x );
var pbuf = discreteUniform( 4, -100, 100, {
'dtype': 'float32'
});
var p = new Complex64Array( pbuf.buffer );
console.log( 'Prepend array: ', p );
var abuf = discreteUniform( 4, -100, 100, {
'dtype': 'float32'
});
var a = new Complex64Array( abuf.buffer );
console.log( 'Append array: ', a );
var out = new Complex64Array( 10 );
var w = new Complex64Array( 13 );
cdiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 );
console.log( 'Output: ', out );#include "stdlib/blas/ext/base/cdiff.h"stdlib_strided_cdiff( N, k, *X, strideX, N1, *Prepend, strideP, N2, *Append, strideA, *Out, strideOut, *Workspace, strideW )
Calculates the k-th discrete forward difference of a single-precision complex floating-point strided array.
const float x[] = { 2.0f, -2.0f, 4.0f, -4.0f, 6.0f, -6.0f, 8.0f, -8.0f, 10.0f, -10.0f };
const float p[] = { 1.0f, -1.0f };
const float a[] = { 11.0f, -11.0f };
float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
stdlib_strided_cdiff( 5, 1, (void *)x, 1, 1, (void *)p, 1, 1, (void *)a, 1, (void *)out, 1, (void *)w, 1 );The function accepts the following arguments:
- N:
[in] CBLAS_INTnumber of indexed elements. - k:
[in] CBLAS_INTnumber of times to recursively compute differences. - X:
[in] void*input array. - strideX:
[in] CBLAS_INTstride length forX. - N1:
[in] CBLAS_INTnumber of indexed elements toPrepend. - Prepend:
[in] void*array containing values to prepend prior to computing differences. - strideP:
[in] CBLAS_INTstride length forPrepend. - N2:
[in] CBLAS_INTnumber of indexed elements toAppend. - Append:
[in] void*array containing values to append prior to computing differences. - strideA:
[in] CBLAS_INTstride length forAppend. - Out:
[out] void*output array. Must haveN + N1 + N2 - kelements. - strideOut:
[in] CBLAS_INTstride length forOut. - Workspace:
[out] void*workspace array. Must haveN + N1 + N2 - 1elements. - strideW:
[in] CBLAS_INTstride length forWorkspace.
void stdlib_strided_cdiff( const CBLAS_INT N, const CBLAS_INT k, const void *X, const CBLAS_INT strideX, const CBLAS_INT N1, const void *Prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const void *Append, const CBLAS_INT strideA, void *Out, const CBLAS_INT strideOut, void *Workspace, const CBLAS_INT strideW );stdlib_strided_cdiff_ndarray( N, k, *X, strideX, offsetX, N1, *Prepend, strideP, offsetP, N2, *Append, strideA, offsetA, *Out, strideOut, offsetOut, *Workspace, strideW, offsetW )
Calculates the k-th discrete forward difference of a single-precision complex floating-point strided array using alternative indexing semantics.
const float x[] = { 2.0f, -2.0f, 4.0f, -4.0f, 6.0f, -6.0f, 8.0f, -8.0f, 10.0f, -10.0f };
const float p[] = { 1.0f, -1.0f };
const float a[] = { 11.0f, -11.0f };
float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
stdlib_strided_cdiff_ndarray( 5, 1, (void *)x, 1, 0, 1, (void *)p, 1, 0, 1, (void *)a, 1, 0, (void *)out, 1, 0, (void *)w, 1, 0 );The function accepts the following arguments:
- N:
[in] CBLAS_INTnumber of indexed elements. - k:
[in] CBLAS_INTnumber of times to recursively compute differences. - X:
[in] void*input array. - strideX:
[in] CBLAS_INTstride length forX. - offsetX:
[in] CBLAS_INTstarting index forX. - N1:
[in] CBLAS_INTnumber of indexed elements toPrepend. - Prepend:
[in] void*array containing values to prepend prior to computing differences. - strideP:
[in] CBLAS_INTstride length forPrepend. - offsetP:
[in] CBLAS_INTstarting index forPrepend. - N2:
[in] CBLAS_INTnumber of indexed elements toAppend. - Append:
[in] void*array containing values to append prior to computing differences. - strideA:
[in] CBLAS_INTstride length forAppend. - offsetA:
[in] CBLAS_INTstarting index forAppend. - Out:
[out] void*output array. Must haveN + N1 + N2 - kelements. - strideOut:
[in] CBLAS_INTstride length forOut. - offsetOut:
[in] CBLAS_INTstarting index forOut. - Workspace:
[out] void*workspace array. Must haveN + N1 + N2 - 1elements. - strideW:
[in] CBLAS_INTstride length forWorkspace. - offsetW:
[in] CBLAS_INTstarting index forWorkspace.
void stdlib_strided_cdiff_ndarray( const CBLAS_INT N, const CBLAS_INT k, const void *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const void *Prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const void *Append, const CBLAS_INT strideA, const CBLAS_INT offsetA, void *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, void *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW );#include "stdlib/blas/ext/base/cdiff.h"
#include <stdio.h>
int main( void ) {
// Create a strided array of interleaved real and imaginary components:
const float x[] = { 1.0f, -1.0f, 2.0f, -2.0f, 3.0f, -3.0f, 4.0f, -4.0f };
// Define a list of values to prepend:
const float p[] = { 0.0f, 0.0f };
// Define a list of values to append:
const float a[] = { 5.0f, -5.0f };
// Define an output array:
float out[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
// Define a workspace:
float w[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
// Compute forward differences:
stdlib_strided_cdiff( 4, 1, (void *)x, 1, 1, (void *)p, 1, 1, (void *)a, 1, (void *)out, 1, (void *)w, 1 );
// Print the result:
for ( int i = 0; i < 10; i++ ) {
printf( "out[ %i ] = %f\n", i, out[ i ] );
}
}