Skip to content

stdlib-js/blas-ext-base-zdiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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!

zdiff

NPM version Build Status Coverage Status

Calculate the k-th discrete forward difference of a double-precision complex floating-point strided array.

Installation

npm install @stdlib/blas-ext-base-zdiff

Alternatively,

  • To load the package in a website via a script tag without installation and bundlers, use the ES Module available on the esm branch (see README).
  • If you are using Deno, visit the deno branch (see README for usage intructions).
  • For use in Observable, or in browser/node environments, use the Universal Module Definition (UMD) build available on the umd branch (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.

Usage

var zdiff = require( '@stdlib/blas-ext-base-zdiff' );

zdiff( N, k, x, strideX, N1, prepend, strideP, N2, append, strideA, out, strideOut, workspace, strideW )

Calculates the k-th discrete forward difference of a double-precision complex floating-point strided array.

var Complex128Array = require( '@stdlib/array-complex128' );

var x = new Complex128Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 ] );
var p = new Complex128Array( [ 1.0, -1.0 ] );
var a = new Complex128Array( [ 11.0, -11.0 ] );
var out = new Complex128Array( 6 );
var w = new Complex128Array( 6 );

zdiff( x.length, 1, x, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 );
// out => <Complex128Array>[ 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 Complex128Array.
  • strideX: stride length for x.
  • N1: number of indexed elements to prepend.
  • prepend: a Complex128Array containing values to prepend prior to computing differences.
  • strideP: stride length for prepend.
  • N2: number of indexed elements to append.
  • append: a Complex128Array containing values to append prior to computing differences.
  • strideA: stride length for append.
  • out: output Complex128Array. Must have N + N1 + N2 - k elements.
  • strideOut: stride length for out.
  • workspace: workspace Complex128Array. Must have N + N1 + N2 - 1 elements.
  • 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 Complex128Array = require( '@stdlib/array-complex128' );

var x = new Complex128Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 ] );
var p = new Complex128Array( [ 1.0, -1.0 ] );
var a = new Complex128Array( [ 11.0, -11.0 ] );
var out = new Complex128Array( 4 );
var w = new Complex128Array( 4 );

zdiff( 3, 1, x, 2, 1, p, 1, 1, a, 1, out, 1, w, 1 );
// out => <Complex128Array>[ 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 Complex128Array = require( '@stdlib/array-complex128' );

// Initial array...
var x0 = new Complex128Array( [ 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 Complex128Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element

var p = new Complex128Array( [ 1.0, -1.0 ] );
var a = new Complex128Array( [ 11.0, -11.0 ] );
var out = new Complex128Array( 5 );
var w = new Complex128Array( 5 );

zdiff( x1.length, 1, x1, 1, 1, p, 1, 1, a, 1, out, 1, w, 1 );
// out => <Complex128Array>[ 3.0, -3.0, 2.0, -2.0, 2.0, -2.0, 2.0, -2.0, 1.0, -1.0 ]

zdiff.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 double-precision complex floating-point strided array using alternative indexing semantics.

var Complex128Array = require( '@stdlib/array-complex128' );

var x = new Complex128Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 ] );
var p = new Complex128Array( [ 1.0, -1.0 ] );
var a = new Complex128Array( [ 11.0, -11.0 ] );
var out = new Complex128Array( 6 );
var w = new Complex128Array( 6 );

zdiff.ndarray( x.length, 1, x, 1, 0, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 );
// out => <Complex128Array>[ 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 Complex128Array = require( '@stdlib/array-complex128' );

var x = new Complex128Array( [ 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 ] );
var p = new Complex128Array( [ 1.0, -1.0 ] );
var a = new Complex128Array( [ 11.0, -11.0 ] );
var out = new Complex128Array( 4 );
var w = new Complex128Array( 4 );

zdiff.ndarray( 3, 1, x, 1, x.length-3, 1, p, 1, 0, 1, a, 1, 0, out, 1, 0, w, 1, 0 );
// out => <Complex128Array>[ 5.0, -5.0, 2.0, -2.0, 2.0, -2.0, 1.0, -1.0 ]

