Skip to content

Commit 8e31cf4

Browse files
committed
Auto-generated commit
1 parent dff88c9 commit 8e31cf4

File tree

15 files changed

+791
-8
lines changed

15 files changed

+791
-8
lines changed

Diff for: base/flag/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# flag
2222

23-
> Return a specified flag for provided [ndarray][@stdlib/ndarray/base/ctor].
23+
> Return a specified flag for a provided [ndarray][@stdlib/ndarray/base/ctor].
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -42,7 +42,7 @@ var flag = require( '@stdlib/ndarray/base/flag' );
4242

4343
#### flag( x, name )
4444

45-
Returns a specified flag for provided [ndarray][@stdlib/ndarray/base/ctor].
45+
Returns a specified flag for a provided [ndarray][@stdlib/ndarray/base/ctor].
4646

4747
```javascript
4848
var zeros = require( '@stdlib/ndarray/zeros' );

Diff for: dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: dist/index.js.map

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: flag/README.md

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
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+
# flag
22+
23+
> Return a specified flag for a provided [ndarray][@stdlib/ndarray/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 flag = require( '@stdlib/ndarray/flag' );
41+
```
42+
43+
#### flag( x, name )
44+
45+
Returns a specified flag for a provided [ndarray][@stdlib/ndarray/ctor].
46+
47+
```javascript
48+
var zeros = require( '@stdlib/ndarray/zeros' );
49+
50+
var x = zeros( [ 3, 2, 3 ] );
51+
// returns <ndarray>
52+
53+
var o = flag( x, 'READONLY' );
54+
// returns <boolean>
55+
```
56+
57+
</section>
58+
59+
<!-- /.usage -->
60+
61+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
62+
63+
<section class="notes">
64+
65+
## Notes
66+
67+
- This function is intended as a slight performance optimization over [`@stdlib/ndarray/flags`][@stdlib/ndarray/flags] when **only** a single flag is needed. For retrieving multiple flags, use [`@stdlib/ndarray/flags`][@stdlib/ndarray/flags] directly.
68+
69+
</section>
70+
71+
<!-- /.notes -->
72+
73+
<!-- Package usage examples. -->
74+
75+
<section class="examples">
76+
77+
## Examples
78+
79+
<!-- eslint no-undef: "error" -->
80+
81+
<!-- eslint-disable new-cap -->
82+
83+
```javascript
84+
var zeros = require( '@stdlib/ndarray/zeros' );
85+
var slice = require( '@stdlib/ndarray/slice' );
86+
var E = require( '@stdlib/slice/multi' );
87+
var S = require( '@stdlib/slice/ctor' );
88+
var flag = require( '@stdlib/ndarray/flag' );
89+
90+
// Create an array:
91+
var x = zeros( [ 10, 10, 10, 10 ] );
92+
// returns <ndarray>
93+
94+
// Define some slices:
95+
var slices = [
96+
// :,:,:,:
97+
E( null, null, null, null ),
98+
99+
// 5:10,4,2:4,::-1
100+
E( S( 5, 10 ), 4, S( 2, 4 ), S( null, null, -1 ) ),
101+
102+
// :,:,2,:
103+
E( null, null, 2, null ),
104+
105+
// 1,2,3,:
106+
E( 1, 2, 3, null ),
107+
108+
// 1,3,::2,4::2
109+
E( 1, 3, S( null, null, 2 ), S( 4, null, 2 ) )
110+
];
111+
112+
// Check whether each slice is row-major contiguous...
113+
var s;
114+
var i;
115+
for ( i = 0; i < slices.length; i++ ) {
116+
s = slice( x, slices[ i ] );
117+
console.log( '%s', flag( s, 'ROW_MAJOR_CONTIGUOUS' ) );
118+
}
119+
```
120+
121+
</section>
122+
123+
<!-- /.examples -->
124+
125+
<!-- 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. -->
126+
127+
<section class="references">
128+
129+
</section>
130+
131+
<!-- /.references -->
132+
133+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
134+
135+
<section class="related">
136+
137+
</section>
138+
139+
<!-- /.related -->
140+
141+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
142+
143+
<section class="links">
144+
145+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
146+
147+
[@stdlib/ndarray/flags]: https://github.com/stdlib-js/ndarray/tree/main/flags
148+
149+
</section>
150+
151+
<!-- /.links -->

