Skip to content

Commit 35de20d

Browse files
committed
feat: add ndarray/defaults
1 parent 6ca0ecb commit 35de20d

File tree

10 files changed

+676
-0
lines changed

10 files changed

+676
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 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+
# defaults
22+
23+
> Default ndarray settings.
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 defaults = require( '@stdlib/ndarray/defaults' );
41+
```
42+
43+
#### defaults()
44+
45+
Returns default ndarray settings.
46+
47+
```javascript
48+
var out = defaults();
49+
// returns {...}
50+
```
51+
52+
The returned object has the following properties:
53+
54+
- **dtypes**: default data types.
55+
56+
- **default**: default data type.
57+
- **floating_point**: default floating-point data type.
58+
- **real_floating_point**: default real-valued floating-point data type.
59+
- **complex_floating_point**: default complex-valued floating-point data type.
60+
- **integral**: default integer data type.
61+
- **signed_integer**: default signed integer data type.
62+
- **unsigned_integer**: default unsigned integer data type.
63+
64+
- **order**: default memory layout.
65+
66+
- **casting**: default casting mode.
67+
68+
- **index_mode**: default index mode.
69+
70+
</section>
71+
72+
<!-- /.usage -->
73+
74+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
75+
76+
<section class="notes">
77+
78+
</section>
79+
80+
<!-- /.notes -->
81+
82+
<!-- Package usage examples. -->
83+
84+
<section class="examples">
85+
86+
## Examples
87+
88+
<!-- eslint no-undef: "error" -->
89+
90+
```javascript
91+
var array = require( '@stdlib/ndarray/array' );
92+
var defaults = require( '@stdlib/ndarray/defaults' );
93+
94+
var o = defaults();
95+
96+
var buf = [ [ 1, 2 ], [ 3, 4 ] ];
97+
var opts = {
98+
'order': o.order,
99+
'casting': 'unsafe',
100+
'mode': o.index_mode
101+
};
102+
103+
opts.dtype = o.dtypes.default;
104+
var x = array( buf, opts );
105+
console.log( x.dtype );
106+
107+
opts.dtype = o.dtypes.floating_point;
108+
x = array( buf, opts );
109+
console.log( x.dtype );
110+
111+
opts.dtype = o.dtypes.real_floating_point;
112+
x = array( buf, opts );
113+
console.log( x.dtype );
114+
115+
opts.dtype = o.dtypes.integral;
116+
x = array( buf, opts );
117+
console.log( x.dtype );
118+
119+
opts.dtype = o.dtypes.signed_integer;
120+
x = array( buf, opts );
121+
console.log( x.dtype );
122+
123+
opts.dtype = o.dtypes.unsigned_integer;
124+
x = array( buf, opts );
125+
console.log( x.dtype );
126+
```
127+
128+
</section>
129+
130+
<!-- /.examples -->
131+
132+
<!-- 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. -->
133+
134+
<section class="references">
135+
136+
</section>
137+
138+
<!-- /.references -->
139+
140+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
141+
142+
<section class="related">
143+
144+
</section>
145+
146+
<!-- /.related -->
147+
148+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
149+
150+
<section class="links">
151+
152+
</section>
153+
154+
<!-- /.links -->
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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 pkg = require( './../package.json' ).name;
25+
var defaults = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg, function benchmark( b ) {
31+
var out;
32+
var i;
33+
34+
b.tic();
35+
for ( i = 0; i < b.iterations; i++ ) {
36+
out = defaults();
37+
if ( typeof out !== 'object' ) {
38+
b.fail( 'should return an object' );
39+
}
40+
}
41+
b.toc();
42+
if ( out.dtypes.default !== 'float64' ) {
43+
b.fail( 'unexpected error' );
44+
}
45+
b.pass( 'benchmark finished' );
46+
b.end();
47+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
2+
{{alias}}()
3+
Returns default ndarray settings.
4+
5+
Returns
6+
-------
7+
out: Object
8+
Default settings.
9+
10+
out.dtypes: Object
11+
Default data types.
12+
13+
out.dtypes.default: string
14+
Default data type.
15+
16+
out.dtypes.floating_point: string
17+
Default floating-point data type.
18+
19+
out.dtypes.real_floating_point: string
20+
Default real-valued floating-point data type.
21+
22+
out.dtypes.complex_floating_point: string
23+
Default complex-valued floating-point data type.
24+
25+
out.dtypes.integral: string
26+
Default integer data type.
27+
28+
out.dtypes.signed_integer: string
29+
Default signed integer data type.
30+
31+
out.dtypes.unsigned_integer: string
32+
Default unsigned integer data type.
33+
34+
out.order: string
35+
Default memory layout.
36+
37+
out.casting: string
38+
Default casting mode.
39+
40+
out.index_mode: string
41+
Default indexing mode.
42+
43+
Examples
44+
--------
45+
> var out = {{alias}}()
46+
{...}
47+
48+
See Also
49+
--------
50+
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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: 2.0
20+
21+
/**
22+
* Interface describing default data types.
23+
*/
24+
interface DataTypes {
25+
/**
26+
* Default data type.
27+
*/
28+
default: 'float64';
29+
30+
/**
31+
* Default floating-point data type.
32+
*/
33+
floating_point: 'float64';
34+
35+
/**
36+
* Default real-valued floating-point data type.
37+
*/
38+
real_floating_point: 'float64';
39+
40+
/**
41+
* Default complex-valued floating-point data type.
42+
*/
43+
complex_floating_point: 'complex128';
44+
45+
/**
46+
* Default integer data type.
47+
*/
48+
integral: 'int32';
49+
50+
/**
51+
* Default signed integer data type.
52+
*/
53+
signed_integer: 'int32';
54+
55+
/**
56+
* Default unsigned integer data type.
57+
*/
58+
unsigned_integer: 'uint32';
59+
}
60+
61+
/**
62+
* Interface describing default ndarray settings.
63+
*/
64+
interface Defaults {
65+
/**
66+
* Default data types.
67+
*/
68+
dtypes: DataTypes;
69+
70+
/**
71+
* Default memory layout.
72+
*/
73+
order: 'row-major';
74+
75+
/**
76+
* Default casting mode.
77+
*/
78+
casting: 'safe';
79+
80+
/**
81+
* Default index mode.
82+
*/
83+
index_mode: 'throw';
84+
}
85+
86+
/**
87+
* Returns default ndarray settings.
88+
*
89+
* @returns default settings
90+
*
91+
* @example
92+
* var o = defaults();
93+
* // returns {...}
94+
*/
95+
declare function defaults(): Defaults;
96+
97+
98+
// EXPORTS //
99+
100+
export = defaults;
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) 2023 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 defaults = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an object...
25+
{
26+
defaults(); // $ExpectType Defaults
27+
}
28+
29+
// The compiler throws an error if the function is provided any arguments...
30+
{
31+
defaults( 9 ); // $ExpectError
32+
}

0 commit comments

Comments
 (0)