-
-
Notifications
You must be signed in to change notification settings - Fork 843
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 25 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
167 changes: 167 additions & 0 deletions
167
lib/node_modules/@stdlib/ndarray/base/mskfilter/README.md
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,167 @@ | ||
<!-- | ||
|
||
@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. | ||
|
||
--> | ||
|
||
# mskfilter | ||
|
||
> Apply a mask to a provided input ndarray and assign unmasked values to elements in a provided one-dimensional output ndarray. | ||
|
||
<section class="intro"> | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var mskfilter = require( '@stdlib/ndarray/base/mskfilter' ); | ||
``` | ||
|
||
#### mskfilter( arrays ) | ||
|
||
Apply a mask to a provided input ndarray and assign unmasked values to elements in a provided one-dimensional output ndarray. | ||
|
||
```javascript | ||
var Float64Array = require( '@stdlib/array/float64' ); | ||
var Uint8Array = require( '@stdlib/array/uint8' ); | ||
|
||
// Define the shape of the input and mask arrays: | ||
var shape = [ 3, 1, 2 ]; | ||
|
||
// Define the array strides: | ||
var sx = [ 2, 2, 1 ]; | ||
var sm = [ 2, 2, 1 ]; | ||
var sy = [ 1 ]; | ||
|
||
// Define the index offsets: | ||
var ox = 1; | ||
var om = 0; | ||
|
||
// Create the input, mask and output ndarray-like objects: | ||
var x = { | ||
'dtype': 'float64', | ||
'data': 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 ] ), | ||
Jaysukh-409 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
'shape': shape, | ||
'strides': sx, | ||
'offset': ox, | ||
'order': 'row-major' | ||
}; | ||
var mask = { | ||
'dtype': 'uint8', | ||
'data': new Uint8Array( [ 1, 0, 1, 0, 1, 0 ] ), | ||
'shape': shape, | ||
'strides': sm, | ||
'offset': om, | ||
'order': 'row-major' | ||
}; | ||
var out = { | ||
'dtype': 'float64', | ||
'data': new Float64Array( 3 ), | ||
'shape': [ 3 ], | ||
'strides': sy, | ||
'offset': 0, | ||
'order': 'row-major' | ||
}; | ||
|
||
mskfilter( [ x, mask, out ] ); | ||
|
||
console.log( out.data ); | ||
// => <Float64Array>[ 2.0, 4.0, 6.0 ] | ||
``` | ||
|
||
The function accepts the following arguments: | ||
|
||
- **arrays**: array-like object containing input ndarray, mask ndarray and one dimensional output ndarray. | ||
Jaysukh-409 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Each provided ndarray should be an object with the following properties: | ||
|
||
- **dtype**: data type. | ||
- **data**: data buffer. | ||
- **shape**: dimensions. | ||
- **strides**: stride lengths. | ||
- **offset**: index offset. | ||
- **order**: specifies whether an ndarray is row-major (C-style) or column major (Fortran-style). | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<section class="notes"> | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
```javascript | ||
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; | ||
var filledarray = require( '@stdlib/array/filled' ); | ||
var filledarrayBy = require( '@stdlib/array/filled-by' ); | ||
var ndarray2array = require( '@stdlib/ndarray/base/to-array' ); | ||
var mskfilter = require( '@stdlib/ndarray/base/mskfilter' ); | ||
|
||
var N = 10; | ||
var shape = [ 5, 2 ]; | ||
var x = { | ||
'dtype': 'float64', | ||
'data': filledarrayBy( N, 'float64', discreteUniform( -100, 100 ) ), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's use random/array/discrete-uniform, random/array/bernoulli, and array/zeros for creating the array buffers. |
||
'shape': shape, | ||
'strides': [ 2, 1 ], | ||
'offset': 0, | ||
'order': 'row-major' | ||
}; | ||
var mask = { | ||
'dtype': 'uint8', | ||
'data': filledarrayBy( N, 'uint8', discreteUniform( 0, 1 ) ), | ||
'shape': shape, | ||
'strides': [ 2, 1 ], | ||
'offset': 0, | ||
'order': 'row-major' | ||
}; | ||
var y = { | ||
'dtype': 'float64', | ||
'data': filledarray( 0, N, 'float64' ), | ||
'shape': [ N ], | ||
'strides': [ 1 ], | ||
'offset': 0, | ||
'order': 'row-major' | ||
}; | ||
|
||
mskfilter( [ x, mask, y ] ); | ||
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 ) ); | ||
Jaysukh-409 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
154 changes: 154 additions & 0 deletions
154
...ode_modules/@stdlib/ndarray/base/mskfilter/benchmark/benchmark.10d_blocked_columnmajor.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,154 @@ | ||
/** | ||
* @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'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; | ||
var isnan = require( '@stdlib/math/base/assert/is-nan' ); | ||
var pow = require( '@stdlib/math/base/special/pow' ); | ||
var floor = require( '@stdlib/math/base/special/floor' ); | ||
var filledarray = require( '@stdlib/array/filled' ); | ||
var filledarrayBy = require( '@stdlib/array/filled-by' ); | ||
var shape2strides = require( '@stdlib/ndarray/base/shape2strides' ); | ||
var pkg = require( './../package.json' ).name; | ||
var mskfilter = require( './../lib/10d_blocked.js' ); | ||
|
||
|
||
// VARIABLES // | ||
|
||
var types = [ 'float64' ]; | ||
var order = 'column-major'; | ||
|
||
|
||
// FUNCTIONS // | ||
|
||
/** | ||
* Creates a benchmark function. | ||
* | ||
* @private | ||
* @param {PositiveInteger} len - ndarray length | ||
* @param {NonNegativeIntegerArray} shape - ndarray shape | ||
* @param {string} dtype - input and output ndarray data type | ||
* @returns {Function} benchmark function | ||
*/ | ||
function createBenchmark( len, shape, dtype ) { | ||
var mask; | ||
var x; | ||
var y; | ||
|
||
x = filledarrayBy( len, dtype, discreteUniform( -100, 100 ) ); | ||
mask = filledarrayBy( len, 'uint8', discreteUniform( 0, 1 ) ); | ||
y = filledarray( 0.0, len, dtype ); | ||
x = { | ||
'dtype': dtype, | ||
'data': x, | ||
'shape': shape, | ||
'strides': shape2strides( shape, order ), | ||
'offset': 0, | ||
'order': order | ||
}; | ||
mask = { | ||
'dtype': 'uint8', | ||
'data': mask, | ||
'shape': shape, | ||
'strides': shape2strides( shape, order ), | ||
'offset': 0, | ||
'order': order | ||
}; | ||
y = { | ||
'dtype': dtype, | ||
'data': y, | ||
'shape': [ len ], | ||
'strides': [ 1 ], | ||
'offset': 0, | ||
'order': order | ||
}; | ||
return benchmark; | ||
|
||
/** | ||
* Benchmark function. | ||
* | ||
* @private | ||
* @param {Benchmark} b - benchmark instance | ||
*/ | ||
function benchmark( b ) { | ||
var i; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
mskfilter( x, mask, y ); | ||
if ( isnan( y.data[ i%len ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
} | ||
b.toc(); | ||
if ( isnan( y.data[ i%len ] ) ) { | ||
b.fail( 'should not return NaN' ); | ||
} | ||
b.pass( 'benchmark finished' ); | ||
b.end(); | ||
} | ||
} | ||
|
||
|
||
// MAIN // | ||
|
||
/** | ||
* Main execution sequence. | ||
* | ||
* @private | ||
*/ | ||
function main() { | ||
var len; | ||
var min; | ||
var max; | ||
var sh; | ||
var t; | ||
var f; | ||
var i; | ||
var j; | ||
|
||
min = 1; // 10^min | ||
max = 6; // 10^max | ||
|
||
for ( j = 0; j < types.length; j++ ) { | ||
t = types[ j ]; | ||
for ( i = min; i <= max; i++ ) { | ||
len = pow( 10, i ); | ||
|
||
sh = [ len/2, 2, 1, 1, 1, 1, 1, 1, 1, 1 ]; | ||
f = createBenchmark( len, sh, t ); | ||
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',dtype='+t, f ); | ||
|
||
sh = [ 1, 1, 1, 1, 1, 1, 1, 1, 2, len/2 ]; | ||
f = createBenchmark( len, sh, t ); | ||
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',dtype='+t, f ); | ||
|
||
len = floor( pow( len, 1.0/10.0 ) ); | ||
sh = [ len, len, len, len, len, len, len, len, len, len ]; | ||
len *= pow( len, 9 ); | ||
f = createBenchmark( len, sh, t ); | ||
bench( pkg+'::blocked:ndims='+sh.length+',len='+len+',shape=['+sh.join(',')+'],order='+order+',dtype='+t, f ); | ||
} | ||
} | ||
} | ||
|
||
main(); |
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.