Skip to content
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!

kernel

NPM version Build Status Coverage Status

Return a kernel for applying a one-dimensional strided array function to three input ndarrays and assigning results to an output ndarray using loop blocking.

Installation

npm install @stdlib/ndarray-base-kernels-generic-ternary-strided1d-blocked

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 kernel = require( '@stdlib/ndarray-base-kernels-generic-ternary-strided1d-blocked' );

kernel( ndims )

Returns a kernel for applying a one-dimensional strided array function to three input ndarrays and assigning results to an output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 3, 2, 2 ];
var ysh = [ 1, 3, 2, 2 ];
var zsh = [ 1, 3, 2, 2 ];
var wsh = [ 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 4, 2, 1 ];
var sy = [ 12, 4, 2, 1 ];
var sz = [ 12, 4, 2, 1 ];
var sw = [ 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Resolve a kernel:
var f = kernel( 2 );

// Apply strided function:
f( gwhere, [ x, y, z, w ], views, [ 1, 3 ], [ 12, 4 ], [ 12, 4 ], [ 12, 4 ], [ 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ]

The function accepts the following arguments:

  • ndims: number of loop dimensions.

If the function is provided ndims < 2 or a value greater than the maximum number of supported loop dimensions, the function returns null.

var f = kernel( 1 );
// returns null

The returned function accepts the following arguments:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

kernel.kernel2d( fcn, arrays, views, shape, stridesX, stridesY, stridesZ, stridesW, strategyX, strategyY, strategyZ, strategyW, options )

Applies a one-dimensional strided array function to a list of specified dimensions in three input ndarrays and assigns results to a provided output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 3, 2, 2 ];
var ysh = [ 1, 3, 2, 2 ];
var zsh = [ 1, 3, 2, 2 ];
var wsh = [ 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 4, 2, 1 ];
var sy = [ 12, 4, 2, 1 ];
var sz = [ 12, 4, 2, 1 ];
var sw = [ 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Apply strided function:
kernel.kernel2d( gwhere, [ x, y, z, w ], views, [ 1, 3 ], [ 12, 4 ], [ 12, 4 ], [ 12, 4 ], [ 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ]

The function has the following parameters:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions. Should have two elements.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

kernel.kernel3d( fcn, arrays, views, shape, stridesX, stridesY, stridesZ, stridesW, strategyX, strategyY, strategyZ, strategyW, options )

Applies a one-dimensional strided array function to a list of specified dimensions in three input ndarrays and assigns results to a provided output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 1, 3, 2, 2 ];
var ysh = [ 1, 1, 3, 2, 2 ];
var zsh = [ 1, 1, 3, 2, 2 ];
var wsh = [ 1, 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 12, 4, 2, 1 ];
var sy = [ 12, 12, 4, 2, 1 ];
var sz = [ 12, 12, 4, 2, 1 ];
var sw = [ 12, 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Apply strided function:
kernel.kernel3d( gwhere, [ x, y, z, w ], views, [ 1, 1, 3 ], [ 12, 12, 4 ], [ 12, 12, 4 ], [ 12, 12, 4 ], [ 12, 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ] ]

The function has the following parameters:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions. Should have three elements.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

kernel.kernel4d( fcn, arrays, views, shape, stridesX, stridesY, stridesZ, stridesW, strategyX, strategyY, strategyZ, strategyW, options )

Applies a one-dimensional strided array function to a list of specified dimensions in three input ndarrays and assigns results to a provided output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 1, 1, 3, 2, 2 ];
var ysh = [ 1, 1, 1, 3, 2, 2 ];
var zsh = [ 1, 1, 1, 3, 2, 2 ];
var wsh = [ 1, 1, 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 12, 12, 4, 2, 1 ];
var sy = [ 12, 12, 12, 4, 2, 1 ];
var sz = [ 12, 12, 12, 4, 2, 1 ];
var sw = [ 12, 12, 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Apply strided function:
kernel.kernel4d( gwhere, [ x, y, z, w ], views, [ 1, 1, 1, 3 ], [ 12, 12, 12, 4 ], [ 12, 12, 12, 4 ], [ 12, 12, 12, 4 ], [ 12, 12, 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ] ] ]

The function has the following parameters:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions. Should have four elements.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

kernel.kernel5d( fcn, arrays, views, shape, stridesX, stridesY, stridesZ, stridesW, strategyX, strategyY, strategyZ, strategyW, options )

Applies a one-dimensional strided array function to a list of specified dimensions in three input ndarrays and assigns results to a provided output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 1, 1, 1, 3, 2, 2 ];
var ysh = [ 1, 1, 1, 1, 3, 2, 2 ];
var zsh = [ 1, 1, 1, 1, 3, 2, 2 ];
var wsh = [ 1, 1, 1, 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 12, 12, 12, 4, 2, 1 ];
var sy = [ 12, 12, 12, 12, 4, 2, 1 ];
var sz = [ 12, 12, 12, 12, 4, 2, 1 ];
var sw = [ 12, 12, 12, 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Apply strided function:
kernel.kernel5d( gwhere, [ x, y, z, w ], views, [ 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ] ] ] ]

