Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ndarray/base/mskfilter #2604

Draft
wants to merge 37 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2836e0d
chore: create folder structure and add example
Jaysukh-409 Jul 15, 2024
67dfb52
feat: add kernels for 0d ndarray
Jaysukh-409 Jul 29, 2024
2f0ba4c
feat: add kernels for 1d ndarray
Jaysukh-409 Jul 30, 2024
d5bcb07
refactor: update the implementation for 1d kernels
Jaysukh-409 Aug 1, 2024
5010468
feat: add kernels for 2d ndarray
Jaysukh-409 Aug 1, 2024
6f3992f
docs: update description of loop kernel
Jaysukh-409 Aug 2, 2024
ecffc55
docs: refactor JSDoc example for loop kernels
Jaysukh-409 Aug 2, 2024
f531567
refactor: update variable name for consistent naming convention
Jaysukh-409 Aug 2, 2024
8ff83b4
feat: add kernels for 3d ndarray
Jaysukh-409 Aug 3, 2024
4039020
feat: add kernels for nd ndarray
Jaysukh-409 Aug 3, 2024
9422eb5
feat: add kernels for 4d ndarray
Jaysukh-409 Aug 5, 2024
f318edb
feat: add kernels for 5d ndarray
Jaysukh-409 Aug 5, 2024
7235a97
feat: add kernels for 6d ndarray
Jaysukh-409 Aug 5, 2024
d7683e0
feat: add kernels for 7d ndarray
Jaysukh-409 Aug 5, 2024
ad939d1
feat: add kernels for 8d ndarray
Jaysukh-409 Aug 5, 2024
f149847
feat: add kernels for 9d ndarray
Jaysukh-409 Aug 5, 2024
121db5a
feat: add kernels for 10d ndarray
Jaysukh-409 Aug 5, 2024
f1e0a81
docs: fix copy-paste error
Jaysukh-409 Aug 5, 2024
611cbcc
Merge branch 'develop' into ndarray/base/mskfilter
Jaysukh-409 Aug 8, 2024
467a34f
refactor: apply suggestions
Jaysukh-409 Aug 8, 2024
db07de8
test: add tests for 0d ndarray
Jaysukh-409 Aug 10, 2024
da81461
test: add tests for 1d ndarray
Jaysukh-409 Aug 10, 2024
7515b00
bench: add benchmark files
Jaysukh-409 Aug 13, 2024
e2ac30c
docs: added examples in readme
Jaysukh-409 Aug 14, 2024
f8926fb
Apply suggestions from code review
kgryte Aug 14, 2024
c193d8b
test: add tests for 2d ndaray
Jaysukh-409 Aug 16, 2024
11cb348
Merge branch 'ndarray/base/mskfilter' of https://github.com/Jaysukh-4…
Jaysukh-409 Aug 16, 2024
3ed9b3d
docs: add repl and typescript declaration
Jaysukh-409 Aug 16, 2024
59c2e81
test: add test for 3d to nd ndarray
Jaysukh-409 Aug 19, 2024
099e730
refactor: updated the implementation of mskfilter
Jaysukh-409 Aug 20, 2024
eaec078
refactor: apply suggestions
Jaysukh-409 Aug 21, 2024
1e848e9
Merge branch 'ndarray/base/mskfilter' of https://github.com/Jaysukh-4…
Jaysukh-409 Aug 21, 2024
1d1acea
feat: update scripts
Jaysukh-409 Sep 16, 2024
9c1003c
feat: update scripts and templates
Jaysukh-409 Sep 16, 2024
4eeeb46
feat: update templates and run script
Jaysukh-409 Sep 24, 2024
4e40c79
feat: add macros for 1d and 2d ndarray
Jaysukh-409 Sep 30, 2024
4d0ae78
fix: remove the unused variables
Jaysukh-409 Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 5 additions & 16 deletions lib/node_modules/@stdlib/ndarray/base/mskfilter/lib/1d.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
*
* var x = {
* 'dtype': 'float64',
* 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0 ] ),
* 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 ] ),
* 'shape': shape,
* 'strides': sx,
* 'offset': ox,
Expand All @@ -64,8 +64,8 @@
*
* var y = {
* 'dtype': 'float64',
* 'data': new Float64Array( 4 ),
* 'shape': [ 4 ],
* 'data': new Float64Array( 3 ),
* 'shape': [ 3 ],
* 'strides': sy,
* 'offset': 0,
* 'order': 'row-major'
Expand All @@ -74,15 +74,12 @@
* mskfilter1d( x, mask, y );
*
* console.log( y.data );
* // => <Float64Array>[ 2.0, 0.0, 0.0, 0.0 ]
* // => <Float64Array>[ 2.0, 6.0, 10.0 ]
*/
function mskfilter1d( x, mask, y ) {
var xbuf;
var mbuf;
var ybuf;
var xlen;
var mlen;
var ylen;
var dx0;
var dm0;
var dy0;
Expand All @@ -108,21 +105,13 @@ function mskfilter1d( x, mask, y ) {
mbuf = mask.data;
ybuf = y.data;

// Extract the array lengths...
xlen = xbuf.length;
mlen = mbuf.length;
ylen = ybuf.length;

// Iterate over the ndarray dimensions...
for ( i0 = 0; i0 < S0; i0++ ) {
if ( ix >= xlen || im >= mlen || iy >= ylen ) {
return;
}
if ( mbuf[ im ] ) {
ybuf[ iy ] = xbuf[ ix ];
iy += dy0;
}
ix += dx0;
iy += dy0;
im += dm0;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
* var sy = [ 1 ];
*
* // Define the index offset:
* var ox = 1;
* var ox = 0;
* var om = 0;
*
* // Define getters and setters:
Expand Down Expand Up @@ -93,18 +93,15 @@
* // returns <Complex64>
*
* var re = realf( v );
* // returns 3.0
* // returns 1.0
*
* var im = imagf( v );
* // returns 4.0
* // returns 2.0
*/
function mskfilter1d( x, mask, y ) {
var xbuf;
var mbuf;
var ybuf;
var xlen;
var mlen;
var ylen;
var getm;
var getx;
var sety;
Expand Down Expand Up @@ -133,27 +130,19 @@ function mskfilter1d( x, mask, y ) {
mbuf = mask.data;
ybuf = y.data;

// Extract the array lengths...
xlen = xbuf.length;
mlen = mbuf.length;
ylen = ybuf.length;

// Cache accessors:
getx = x.accessors[ 0 ];
getm = mask.accessors[ 0 ];
sety = y.accessors[ 1 ];

// Iterate over the ndarray dimensions...
for ( i0 = 0; i0 < S0; i0++ ) {
if ( ix >= xlen || im >= mlen || iy >= ylen ) {
return;
}
if ( getm( mbuf, im ) ) {
sety( ybuf, iy, getx( xbuf, ix ) );
iy += dy0;
}
ix += dx0;
im += dm0;
iy += dy0;
}
}

Expand Down
150 changes: 150 additions & 0 deletions lib/node_modules/@stdlib/ndarray/base/mskfilter/lib/2d.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MAIN //

/**
* Apply a mask to a provided input ndarray and assign unmasked values to elements in a provided one-dimensional output ndarray.
Jaysukh-409 marked this conversation as resolved.
Show resolved Hide resolved
*
* @private
* @param {Object} x - object containing input ndarray meta data
* @param {Object} mask - object containing mask ndarray meta data
* @param {Object} y - object containing output ndarray meta data
* @returns {void}
*
* @example
* var Float64Array = require( '@stdlib/array/float64' );
*
* // Define the shape of the array:
* var shape = [ 2, 2 ];
*
* // Define the array strides:
* var sx = [ 4, 1 ];
* var sm = [ 2, 1 ];
* var sy = [ 1 ];
*
* // Define the index offset:
* var ox = 0;
* var om = 0;
*
* var x = {
* 'dtype': 'float64',
* 'data': new Float64Array( [ 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0 ] ),
* 'shape': shape,
* 'strides': sx,
* 'offset': ox,
* 'order': 'row-major'
* };
*
* var mask = {
* 'dtype': 'float64',
* 'data': new Float64Array( [ 1, 0, 1, 0 ] ),
kgryte marked this conversation as resolved.
Show resolved Hide resolved
* 'shape': shape,
* 'strides': sm,
* 'offset': om,
* 'order': 'row-major'
* };
*
* var y = {
* 'dtype': 'float64',
* 'data': new Float64Array( 2 ),
* 'shape': [ 2 ],
* 'strides': sy,
* 'offset': 0,
* 'order': 'row-major'
* };
*
* mskfilter2d( x, mask, y );
*
* console.log( y.data );
* // => <Float64Array>[ 1.0, 5.0 ]
*/
function mskfilter2d( x, mask, y ) {
var xbuf;
var mbuf;
var ybuf;
var dx0;
var dx1;
var dm0;
var dm1;
var dy0;
var S0;
var S1;
var sh;
var sm;
var sx;
var ix;
var im;
var iy;
var i0;
var i1;

// Extract loop variables: dimensions and loop offset (pointer) increments...
sh = x.shape;
sx = x.strides;
sm = mask.strides;
if ( x.order === 'row-major' ) {
// For row-major ndarrays, the last dimensions have the fastest changing indices...
S0 = sh[ 1 ];
S1 = sh[ 0 ];
dx0 = sx[ 1 ]; // offset increment for innermost loop
dx1 = sx[ 0 ] - ( S0*sx[1] ); // offset increment for outermost loop
dm0 = sm[ 1 ];
dm1 = sm[ 0 ] - ( S0*sm[1] );
} else { // order === 'column-major'
// For column-major ndarrays, the first dimensions have the fastest changing indices...
S0 = sh[ 0 ];
S1 = sh[ 1 ];
dx0 = sx[ 0 ]; // offset increment for innermost loop
dx1 = sx[ 1 ] - ( S0*sx[0] ); // offset increment for outermost loop
dm0 = sm[ 0 ];
dm1 = sm[ 1 ] - ( S0*sm[0] );
}
dy0 = y.strides[ 0 ];

// Set the pointers to the first indexed elements in the respective ndarrays...
ix = x.offset;
im = mask.offset;
iy = y.offset;

// Cache references to the input and output ndarray buffers...
xbuf = x.data;
mbuf = mask.data;
ybuf = y.data;

// Iterate over the ndarray dimensions...
for ( i1 = 0; i1 < S1; i1++ ) {
for ( i0 = 0; i0 < S0; i0++ ) {
if ( mbuf[ im ] ) {
ybuf[ iy ] = xbuf[ ix ];
iy += dy0;
}
ix += dx0;
im += dm0;
}
ix += dx1;
im += dm1;
}
}


// EXPORTS //

module.exports = mskfilter2d;
Loading
Loading