-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: add ndarray/base/ternary-tiling-block-size
#9495
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
Merged
Merged
Changes from 1 commit
Commits
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
126 changes: 126 additions & 0 deletions
126
lib/node_modules/@stdlib/ndarray/base/ternary-tiling-block-size/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,126 @@ | ||
| <!-- | ||
|
|
||
| @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. | ||
|
|
||
| --> | ||
|
|
||
| # ternaryBlockSize | ||
|
|
||
| > Resolve a loop block size for multi-dimensional array tiled loops. | ||
|
|
||
| <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="intro"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.intro --> | ||
|
|
||
| <!-- Package usage documentation. --> | ||
|
|
||
| <section class="usage"> | ||
|
|
||
| ## Usage | ||
|
|
||
| ```javascript | ||
| var ternaryBlockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); | ||
| ``` | ||
|
|
||
| #### ternaryBlockSize( dtypeW, dtypeX, dtypeY, dtypeZ ) | ||
|
|
||
| Resolves a loop block size according to provided ndarray [dtypes][@stdlib/ndarray/dtypes] for multi-dimensional array tiled loops applying a ternary function. | ||
|
|
||
| ```javascript | ||
| var bsize = ternaryBlockSize( 'float64', 'float64', 'float64', 'float64' ); | ||
| // returns <number> | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.usage --> | ||
|
|
||
| <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="notes"> | ||
|
|
||
| ## Notes | ||
|
|
||
| - The returned loop tiling block size is in units of elements. | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.notes --> | ||
|
|
||
| <!-- Package usage examples. --> | ||
|
|
||
| <section class="examples"> | ||
|
|
||
| ## Examples | ||
|
|
||
| <!-- eslint no-undef: "error" --> | ||
|
|
||
| ```javascript | ||
| var dtypes = require( '@stdlib/ndarray/dtypes' ); | ||
| var cartesianPower = require( '@stdlib/array/base/cartesian-power' ); | ||
| var promotionRules = require( '@stdlib/ndarray/promotion-rules' ); | ||
| var ternaryBlockSize = require( '@stdlib/ndarray/base/ternary-tiling-block-size' ); | ||
|
|
||
| // Generate a list of input ndarray dtype triplets: | ||
| var dt = cartesianPower( dtypes(), 3 ); | ||
|
|
||
| // Resolve the block size for each dtype triplet and its promoted dtype... | ||
| var t; | ||
| var b; | ||
| var i; | ||
| console.log( 'block_size, xdtype, ydtype, zdtype, wdtype' ); | ||
| for ( i = 0; i < dt.length; i++ ) { | ||
| t = promotionRules.apply( null, dt[ i ] ); | ||
| dt[ i ].push( ( t === -1 ) ? 'generic' : t ); | ||
| b = ternaryBlockSize.apply( null, dt[ i ] ); | ||
| console.log( '%d, %s, %s, %s, %s', b, dt[i][0], dt[i][1], dt[i][2], dt[i][3] ); | ||
| } | ||
| ``` | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.examples --> | ||
|
|
||
| <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
|
||
| <section class="references"> | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.references --> | ||
|
|
||
| <!-- 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"> | ||
|
|
||
| [@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes | ||
|
|
||
| </section> | ||
|
|
||
| <!-- /.links --> | ||
87 changes: 87 additions & 0 deletions
87
lib/node_modules/@stdlib/ndarray/base/ternary-tiling-block-size/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,87 @@ | ||
| /** | ||
| * @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 bench = require( '@stdlib/bench' ); | ||
| var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; | ||
| var pkg = require( './../package.json' ).name; | ||
| var blockSize = require( './../lib' ); | ||
|
|
||
|
|
||
| // MAIN // | ||
|
|
||
| bench( pkg, function benchmark( b ) { | ||
| var dx; | ||
| var dy; | ||
| var dz; | ||
| var s; | ||
| var i; | ||
|
|
||
| dx = [ | ||
| 'float64', | ||
| 'float32', | ||
| 'int8', | ||
| 'uint8', | ||
| 'uint8c', | ||
| 'int16', | ||
| 'uint16', | ||
| 'int32', | ||
| 'uint32', | ||
| 'binary', | ||
| 'generic', | ||
| 'foobar' | ||
| ]; | ||
| dy = [ | ||
| 'float64', | ||
| 'float32', | ||
| 'int8', | ||
| 'uint8', | ||
| 'uint8c', | ||
| 'int16', | ||
| 'uint16', | ||
| 'int32', | ||
| 'uint32', | ||
| 'binary', | ||
| 'generic', | ||
| 'foobar' | ||
| ]; | ||
| dz = [ | ||
| 'float64', | ||
| 'generic', | ||
| 'int32', | ||
| 'int16', | ||
| 'int8' | ||
| ]; | ||
|
|
||
| b.tic(); | ||
| for ( i = 0; i < b.iterations; i++ ) { | ||
| s = blockSize( dx[ i%dx.length ], dy[ i%dy.length ], dz[ i%dz.length ] ); // eslint-disable-line max-len | ||
headlessNode marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if ( typeof s !== 'number' ) { | ||
| b.fail( 'should return a number' ); | ||
| } | ||
| } | ||
| b.toc(); | ||
| if ( !isPositiveInteger( s ) ) { | ||
| b.fail( 'should return a positive integer' ); | ||
| } | ||
| b.pass( 'benchmark finished' ); | ||
| b.end(); | ||
| }); | ||
33 changes: 33 additions & 0 deletions
33
lib/node_modules/@stdlib/ndarray/base/ternary-tiling-block-size/docs/repl.txt
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,33 @@ | ||
|
|
||
| {{alias}}( dtypeW, dtypeX, dtypeY, dtypeZ ) | ||
| Returns a loop block size for multi-dimensional array tiled loops. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| dtypeW: string|DataType | ||
| First input array data type. | ||
|
|
||
| dtypeX: string|DataType | ||
| Second input array data type. | ||
|
|
||
| dtypeY: string|DataType | ||
| Third input array data type. | ||
|
|
||
| dtypeZ: string|DataType | ||
| Output array data type. | ||
|
|
||
| Returns | ||
| ------- | ||
| out: integer | ||
| Block size. | ||
|
|
||
| Examples | ||
| -------- | ||
| > var out = {{alias}}( 'float64', 'float64', 'float64' ) | ||
headlessNode marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <number> | ||
| > out = {{alias}}( 'int32', 'float64', 'float64' ) | ||
headlessNode marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <number> | ||
|
|
||
| See Also | ||
| -------- | ||
|
|
||
43 changes: 43 additions & 0 deletions
43
lib/node_modules/@stdlib/ndarray/base/ternary-tiling-block-size/docs/types/index.d.ts
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,43 @@ | ||
| /* | ||
| * @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. | ||
| */ | ||
|
|
||
| // TypeScript Version: 4.1 | ||
|
|
||
| /// <reference types="@stdlib/types"/> | ||
|
|
||
| import { DataType } from '@stdlib/types/ndarray'; | ||
|
|
||
| /** | ||
| * Returns a loop block size for multi-dimensional array tiled loops. | ||
| * | ||
| * @param dtypeW - first input array data type | ||
| * @param dtypeX - first input array data type | ||
| * @param dtypeY - second input array data type | ||
| * @param dtypeZ - output array data type | ||
| * @returns block size (in units of elements) | ||
| * | ||
| * @example | ||
| * var bsize = ternaryBlockSize( 'float64', 'float64', 'float64', 'float64' ); | ||
| * // returns <number> | ||
| */ | ||
| declare function ternaryBlockSize( dtypeW: DataType, dtypeX: DataType, dtypeY: DataType, dtypeZ: DataType ): number; | ||
|
|
||
|
|
||
| // EXPORTS // | ||
|
|
||
| export = ternaryBlockSize; |
42 changes: 42 additions & 0 deletions
42
lib/node_modules/@stdlib/ndarray/base/ternary-tiling-block-size/docs/types/test.ts
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,42 @@ | ||
| /* | ||
| * @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. | ||
| */ | ||
|
|
||
| import ternaryBlockSize = require( './index' ); | ||
|
|
||
|
|
||
| // TESTS // | ||
|
|
||
| // The function returns a number... | ||
| { | ||
| ternaryBlockSize( 'float64', 'float64', 'float64', 'float64' ); // $ExpectType number | ||
| ternaryBlockSize( 'float32', 'int8', 'uint16', 'complex128' ); // $ExpectType number | ||
| ternaryBlockSize( 'generic', 'generic', 'generic', 'generic' ); // $ExpectType number | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided insufficient arguments... | ||
| { | ||
| ternaryBlockSize(); // $ExpectError | ||
| ternaryBlockSize( 'float64' ); // $ExpectError | ||
| ternaryBlockSize( 'float64', 'float64' ); // $ExpectError | ||
| ternaryBlockSize( 'float64', 'float64', 'float64' ); // $ExpectError | ||
| } | ||
|
|
||
| // The compiler throws an error if the function is provided too many arguments... | ||
| { | ||
| ternaryBlockSize( 'float64', 'float64', 'float64', 'float64', {} ); // $ExpectError | ||
| } |
39 changes: 39 additions & 0 deletions
39
lib/node_modules/@stdlib/ndarray/base/ternary-tiling-block-size/examples/index.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,39 @@ | ||
| /** | ||
| * @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'; | ||
|
|
||
| var dtypes = require( '@stdlib/ndarray/dtypes' ); | ||
| var cartesianPower = require( '@stdlib/array/base/cartesian-power' ); | ||
| var promotionRules = require( '@stdlib/ndarray/promotion-rules' ); | ||
| var ternaryBlockSize = require( './../lib' ); | ||
|
|
||
| // Generate a list of input ndarray dtype triplets: | ||
| var dt = cartesianPower( dtypes(), 3 ); | ||
|
|
||
| // Resolve the block size for each dtype triplet and its promoted dtype... | ||
| var t; | ||
| var b; | ||
| var i; | ||
| console.log( 'block_size, xdtype, ydtype, zdtype, wdtype' ); | ||
kgryte marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| for ( i = 0; i < dt.length; i++ ) { | ||
| t = promotionRules.apply( null, dt[ i ] ); | ||
| dt[ i ].push( ( t === -1 ) ? 'generic' : t ); | ||
| b = ternaryBlockSize.apply( null, dt[ i ] ); | ||
| console.log( '%d, %s, %s, %s, %s', b, dt[i][0], dt[i][1], dt[i][2], dt[i][3] ); | ||
| } | ||
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.