The function has the following parameters:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions. Should have five elements.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

kernel.kernel6d( fcn, arrays, views, shape, stridesX, stridesY, stridesZ, stridesW, strategyX, strategyY, strategyZ, strategyW, options )

Applies a one-dimensional strided array function to a list of specified dimensions in three input ndarrays and assigns results to a provided output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 1, 1, 1, 1, 3, 2, 2 ];
var ysh = [ 1, 1, 1, 1, 1, 3, 2, 2 ];
var zsh = [ 1, 1, 1, 1, 1, 3, 2, 2 ];
var wsh = [ 1, 1, 1, 1, 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 12, 12, 12, 12, 4, 2, 1 ];
var sy = [ 12, 12, 12, 12, 12, 4, 2, 1 ];
var sz = [ 12, 12, 12, 12, 12, 4, 2, 1 ];
var sw = [ 12, 12, 12, 12, 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Apply strided function:
kernel.kernel6d( gwhere, [ x, y, z, w ], views, [ 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ] ] ] ] ]

The function has the following parameters:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions. Should have six elements.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

kernel.kernel7d( fcn, arrays, views, shape, stridesX, stridesY, stridesZ, stridesW, strategyX, strategyY, strategyZ, strategyW, options )

Applies a one-dimensional strided array function to a list of specified dimensions in three input ndarrays and assigns results to a provided output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var ysh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var zsh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var wsh = [ 1, 1, 1, 1, 1, 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sy = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sz = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sw = [ 12, 12, 12, 12, 12, 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Apply strided function:
kernel.kernel7d( gwhere, [ x, y, z, w ], views, [ 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ [ [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ] ] ] ] ] ]

The function has the following parameters:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions. Should have seven elements.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

kernel.kernel8d( fcn, arrays, views, shape, stridesX, stridesY, stridesZ, stridesW, strategyX, strategyY, strategyZ, strategyW, options )

Applies a one-dimensional strided array function to a list of specified dimensions in three input ndarrays and assigns results to a provided output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var ysh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var zsh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var wsh = [ 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sy = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sz = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sw = [ 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Apply strided function:
kernel.kernel8d( gwhere, [ x, y, z, w ], views, [ 1, 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ [ [ [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ] ] ] ] ] ] ]

The function has the following parameters:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions. Should have eight elements.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

kernel.kernel9d( fcn, arrays, views, shape, stridesX, stridesY, stridesZ, stridesW, strategyX, strategyY, strategyZ, strategyW, options )

Applies a one-dimensional strided array function to a list of specified dimensions in three input ndarrays and assigns results to a provided output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var zsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var wsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sy = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sz = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sw = [ 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Apply strided function:
kernel.kernel9d( gwhere, [ x, y, z, w ], views, [ 1, 1, 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ [ [ [ [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ] ] ] ] ] ] ] ]

The function has the following parameters:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions. Should have nine elements.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

kernel.kernel10d( fcn, arrays, views, shape, stridesX, stridesY, stridesZ, stridesW, strategyX, strategyY, strategyZ, strategyW, options )

Applies a one-dimensional strided array function to a list of specified dimensions in three input ndarrays and assigns results to a provided output ndarray using loop blocking.

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var ysh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var zsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];
var wsh = [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sy = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sz = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];
var sw = [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Define an input strategy:
function inputStrategy( x ) {
    return {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 4 ],
        'strides': [ 1 ],
        'offset': x.offset,
        'order': x.order
    };
}

// Define an output strategy:
function outputStrategy( x ) {
    return x;
}

var strategy = {
    'input': inputStrategy,
    'output': outputStrategy
};

// Apply strided function:
kernel.kernel10d( gwhere, [ x, y, z, w ], views, [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 12, 12, 12, 12, 12, 4 ], strategy, strategy, strategy, strategy, {} );

var arr = ndarray2array( w.data, w.shape, w.strides, w.offset, w.order );
// returns [ [ [ [ [ [ [ [ [ [ [ [ 1.0, -2.0 ], [ 3.0, -4.0 ] ], [ [ 5.0, -6.0 ], [ 7.0, -8.0 ] ], [ [ 9.0, -10.0 ], [ 11.0, -12.0 ] ] ] ] ] ] ] ] ] ] ] ]

