About stdlib...
We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.
The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.
When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.
To join us in bringing numerical computing to the web, get started by checking us out on GitHub, and please consider financially supporting stdlib. We greatly appreciate your continued support!
Calculate the k-th discrete forward difference of a single-precision complex floating-point strided array.
npm install @stdlib/blas-ext-base-cdiffAlternatively,
- To load the package in a website via a
scripttag without installation and bundlers, use the ES Module available on theesmbranch (see README). - If you are using Deno, visit the
denobranch (see README for usage intructions). - For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the
umdbranch (see README).
The branches.md file summarizes the available branches and displays a diagram illustrating their relationships.
To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.
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.
#include "stdlib/complex/float32/ctor.h"
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, (const stdlib_complex64_t *)x, 1, 1, (const stdlib_complex64_t *)p, 1, 1, (const stdlib_complex64_t *)a, 1, (stdlib_complex64_t *)out, 1, (stdlib_complex64_t *)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] stdlib_complex64_t*input array. - strideX:
[in] CBLAS_INTstride length forX. - N1:
[in] CBLAS_INTnumber of indexed elements forPrepend. - Prepend:
[in] stdlib_complex64_t*array containing values to prepend prior to computing differences. - strideP:
[in] CBLAS_INTstride length forPrepend. - N2:
[in] CBLAS_INTnumber of indexed elements forAppend. - Append:
[in] stdlib_complex64_t*array containing values to append prior to computing differences. - strideA:
[in] CBLAS_INTstride length forAppend. - Out:
[out] stdlib_complex64_t*output array. Must haveN + N1 + N2 - kelements. - strideOut:
[in] CBLAS_INTstride length forOut. - Workspace:
[out] stdlib_complex64_t*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 stdlib_complex64_t *X, const CBLAS_INT strideX, const CBLAS_INT N1, const stdlib_complex64_t *Prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const stdlib_complex64_t *Append, const CBLAS_INT strideA, stdlib_complex64_t *Out, const CBLAS_INT strideOut, stdlib_complex64_t *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.
#include "stdlib/complex/float32/ctor.h"
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, (const stdlib_complex64_t *)x, 1, 0, 1, (const stdlib_complex64_t *)p, 1, 0, 1, (const stdlib_complex64_t *)a, 1, 0, (stdlib_complex64_t *)out, 1, 0, (stdlib_complex64_t *)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] stdlib_complex64_t*input array. - strideX:
[in] CBLAS_INTstride length forX. - offsetX:
[in] CBLAS_INTstarting index forX. - N1:
[in] CBLAS_INTnumber of indexed elements forPrepend. - Prepend:
[in] stdlib_complex64_t*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 forAppend. - Append:
[in] stdlib_complex64_t*array containing values to append prior to computing differences. - strideA:
[in] CBLAS_INTstride length forAppend. - offsetA:
[in] CBLAS_INTstarting index forAppend. - Out:
[out] stdlib_complex64_t*output array. Must haveN + N1 + N2 - kelements. - strideOut:
[in] CBLAS_INTstride length forOut. - offsetOut:
[in] CBLAS_INTstarting index forOut. - Workspace:
[out] stdlib_complex64_t*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 stdlib_complex64_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const stdlib_complex64_t *Prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const stdlib_complex64_t *Append, const CBLAS_INT strideA, const CBLAS_INT offsetA, stdlib_complex64_t *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, stdlib_complex64_t *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW );#include "stdlib/blas/ext/base/cdiff.h"
#include "stdlib/complex/float32/ctor.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, (const stdlib_complex64_t *)x, 1, 1, (const stdlib_complex64_t *)p, 1, 1, (const stdlib_complex64_t *)a, 1, (stdlib_complex64_t *)out, 1, (stdlib_complex64_t *)w, 1 );
// Print the result:
for ( int i = 0; i < 10; i++ ) {
printf( "out[ %i ] = %f\n", i, out[ i ] );
}
}This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
See LICENSE.
Copyright © 2016-2026. The Stdlib Authors.