Notes

  • When k <= 1, the workspace array is unused and thus ignored.
  • If N + N1 + N2 <= 1 or k >= N + N1 + N2, both functions return the output array unchanged.

Examples

var discreteUniform = require( '@stdlib/random-array-discrete-uniform' );
var Complex128Array = require( '@stdlib/array-complex128' );
var zdiff = require( '@stdlib/blas-ext-base-zdiff' );

var xbuf = discreteUniform( 20, -100, 100, {
    'dtype': 'float64'
});
var x = new Complex128Array( xbuf.buffer );
console.log( 'Input array: ', x );

var pbuf = discreteUniform( 4, -100, 100, {
    'dtype': 'float64'
});
var p = new Complex128Array( pbuf.buffer );
console.log( 'Prepend array: ', p );

var abuf = discreteUniform( 4, -100, 100, {
    'dtype': 'float64'
});
var a = new Complex128Array( abuf.buffer );
console.log( 'Append array: ', a );

var out = new Complex128Array( 10 );
var w = new Complex128Array( 13 );

zdiff( x.length, 4, x, 1, 2, p, 1, 2, a, 1, out, 1, w, 1 );
console.log( 'Output: ', out );

C APIs

Usage

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

stdlib_strided_zdiff( N, k, *X, strideX, N1, *Prepend, strideP, N2, *Append, strideA, *Out, strideOut, *Workspace, strideW )

Calculates the k-th discrete forward difference of a double-precision complex floating-point strided array.

#include "stdlib/complex/float64/ctor.h"