Diff for: flag/benchmark/benchmark.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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 zeros = require( './../../zeros' );
25+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var pkg = require( './../package.json' ).name;
27+
var flag = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var values;
34+
var names;
35+
var out;
36+
var i;
37+
38+
values = [
39+
zeros( [ 10, 10, 10, 1 ] ),
40+
zeros( [ 5, 5, 5, 1, 1 ] ),
41+
zeros( [ 3, 4, 5 ] )
42+
];
43+
names = [
44+
'ROW_MAJOR_CONTIGUOUS',
45+
'COLUMN_MAJOR_CONTIGUOUS',
46+
'READONLY'
47+
];
48+
49+
b.tic();
50+
for ( i = 0; i < b.iterations; i++ ) {
51+
out = flag( values[ i%values.length ], names[ i%names.length ] );
52+
if ( typeof out !== 'boolean' ) {
53+
b.fail( 'should return a boolean' );
54+
}
55+
}
56+
b.toc();
57+
if ( !isBoolean( out ) ) {
58+
b.fail( 'should return a boolean' );
59+
}
60+
b.pass( 'benchmark finished' );
61+
b.end();
62+
});

Diff for: flag/docs/repl.txt

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
{{alias}}( x, name )
3+
Returns a specified flag for a provided ndarray.
4+
5+
Parameters
6+
----------
7+
x: ndarray
8+
Input ndarray.
9+
10+
name: string|symbol
11+
Flag name.
12+
13+
Returns
14+
-------
15+
out: any
16+
Flag value.
17+
18+
Examples
19+
--------
20+
> var out = {{alias}}( {{alias:@stdlib/ndarray/zeros}}( [ 3, 3, 3 ] ), 'READONLY' )
21+
<boolean>
22+
23+
See Also
24+
--------
25+

Diff for: flag/docs/types/index.d.ts

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { ndarray, Flags } from '@stdlib/types/ndarray';
24+
25+
/**
26+
* Returns a specified flag for a provided ndarray.
27+
*
28+
* @param x - input ndarray
29+
* @param name - flag name
30+
* @returns flag value
31+
*
32+
* @example
33+
* var zeros = require( `@stdlib/ndarray/zeros` );
34+
*
35+
* var o = flag( zeros( [ 3, 3, 3 ] ), 'READONLY' );
36+
* // returns <boolean>
37+
*/
38+
declare function flag<V extends keyof Flags>( x: ndarray, name: V ): Flags[V];
39+
40+
41+
// EXPORTS //
42+
43+
export = flag;

Diff for: flag/docs/types/test.ts

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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 zeros = require( './../../../zeros' );
20+
import flag = require( './index' );
21+
22+
23+
// TESTS //
24+
25+
// The function returns an ndarray flag...
26+
{
27+
flag( zeros( [ 3, 2, 1 ] ), 'READONLY' ); // $ExpectType boolean | undefined
28+
}
29+
30+
// The compiler throws an error if the function is provided a first argument which is not an ndarray...
31+
{
32+
flag( '5', 'READONLY' ); // $ExpectError
33+
flag( 5, 'READONLY' ); // $ExpectError
34+
flag( true, 'READONLY' ); // $ExpectError
35+
flag( false, 'READONLY' ); // $ExpectError
36+
flag( null, 'READONLY' ); // $ExpectError
37+
flag( undefined, 'READONLY' ); // $ExpectError
38+
flag( [ '1', '2' ], 'READONLY' ); // $ExpectError
39+
flag( {}, 'READONLY' ); // $ExpectError
40+
flag( ( x: number ): number => x, 'READONLY' ); // $ExpectError
41+
}
42+
43+
// The compiler throws an error if the function is provided a second argument which is not a valid flag name...
44+
{
45+
flag( zeros( [ 3, 2, 1 ] ), null ); // $ExpectError
46+
flag( zeros( [ 3, 2, 1 ] ), undefined ); // $ExpectError
47+
flag( zeros( [ 3, 2, 1 ] ), [ '1', '2' ] ); // $ExpectError
48+
flag( zeros( [ 3, 2, 1 ] ), {} ); // $ExpectError
49+
flag( zeros( [ 3, 2, 1 ] ), ( x: number ): number => x ); // $ExpectError
50+
}
51+
52+
// The compiler throws an error if the function is provided an unsupported number of arguments...
53+
{
54+
flag(); // $ExpectError
55+
flag( zeros( [ 2, 2 ] ) ); // $ExpectError
56+
flag( zeros( [ 2, 2 ] ), 'READONLY', {} ); // $ExpectError
57+
}

0 commit comments

Comments
 (0)