Skip to content

Commit a61b40c

Browse files
Pranavchikukgryte
andauthored
feat: add blas/base/matrix-triangle-str2enum and blas/base/matrix-triangle/enum2str
PR-URL: #2495 Co-authored-by: Athan Reines <[email protected]> Reviewed-by: Athan Reines <[email protected]>
1 parent 82c8ae0 commit a61b40c

File tree

20 files changed

+1079
-0
lines changed

20 files changed

+1079
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
# enum2str
22+
23+
> Return the BLAS matrix triangle string associated with a BLAS matrix triangle enumeration constant.
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 enum2str = require( '@stdlib/blas/base/matrix-triangle-enum2str' );
41+
```
42+
43+
#### enum2str( value )
44+
45+
Returns the BLAS matrix triangle string associated with a BLAS matrix triangle enumeration constant.
46+
47+
```javascript
48+
var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' );
49+
50+
var v = str2enum( 'upper' );
51+
// returns <number>
52+
53+
var s = enum2str( v );
54+
// returns 'upper'
55+
```
56+
57+
If unable to resolve a matrix triangle string, the function returns `null`.
58+
59+
```javascript
60+
var v = enum2str( -999999999 );
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+
</section>
73+
74+
<!-- /.notes -->
75+
76+
<!-- Package usage examples. -->
77+
78+
<section class="examples">
79+
80+
## Examples
81+
82+
<!-- eslint no-undef: "error" -->
83+
84+
```javascript
85+
var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' );
86+
var enum2str = require( '@stdlib/blas/base/matrix-triangle-enum2str' );
87+
88+
var str = enum2str( str2enum( 'upper' ) );
89+
// returns 'upper'
90+
91+
str = enum2str( str2enum( 'lower' ) );
92+
// returns 'lower'
93+
```
94+
95+
</section>
96+
97+
<!-- /.examples -->
98+
99+
<!-- 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. -->
100+
101+
<section class="references">
102+
103+
</section>
104+
105+
<!-- /.references -->
106+
107+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
108+
109+
<section class="related">
110+
111+
</section>
112+
113+
<!-- /.related -->
114+
115+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
116+
117+
<section class="links">
118+
119+
</section>
120+
121+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 isString = require( '@stdlib/assert/is-string' ).isPrimitive;
25+
var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' );
26+
var pkg = require( './../package.json' ).name;
27+
var enum2str = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var values;
34+
var out;
35+
var i;
36+
37+
values = [
38+
str2enum( 'upper' ),
39+
str2enum( 'lower' )
40+
];
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
out = enum2str( values[ i%values.length ] );
45+
if ( typeof out !== 'string' ) {
46+
b.fail( 'should return a string' );
47+
}
48+
}
49+
b.toc();
50+
if ( !isString( out ) ) {
51+
b.fail( 'should return a string' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
{{alias}}( value )
3+
Returns the BLAS matrix triangle string associated with a BLAS matrix
4+
triangle enumeration constant.
5+
6+
Parameters
7+
----------
8+
value: integer
9+
Matrix triangle enumeration constant.
10+
11+
Returns
12+
-------
13+
out: string|null
14+
Matrix triangle string.
15+
16+
Examples
17+
--------
18+
> var out = {{alias}}( {{alias:@stdlib/blas/base/matrix-triangle-str2enum}}( 'upper' ) )
19+
'upper'
20+
21+
See Also
22+
--------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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 BLAS matrix triangle string associated with a BLAS matrix triangle enumeration constant.
23+
*
24+
* @param value - enumeration constant
25+
* @returns matrix triangle string
26+
*
27+
* @example
28+
* var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' );
29+
*
30+
* var v = str2enum( 'upper' );
31+
* // returns <number>
32+
*
33+
* var s = enum2str( v );
34+
* // returns 'upper'
35+
*/
36+
declare function enum2str( value: number ): string | null;
37+
38+
39+
// EXPORTS //
40+
41+
export = enum2str;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 enum2str = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns a string or null...
25+
{
26+
enum2str( 0 ); // $ExpectType string | null
27+
}
28+
29+
// The compiler throws an error if not provided a number...
30+
{
31+
enum2str( '10' ); // $ExpectError
32+
enum2str( true ); // $ExpectError
33+
enum2str( false ); // $ExpectError
34+
enum2str( null ); // $ExpectError
35+
enum2str( undefined ); // $ExpectError
36+
enum2str( [] ); // $ExpectError
37+
enum2str( {} ); // $ExpectError
38+
enum2str( ( x: number ): number => x ); // $ExpectError
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' );
22+
var enum2str = require( './../lib' );
23+
24+
var str = enum2str( str2enum( 'upper' ) );
25+
console.log( str );
26+
// => 'upper'
27+
28+
str = enum2str( str2enum( 'lower' ) );
29+
console.log( str );
30+
// => 'lower'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 BLAS matrix triangle string associated with a BLAS matrix triangle enumeration constant.
23+
*
24+
* @module @stdlib/blas/base/matrix-triangle-enum2str
25+
*
26+
* @example
27+
* var str2enum = require( '@stdlib/blas/base/matrix-triangle-str2enum' );
28+
* var enum2str = require( '@stdlib/blas/base/matrix-triangle-enum2str' );
29+
*
30+
* var v = str2enum( 'upper' );
31+
* // returns <number>
32+
*
33+
* var s = enum2str( v );
34+
* // returns 'upper'
35+
*/
36+
37+
// MODULES //
38+
39+
var main = require( './main.js' );
40+
41+
42+
// EXPORTS //
43+
44+
module.exports = main;

0 commit comments

Comments
 (0)