const double x[] = { 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 };
const double p[] = { 1.0, -1.0 };
const double a[] = { 11.0, -11.0 };
double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
double w[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

stdlib_strided_zdiff( 5, 1, (const stdlib_complex128_t *)x, 1, 1, (const stdlib_complex128_t *)p, 1, 1, (const stdlib_complex128_t *)a, 1, (stdlib_complex128_t *)out, 1, (stdlib_complex128_t *)w, 1 );

The function accepts the following arguments:

  • N: [in] CBLAS_INT number of indexed elements.
  • k: [in] CBLAS_INT number of times to recursively compute differences.
  • X: [in] stdlib_complex128_t* input array.
  • strideX: [in] CBLAS_INT stride length for X.
  • N1: [in] CBLAS_INT number of indexed elements for Prepend.
  • Prepend: [in] stdlib_complex128_t* array containing values to prepend prior to computing differences.
  • strideP: [in] CBLAS_INT stride length for Prepend.
  • N2: [in] CBLAS_INT number of indexed elements for Append.
  • Append: [in] stdlib_complex128_t* array containing values to append prior to computing differences.
  • strideA: [in] CBLAS_INT stride length for Append.
  • Out: [out] stdlib_complex128_t* output array. Must have N + N1 + N2 - k elements.
  • strideOut: [in] CBLAS_INT stride length for Out.
  • Workspace: [out] stdlib_complex128_t* workspace array. Must have N + N1 + N2 - 1 elements.
  • strideW: [in] CBLAS_INT stride length for Workspace.
void stdlib_strided_zdiff( const CBLAS_INT N, const CBLAS_INT k, const stdlib_complex128_t *X, const CBLAS_INT strideX, const CBLAS_INT N1, const stdlib_complex128_t *Prepend, const CBLAS_INT strideP, const CBLAS_INT N2, const stdlib_complex128_t *Append, const CBLAS_INT strideA, stdlib_complex128_t *Out, const CBLAS_INT strideOut, stdlib_complex128_t *Workspace, const CBLAS_INT strideW );

stdlib_strided_zdiff_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 double-precision complex floating-point strided array using alternative indexing semantics.

#include "stdlib/complex/float64/ctor.h"

const double x[] = { 2.0, -2.0, 4.0, -4.0, 6.0, -6.0, 8.0, -8.0, 10.0, -10.0 };
const double p[] = { 1.0, -1.0 };
const double a[] = { 11.0, -11.0 };
double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
double w[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

stdlib_strided_zdiff_ndarray( 5, 1, (const stdlib_complex128_t *)x, 1, 0, 1, (const stdlib_complex128_t *)p, 1, 0, 1, (const stdlib_complex128_t *)a, 1, 0, (stdlib_complex128_t *)out, 1, 0, (stdlib_complex128_t *)w, 1, 0 );

The function accepts the following arguments:

  • N: [in] CBLAS_INT number of indexed elements.
  • k: [in] CBLAS_INT number of times to recursively compute differences.
  • X: [in] stdlib_complex128_t* input array.
  • strideX: [in] CBLAS_INT stride length for X.
  • offsetX: [in] CBLAS_INT starting index for X.
  • N1: [in] CBLAS_INT number of indexed elements for Prepend.
  • Prepend: [in] stdlib_complex128_t* array containing values to prepend prior to computing differences.
  • strideP: [in] CBLAS_INT stride length for Prepend.
  • offsetP: [in] CBLAS_INT starting index for Prepend.
  • N2: [in] CBLAS_INT number of indexed elements for Append.
  • Append: [in] stdlib_complex128_t* array containing values to append prior to computing differences.
  • strideA: [in] CBLAS_INT stride length for Append.
  • offsetA: [in] CBLAS_INT starting index for Append.
  • Out: [out] stdlib_complex128_t* output array. Must have N + N1 + N2 - k elements.
  • strideOut: [in] CBLAS_INT stride length for Out.
  • offsetOut: [in] CBLAS_INT starting index for Out.
  • Workspace: [out] stdlib_complex128_t* workspace array. Must have N + N1 + N2 - 1 elements.
  • strideW: [in] CBLAS_INT stride length for Workspace.
  • offsetW: [in] CBLAS_INT starting index for Workspace.
void stdlib_strided_zdiff_ndarray( const CBLAS_INT N, const CBLAS_INT k, const stdlib_complex128_t *X, const CBLAS_INT strideX, const CBLAS_INT offsetX, const CBLAS_INT N1, const stdlib_complex128_t *Prepend, const CBLAS_INT strideP, const CBLAS_INT offsetP, const CBLAS_INT N2, const stdlib_complex128_t *Append, const CBLAS_INT strideA, const CBLAS_INT offsetA, stdlib_complex128_t *Out, const CBLAS_INT strideOut, const CBLAS_INT offsetOut, stdlib_complex128_t *Workspace, const CBLAS_INT strideW, const CBLAS_INT offsetW );

Examples

#include "stdlib/blas/ext/base/zdiff.h"
#include "stdlib/complex/float64/ctor.h"
#include <stdio.h>

int main( void ) {
    // Create a strided array of interleaved real and imaginary components:
    const double x[] = { 1.0, -1.0, 2.0, -2.0, 3.0, -3.0, 4.0, -4.0 };

    // Define a list of values to prepend:
    const double p[] = { 0.0, 0.0 };

    // Define a list of values to append:
    const double a[] = { 5.0, -5.0 };

    // Define an output array:
    double out[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

    // Define a workspace:
    double w[] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };

    // Compute forward differences:
    stdlib_strided_zdiff( 4, 1, (const stdlib_complex128_t *)x, 1, 1, (const stdlib_complex128_t *)p, 1, 1, (const stdlib_complex128_t *)a, 1, (stdlib_complex128_t *)out, 1, (stdlib_complex128_t *)w, 1 );

    // Print the result:
    for ( int i = 0; i < 10; i++ ) {
        printf( "out[ %i ] = %lf\n", i, out[ i ] );
    }
}

Notice

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.

Community

Chat


License

See LICENSE.

Copyright

Copyright © 2016-2026. The Stdlib Authors.

Releases

No releases published

Packages

 
 
 

Contributors