-
-
Notifications
You must be signed in to change notification settings - Fork 841
feat: add ndarray/base/mskfilter
#2604
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
Draft
Jaysukh-409
wants to merge
39
commits into
stdlib-js:develop
Choose a base branch
from
Jaysukh-409:ndarray/base/mskfilter
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
2836e0d
chore: create folder structure and add example
Jaysukh-409 67dfb52
feat: add kernels for 0d ndarray
Jaysukh-409 2f0ba4c
feat: add kernels for 1d ndarray
Jaysukh-409 d5bcb07
refactor: update the implementation for 1d kernels
Jaysukh-409 5010468
feat: add kernels for 2d ndarray
Jaysukh-409 6f3992f
docs: update description of loop kernel
Jaysukh-409 ecffc55
docs: refactor JSDoc example for loop kernels
Jaysukh-409 f531567
refactor: update variable name for consistent naming convention
Jaysukh-409 8ff83b4
feat: add kernels for 3d ndarray
Jaysukh-409 4039020
feat: add kernels for nd ndarray
Jaysukh-409 9422eb5
feat: add kernels for 4d ndarray
Jaysukh-409 f318edb
feat: add kernels for 5d ndarray
Jaysukh-409 7235a97
feat: add kernels for 6d ndarray
Jaysukh-409 d7683e0
feat: add kernels for 7d ndarray
Jaysukh-409 ad939d1
feat: add kernels for 8d ndarray
Jaysukh-409 f149847
feat: add kernels for 9d ndarray
Jaysukh-409 121db5a
feat: add kernels for 10d ndarray
Jaysukh-409 f1e0a81
docs: fix copy-paste error
Jaysukh-409 611cbcc
Merge branch 'develop' into ndarray/base/mskfilter
Jaysukh-409 467a34f
refactor: apply suggestions
Jaysukh-409 db07de8
test: add tests for 0d ndarray
Jaysukh-409 da81461
test: add tests for 1d ndarray
Jaysukh-409 7515b00
bench: add benchmark files
Jaysukh-409 e2ac30c
docs: added examples in readme
Jaysukh-409 f8926fb
Apply suggestions from code review
kgryte c193d8b
test: add tests for 2d ndaray
Jaysukh-409 11cb348
Merge branch 'ndarray/base/mskfilter' of https://github.com/Jaysukh-4…
Jaysukh-409 3ed9b3d
docs: add repl and typescript declaration
Jaysukh-409 59c2e81
test: add test for 3d to nd ndarray
Jaysukh-409 099e730
refactor: updated the implementation of mskfilter
Jaysukh-409 eaec078
refactor: apply suggestions
Jaysukh-409 1e848e9
Merge branch 'ndarray/base/mskfilter' of https://github.com/Jaysukh-4…
Jaysukh-409 1d1acea
feat: update scripts
Jaysukh-409 9c1003c
feat: update scripts and templates
Jaysukh-409 4eeeb46
feat: update templates and run script
Jaysukh-409 4e40c79
feat: add macros for 1d and 2d ndarray
Jaysukh-409 4d0ae78
fix: remove the unused variables
Jaysukh-409 b649357
Merge remote-tracking branch 'upstream/develop' into ndarray/base/msk…
stdlib-bot 1548fa7
chore: update copyright years
stdlib-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
lib/node_modules/@stdlib/ndarray/base/mskfilter/lib/2d.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
* | ||
* @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; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.