The function has the following parameters:

  • fcn: function which will be applied to three one-dimensional input subarrays and should update a one-dimensional output subarray with results.
  • arrays: array containing three input ndarray descriptors and one output ndarray descriptor, followed by any additional ndarray arguments.
  • views: initialized ndarray descriptors representing subarray views.
  • shape: loop dimensions. Should have ten elements.
  • stridesX: loop dimension strides for the first input ndarray.
  • stridesY: loop dimension strides for the second input ndarray.
  • stridesZ: loop dimension strides for the third input ndarray.
  • stridesW: loop dimension strides for the output ndarray.
  • strategyX: strategy for marshaling data to and from a first input ndarray view.
  • strategyY: strategy for marshaling data to and from a second input ndarray view.
  • strategyZ: strategy for marshaling data to and from a third input ndarray view.
  • strategyW: strategy for marshaling data to and from an output ndarray view.
  • options: function options which are passed through to fcn.

Notes

  • The strided array function is expected to have the following signature:

    fcn( arrays[, options] )
    

    where

    • arrays: array containing a one-dimensional subarray of the first input ndarray, a one-dimensional subarray of the second input ndarray, a one-dimensional subarray of the third input ndarray, a one-dimensional subarray of the output ndarray, and any additional ndarray arguments as subarrays.
    • options: function options (optional).
  • For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before performing an operation in order to achieve better performance.

Examples

var Float64Array = require( '@stdlib/array-float64' );
var ndarray2array = require( '@stdlib/ndarray-base-to-array' );
var gwhere = require( '@stdlib/blas-ext-base-ndarray-gwhere' );
var strategy = require( '@stdlib/ndarray-base-kernels-generic-unary-strided1d-strategy' );
var kernel = require( '@stdlib/ndarray-base-kernels-generic-ternary-strided1d-blocked' );

// Create data buffers:
var xbuf = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0 ] );
var ybuf = new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0 ] );
var zbuf = new Float64Array( [ -1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0, -9.0, -10.0, -11.0, -12.0 ] );
var wbuf = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] );

// Define the array shapes:
var xsh = [ 1, 1, 1, 1, 3, 2, 2 ];
var ysh = [ 1, 1, 1, 1, 3, 2, 2 ];
var zsh = [ 1, 1, 1, 1, 3, 2, 2 ];
var wsh = [ 1, 1, 1, 1, 3, 2, 2 ];

// Define the array strides:
var sx = [ 12, 12, 12, 12, 4, 2, 1 ];
var sy = [ 12, 12, 12, 12, 4, 2, 1 ];
var sz = [ 12, 12, 12, 12, 4, 2, 1 ];
var sw = [ 12, 12, 12, 12, 4, 2, 1 ];

// Define the index offsets:
var ox = 0;
var oy = 0;
var oz = 0;
var ow = 0;

// Create the input ndarray descriptors:
var x = {
    'dtype': 'float64',
    'data': xbuf,
    'shape': xsh,
    'strides': sx,
    'offset': ox,
    'order': 'row-major'
};

var y = {
    'dtype': 'float64',
    'data': ybuf,
    'shape': ysh,
    'strides': sy,
    'offset': oy,
    'order': 'row-major'
};

var z = {
    'dtype': 'float64',
    'data': zbuf,
    'shape': zsh,
    'strides': sz,
    'offset': oz,
    'order': 'row-major'
};

// Create an output ndarray descriptor:
var w = {
    'dtype': 'float64',
    'data': wbuf,
    'shape': wsh,
    'strides': sw,
    'offset': ow,
    'order': 'row-major'
};

// Initialize ndarray descriptors representing subarray views:
var views = [
    {
        'dtype': x.dtype,
        'data': x.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': x.offset,
        'order': x.order
    },
    {
        'dtype': y.dtype,
        'data': y.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': y.offset,
        'order': y.order
    },
    {
        'dtype': z.dtype,
        'data': z.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': z.offset,
        'order': z.order
    },
    {
        'dtype': w.dtype,
        'data': w.data,
        'shape': [ 2, 2 ],
        'strides': [ 2, 1 ],
        'offset': w.offset,
        'order': w.order
    }
];

// Resolve input/output strategies when iterating over subarray views:
var strategyX = strategy( views[ 0 ] );
var strategyY = strategy( views[ 1 ] );
var strategyZ = strategy( views[ 2 ] );
var strategyW = strategy( views[ 3 ] );

// Resolve a kernel:
var f = kernel( 5 );

// Apply strided function:
f( gwhere, [ x, y, z, w ], views, [ 1, 1, 1, 1, 3 ], [ 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 4 ], [ 12, 12, 12, 12, 4 ], strategyX, strategyY, strategyZ, strategyW, {} );

console.log( ndarray2array( x.data, x.shape, x.strides, x.offset, x.order ) );
console.log( ndarray2array( y.data, y.shape, y.strides, y.offset, y.order ) );
console.log( ndarray2array( z.data, z.shape, z.strides, z.offset, z.order ) );
console.log( ndarray2array( w.data, w.shape, w.strides, w.offset, w.order ) );

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.

About

Return a kernel for applying a one-dimensional strided array function to three input ndarrays and assigning results to an output ndarray using loop blocking.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages