Skip to content

Commit 57e97ae

Browse files
committed
feat: add ndarray/base/dtype-objects
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 2cbcb64 commit 57e97ae

File tree

10 files changed

+538
-0
lines changed

10 files changed

+538
-0
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2025 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+
# Data Type Objects
22+
23+
> Return an object mapping supported [data type][@stdlib/ndarray/dtypes] strings to data type [objects][@stdlib/ndarray/dtype-ctor].
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 dtypeObjects = require( '@stdlib/ndarray/base/dtype-objects' );
41+
```
42+
43+
#### dtypeObjects()
44+
45+
Returns an object mapping supported [data type][@stdlib/ndarray/dtypes] strings to data type [objects][@stdlib/ndarray/dtype-ctor].
46+
47+
```javascript
48+
var out = dtypeObjects();
49+
// {...}
50+
```
51+
52+
</section>
53+
54+
<!-- /.usage -->
55+
56+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
57+
58+
<section class="notes">
59+
60+
</section>
61+
62+
<!-- /.notes -->
63+
64+
<!-- Package usage examples. -->
65+
66+
<section class="examples">
67+
68+
## Examples
69+
70+
<!-- eslint no-undef: "error" -->
71+
72+
```javascript
73+
var dtypeStrings = require( '@stdlib/ndarray/base/dtype-strings' );
74+
var dtypeObjects = require( '@stdlib/ndarray/base/dtype-objects' );
75+
76+
var dt = dtypeStrings();
77+
// returns [...]
78+
79+
var o = dtypeObjects();
80+
// returns {...}
81+
82+
var i;
83+
for ( i = 0; i < dt.length; i++ ) {
84+
console.log( '%s => %s', dt[ i ], o[ dt[ i ] ].description );
85+
}
86+
```
87+
88+
</section>
89+
90+
<!-- /.examples -->
91+
92+
<!-- 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. -->
93+
94+
<section class="references">
95+
96+
</section>
97+
98+
<!-- /.references -->
99+
100+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
101+
102+
<section class="related">
103+
104+
</section>
105+
106+
<!-- /.related -->
107+
108+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
109+
110+
<section class="links">
111+
112+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes
113+
114+
[@stdlib/ndarray/dtype-ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtype-ctor
115+
116+
</section>
117+
118+
<!-- /.links -->
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 isObject = require( '@stdlib/assert/is-object' );
25+
var pkg = require( './../package.json' ).name;
26+
var dtypeObjects = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var out;
33+
var i;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
out = dtypeObjects();
38+
if ( typeof out !== 'object' ) {
39+
b.fail( 'should return an object' );
40+
}
41+
}
42+
b.toc();
43+
if ( !isObject( out ) ) {
44+
b.fail( 'should return an object' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
{{alias}}()
3+
Returns an object mapping supported data type strings to data type objects.
4+
5+
Returns
6+
-------
7+
out: Object
8+
Object mapping supported data type strings to data type objects.
9+
10+
Examples
11+
--------
12+
> var out = {{alias}}()
13+
{...}
14+
15+
See Also
16+
--------
17+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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+
/// <reference types="@stdlib/types"/>
22+
23+
import { DataTypeString } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* An object mapping supported data type strings to data type objects.
27+
*/
28+
type Table = {
29+
[ key in DataTypeString ]: Object; // FIXME: update once we have a `DataType` object type definition
30+
};
31+
32+
/**
33+
* Returns an object mapping supported data type strings to data type objects.
34+
*
35+
* @returns object mapping supported data type strings to data type objects
36+
*
37+
* @example
38+
* var o = dtypeObjects();
39+
* // returns {...}
40+
*/
41+
declare function dtypeObjects(): Table;
42+
43+
44+
// EXPORTS //
45+
46+
export = dtypeObjects;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 dtypeObjects = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an object mapping data type strings to data type objects...
25+
{
26+
dtypeObjects(); // $ExpectType Table
27+
}
28+
29+
// The compiler throws an error if the function is provided an unsupported number of arguments...
30+
{
31+
dtypeObjects( 'foo' ); // $ExpectError
32+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 dtypeStrings = require( '@stdlib/ndarray/base/dtype-strings' );
22+
var dtypeObjects = require( './../lib' );
23+
24+
var dt = dtypeStrings();
25+
// returns [...]
26+
27+
var o = dtypeObjects();
28+
// returns {...}
29+
30+
var i;
31+
for ( i = 0; i < dt.length; i++ ) {
32+
console.log( '%s => %s', dt[ i ], o[ dt[ i ] ].description );
33+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2025 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 an object mapping supported data type strings to data type objects.
23+
*
24+
* @module @stdlib/ndarray/base/dtype-objects
25+
*
26+
* @example
27+
* var dtypeObjects = require( '@stdlib/ndarray/base/dtype-objects' );
28+
*
29+
* var o = dtypeObjects();
30+
* // returns {...}
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)