Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<!--

@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.

-->

# quaternaryBlockSize

> 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 quaternaryBlockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' );
```

#### quaternaryBlockSize( dtypeX, dtypeY, dtypeZ, dtypeW, dtypeU )

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 = quaternaryBlockSize( 'float64', 'float64', 'float64', 'float64', 'float64' );
// returns <number>
```

The function supports the following arguments:

- **dtypeX**: first input array data type.
- **dtypeY**: second input array data type.
- **dtypeZ**: third input array data type.
- **dtypeW**: fourth input array data type.
- **dtypeU**: output array data type.

</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 quaternaryBlockSize = require( '@stdlib/ndarray/base/quaternary-tiling-block-size' );

// Generate a list of input ndarray dtype quadruplets:
var dt = cartesianPower( dtypes(), 4 );

// Resolve the block size for each dtype quadruplet and its promoted dtype...
var t;
var b;
var i;
console.log( 'block_size, xdtype, ydtype, zdtype, wdtype, udtype' );
for ( i = 0; i < dt.length; i++ ) {
t = promotionRules.apply( null, dt[ i ] );
dt[ i ].push( ( t === -1 ) ? 'generic' : t );
b = quaternaryBlockSize.apply( null, dt[ i ] );
console.log( '%d, %s, %s, %s, %s, %s', b, dt[i][0], dt[i][1], dt[i][2], dt[i][3], dt[i][4] );
}
```

</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 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* @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 dw;
var du;
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',
'float32',
'int8',
'uint8',
'uint8c',
'int16',
'uint16',
'int32',
'uint32',
'binary',
'generic',
'foobar'
];
dw = [
'float64',
'float32',
'int8',
'uint8',
'uint8c',
'int16',
'uint16',
'int32',
'uint32',
'binary',
'generic',
'foobar'
];
du = [
'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 ], dw[ i%dw.length ], du[ i%du.length ] ); // eslint-disable-line max-len
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();
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

{{alias}}( dtypeX, dtypeY, dtypeZ, dtypeW, dtypeU )
Returns a loop block size for multi-dimensional array tiled loops.

Parameters
----------
dtypeX: string|DataType
First input array data type.

dtypeY: string|DataType
Second input array data type.

dtypeZ: string|DataType
Third input array data type.

dtypeW: string|DataType
Fourth input array data type.

dtypeU: string|DataType
Output array data type.

Returns
-------
out: integer
Block size.

Examples
--------
> var out = {{alias}}( 'float64', 'int8', 'float64', 'float64', 'float64' )
<number>
> out = {{alias}}( 'float64', 'int32', 'float64', 'float64', 'float64' )
<number>

See Also
--------

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @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 dtypeX - first input array data type
* @param dtypeY - second input array data type
* @param dtypeZ - third input array data type
* @param dtypeW - fourth input array data type
* @param dtypeU - output array data type
* @returns block size (in units of elements)
*
* @example
* var bsize = quaternaryBlockSize( 'float64', 'float64', 'float64', 'float64', 'float64' );
* // returns <number>
*/
declare function quaternaryBlockSize( dtypeX: DataType, dtypeY: DataType, dtypeZ: DataType, dtypeW: DataType, dtypeU: DataType ): number;


// EXPORTS //

export = quaternaryBlockSize;
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.
*/

import quaternaryBlockSize = require( './index' );


// TESTS //

// The function returns a number...
{
quaternaryBlockSize( 'float64', 'float64', 'float64', 'float64', 'float64' ); // $ExpectType number
quaternaryBlockSize( 'float32', 'int8', 'uint16', 'complex128', 'complex128' ); // $ExpectType number
quaternaryBlockSize( 'generic', 'generic', 'generic', 'generic', 'generic' ); // $ExpectType number
}

// The compiler throws an error if the function is provided insufficient arguments...
{
quaternaryBlockSize(); // $ExpectError
quaternaryBlockSize( 'float64' ); // $ExpectError
quaternaryBlockSize( 'float64', 'float64' ); // $ExpectError
quaternaryBlockSize( 'float64', 'float64', 'float64' ); // $ExpectError
quaternaryBlockSize( 'float64', 'float64', 'float64', 'float64' ); // $ExpectError
}

// The compiler throws an error if the function is provided too many arguments...
{
quaternaryBlockSize( 'float64', 'float64', 'float64', 'float64', 'float64', {} ); // $ExpectError
}
Loading