Skip to content

Commit 4e6b7fd

Browse files
committed
feat: add blas/base/layout-resolve-enum
1 parent c533088 commit 4e6b7fd

File tree

10 files changed

+568
-0
lines changed

10 files changed

+568
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# resolve
22+
23+
> Return the enumeration constant associated with a supported BLAS memory layout value.
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var resolve = require( '@stdlib/blas/base/layout-resolve-enum' );
41+
```
42+
43+
#### resolve( layout )
44+
45+
Returns the enumeration constant associated with a BLAS memory layout value.
46+
47+
```javascript
48+
var str2enum = require( '@stdlib/blas/base/layout-str2enum' );
49+
50+
var v = resolve( 'row-major' );
51+
// returns <number>
52+
53+
v = resolve( str2enum( 'row-major' ) );
54+
// returns <number>
55+
```
56+
57+
If unable to resolve an enumeration constant, the function returns `null`.
58+
59+
```javascript
60+
var v = resolve( 'beep' );
61+
// returns null
62+
```
63+
64+
</section>
65+
66+
<!-- /.usage -->
67+
68+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
69+
70+
<section class="notes">
71+
72+
## Notes
73+
74+
- Downstream consumers of this function should **not** rely on specific integer values (e.g., `ROW_MAJOR == 0`). Instead, the function should be used in an opaque manner.
75+
76+
</section>
77+
78+
<!-- /.notes -->
79+
80+
<!-- Package usage examples. -->
81+
82+
<section class="examples">
83+
84+
## Examples
85+
86+
<!-- eslint no-undef: "error" -->
87+
88+
```javascript
89+
var resolve = require( '@stdlib/blas/base/layout-resolve-enum' );
90+
91+
var v = resolve( 'row-major' );
92+
// returns <number>
93+
94+
v = resolve( 'column-major' );
95+
// returns <number>
96+
```
97+
98+
</section>
99+
100+
<!-- /.examples -->
101+
102+
<!-- 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. -->
103+
104+
<section class="references">
105+
106+
</section>
107+
108+
<!-- /.references -->
109+
110+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
111+
112+
<section class="related">
113+
114+
</section>
115+
116+
<!-- /.related -->
117+
118+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
119+
120+
<section class="links">
121+
122+
</section>
123+
124+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
25+
var str2enum = require( '@stdlib/blas/base/layout-str2enum' );
26+
var pkg = require( './../package.json' ).name;
27+
var resolve = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg+'::string', function benchmark( b ) {
33+
var values;
34+
var out;
35+
var i;
36+
37+
values = [
38+
'row-major',
39+
'column-major'
40+
];
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
out = resolve( values[ i%values.length ] );
45+
if ( typeof out !== 'number' ) {
46+
b.fail( 'should return a number' );
47+
}
48+
}
49+
b.toc();
50+
if ( !isInteger( out ) ) {
51+
b.fail( 'should return an integer' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
56+
57+
bench( pkg+'::integer', function benchmark( b ) {
58+
var values;
59+
var out;
60+
var i;
61+
62+
values = [
63+
str2enum( 'row-major' ),
64+
str2enum( 'column-major' )
65+
];
66+
67+
b.tic();
68+
for ( i = 0; i < b.iterations; i++ ) {
69+
out = resolve( values[ i%values.length ] );
70+
if ( typeof out !== 'number' ) {
71+
b.fail( 'should return a number' );
72+
}
73+
}
74+
b.toc();
75+
if ( !isInteger( out ) ) {
76+
b.fail( 'should return an integer' );
77+
}
78+
b.pass( 'benchmark finished' );
79+
b.end();
80+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
{{alias}}( layout )
3+
Returns the enumeration constant associated with a supported BLAS memory
4+
layout value.
5+
6+
Downstream consumers of this function should *not* rely on specific integer
7+
values (e.g., `ROW_MAJOR == 0`). Instead, the function should be used in an
8+
opaque manner.
9+
10+
Parameters
11+
----------
12+
layout: any
13+
Layout value.
14+
15+
Returns
16+
-------
17+
out: integer|null
18+
Enumeration constant.
19+
20+
Examples
21+
--------
22+
> var out = {{alias}}( 'row-major' )
23+
<number>
24+
> out = {{alias}}( {{alias:@stdlib/blas/base/layout-str2enum}}( 'row-major' ) )
25+
<number>
26+
27+
See Also
28+
--------
29+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Returns the enumeration constant associated with a BLAS memory layout value.
23+
*
24+
* ## Notes
25+
*
26+
* - Downstream consumers of this function should **not** rely on specific integer values (e.g., `ROW_MAJOR == 0`). Instead, the function should be used in an opaque manner.
27+
*
28+
* @param layout - layout value
29+
* @returns enumeration constant
30+
*
31+
* @example
32+
* var v = resolve( 'row-major' );
33+
* // returns <number>
34+
*/
35+
declare function resolve( layout: any ): number | null;
36+
37+
38+
// EXPORTS //
39+
40+
export = resolve;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import resolve = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a number or null...
25+
{
26+
resolve( 0 ); // $ExpectType number | null
27+
resolve( 'row-major' ); // $ExpectType number | null
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var resolve = require( './../lib' );
22+
23+
var v = resolve( 'row-major' );
24+
console.log( v );
25+
// => <number>
26+
27+
v = resolve( 'column-major' );
28+
console.log( v );
29+
// => <number>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* Return the enumeration constant associated with a supported BLAS memory layout value.
23+
*
24+
* @module @stdlib/blas/base/layout-resolve-enum
25+
*
26+
* @example
27+
* var resolve = require( '@stdlib/blas/base/layout-resolve-enum' );
28+
*
29+
* var v = resolve( 'row-major' );
30+
* // returns <number>
31+
*/
32+
33+
// MODULES //
34+
35+
var main = require( './main.js' );
36+
37+
38+
// EXPORTS //
39+
40+
module.exports = main;

0 commit comments

Comments
 (0)