Repository navigation
feat: add number/uint64/base/or
#16513
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
Open
impawstarlight
wants to merge
2
commits into
stdlib-js:develop
Choose a base branch
from
impawstarlight:feature/uint64-base-or
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.
+1,550
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
171 changes: 171 additions & 0 deletions
171
lib/node_modules/@stdlib/number/uint64/base/or/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,171 @@ | ||
| <!-- | ||
|
|
||
| @license Apache-2.0 | ||
|
|
||
| Copyright (c) 2026 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. | ||
|
|
||
| --> | ||
|
|
||
| # or | ||
|
|
||
| > Compute the bitwise OR of two 64-bit unsigned integers. | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var or = require( '@stdlib/number/uint64/base/or' ); | ||
| ``` | ||
|
|
||
| #### or( a, b ) | ||
|
|
||
| Computes the bitwise OR of two 64-bit unsigned integers. | ||
|
|
||
| ```javascript | ||
| var Uint64 = require( '@stdlib/number/uint64/ctor' ); | ||
|
|
||
| var a = new Uint64( 5 ); | ||
| var b = new Uint64( 3 ); | ||
|
|
||
| var v = or( a, b ); | ||
| // returns <Uint64>[ 7n ] | ||
| ``` | ||
|
|
||
| The function supports the following parameters: | ||
|
|
||
| - **a**: first 64-bit unsigned integer. | ||
| - **b**: second 64-bit unsigned integer. | ||
|
|
||
| #### or.assign( ah, al, bh, bl, out, stride, offset ) | ||
|
|
||
| Computes the bitwise OR of two 64-bit unsigned integers and assigns results to a provided output array. | ||
|
|
||
| ```javascript | ||
| var Uint32Array = require( '@stdlib/array/uint32' ); | ||
|
|
||
| var out = new Uint32Array( 2 ); | ||
| var v = or.assign( 1, 2, 3, 4, out, 1, 0 ); | ||
| // returns <Uint32Array>[ 3, 6 ] | ||
|
|
||
| var bool = ( out === v ); | ||
| // returns true | ||
| ``` | ||
|
|
||
| The function supports the following parameters: | ||
|
|
||
| - **ah**: high 32-bit word of the first 64-bit unsigned integer. | ||
| - **al**: low 32-bit word of the first 64-bit unsigned integer. | ||
| - **bh**: high 32-bit word of the second 64-bit unsigned integer. | ||
| - **bl**: low 32-bit word of the second 64-bit unsigned integer. | ||
| - **out**: output array. | ||
| - **stride**: stride length for `out`. | ||
| - **offset**: starting index for `out`. | ||
|
|
||
| #### or.strided( a, sa, oa, b, sb, ob, out, so, oo ) | ||
|
|
||
| Computes the bitwise OR of two 64-bit unsigned integers stored in integer-valued strided array views and assigns results to a provided strided output array. | ||
|
|
||
| ```javascript | ||
| var Uint32Array = require( '@stdlib/array/uint32' ); | ||
|
|
||
| var a = new Uint32Array( [ 1, 2 ] ); | ||
| var b = new Uint32Array( [ 3, 4 ] ); | ||
| var out = new Uint32Array( 2 ); | ||
|
|
||
| var v = or.strided( a, 1, 0, b, 1, 0, out, 1, 0 ); | ||
| // returns <Uint32Array>[ 3, 6 ] | ||
|
|
||
| var bool = ( out === v ); | ||
| // returns true | ||
| ``` | ||
|
|
||
| The function supports the following parameters: | ||
|
|
||
| - **a**: first 64-bit unsigned integer strided array view containing interleaved 32-bit unsigned integer high and low order words. | ||
| - **sa**: stride length for `a`. | ||
| - **oa**: starting index for `a`. | ||
| - **b**: second 64-bit unsigned integer strided array view containing interleaved 32-bit unsigned integer high and low order words. | ||
| - **sb**: stride length for `b`. | ||
| - **ob**: starting index for `b`. | ||
| - **out**: output array. | ||
| - **so**: stride length for `out`. | ||
| - **oo**: starting index for `out`. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var words2uint64 = require( '@stdlib/number/uint64/ctor' ).of; | ||
| var lpad = require( '@stdlib/string/base/left-pad' ); | ||
| var or = require( '@stdlib/number/uint64/base/or' ); | ||
|
|
||
| // Define a mask that sets the middle 32 bits (bits 16 to 47): | ||
| var mask = words2uint64( 0x0000ffff, 0xffff0000 ); | ||
|
|
||
| // Define a function for converting to 64-bit fixed length hex string: | ||
| function toHex64( x ) { | ||
| return '0x'+lpad( x.toString( 16 ), 16, '0' ); | ||
| } | ||
|
|
||
| var values = [ | ||
| words2uint64( 0x12340000, 0x0000def0 ), | ||
| words2uint64( 0x11112222, 0x33334444 ), | ||
| words2uint64( 0xaaaabbbb, 0xccccdddd ), | ||
| words2uint64( 0x00000000, 0x00000000 ) | ||
| ]; | ||
|
|
||
| var i; | ||
| for ( i = 0; i < values.length; i++ ) { | ||
| console.log( '%s | %s = %s', toHex64( values[ i ] ), toHex64( mask ), toHex64( or( values[ i ], mask ) ) ); | ||
| } | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
|
||
| <section class="related"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.related --> | ||
|
|
||
| <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="links"> | ||
|
|
||
| <!-- <related-links> --> | ||
|
|
||
| <!-- </related-links> --> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
129 changes: 129 additions & 0 deletions
129
lib/node_modules/@stdlib/number/uint64/base/or/benchmark/benchmark.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,129 @@ | ||
| /** | ||
| * @license Apache-2.0 | ||
| * | ||
| * Copyright (c) 2026 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 Uint32Array = require( '@stdlib/array/uint32' ); | ||
| var bench = require( '@stdlib/bench' ); | ||
| var UINT32_MAX = require( '@stdlib/constants/uint32/max' ); | ||
| var Uint64 = require( '@stdlib/number/uint64/ctor' ); | ||
| var discreteUniform = require( '@stdlib/random/array/discrete-uniform' ); | ||
| var format = require( '@stdlib/string/format' ); | ||
| var pkg = require( './../package.json' ).name; | ||
| var or = require( './../lib' ); | ||
|
|
||
|
|
||
| // VARIABLES // | ||
|
|
||
| var options = { | ||
| 'dtype': 'uint32' | ||
| }; | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( pkg, function benchmark( b ) { | ||
| var values; | ||
| var out; | ||
| var N; | ||
| var x; | ||
| var y; | ||
| var z; | ||
| var i; | ||
|
|
||
| N = 100; | ||
| x = discreteUniform( N, 0, UINT32_MAX, options ); | ||
| values = []; | ||
| for ( i = 0; i < N; i++ ) { | ||
| values.push( Uint64.of( x[ i ], x[ (i+1)%N ] ) ); | ||
| } | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| y = values[ i%N ]; | ||
| z = values[ (i+1)%N ]; | ||
| out = or( y, z ); | ||
| if ( typeof out !== 'object' ) { | ||
| b.fail( 'should return an object' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( !( out instanceof Uint64 ) ) { | ||
| b.fail( 'should return a Uint64 instance' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); | ||
|
|
||
| bench( format( '%s:assign', pkg ), function benchmark( b ) { | ||
| var out; | ||
| var N; | ||
| var x; | ||
| var i; | ||
|
|
||
| N = 100; | ||
| x = discreteUniform( N, 0, UINT32_MAX, options ); | ||
|
|
||
| out = new Uint32Array( 2 ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| out = or.assign( x[ i%N ], x[ (i+1)%N ], x[ (i+2)%N ], x[ (i+3)%N ], out, 1, 0 ); // eslint-disable-line max-len | ||
| if ( typeof out !== 'object' ) { | ||
| b.fail( 'should return an object' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( !( out instanceof Uint32Array ) ) { | ||
| b.fail( 'should return a Uint32Array' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); | ||
|
|
||
| bench( format( '%s:strided', pkg ), function benchmark( b ) { | ||
| var out; | ||
| var N; | ||
| var x; | ||
| var y; | ||
| var i; | ||
| var j; | ||
|
|
||
| N = 50; | ||
| x = discreteUniform( N*2, 0, UINT32_MAX, options ); | ||
| y = discreteUniform( N*2, 0, UINT32_MAX, options ); | ||
|
|
||
| out = new Uint32Array( 2 ); | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| j = ( i % N ) * 2; | ||
| out = or.strided( x, 1, j, y, 1, j, out, 1, 0 ); | ||
| if ( typeof out !== 'object' ) { | ||
| b.fail( 'should return an object' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( !( out instanceof Uint32Array ) ) { | ||
| b.fail( 'should return a Uint32Array' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); |
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.