Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Dec 31, 2023
1 parent dd05593 commit dff88c9
Show file tree
Hide file tree
Showing 13 changed files with 765 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/index.js.map

Large diffs are not rendered by default.

145 changes: 145 additions & 0 deletions flags/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<!--
@license Apache-2.0
Copyright (c) 2023 The Stdlib Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

# flags

> Return the flags of a provided [ndarray][@stdlib/ndarray/ctor].
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```javascript
var flags = require( '@stdlib/ndarray/flags' );
```

#### flags( x )

Returns the flags of a provided [ndarray][@stdlib/ndarray/ctor].

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

var x = zeros( [ 3, 2, 3 ] );
// returns <ndarray>

var o = flags( x );
// returns {...}
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

<!-- eslint-disable new-cap -->

```javascript
var zeros = require( '@stdlib/ndarray/zeros' );
var slice = require( '@stdlib/ndarray/slice' );
var E = require( '@stdlib/slice/multi' );
var S = require( '@stdlib/slice/ctor' );
var flags = require( '@stdlib/ndarray/flags' );

// Create an array:
var x = zeros( [ 10, 10, 10, 10 ] );
// returns <ndarray>

// Define some slices:
var slices = [
// :,:,:,:
E( null, null, null, null ),

// 5:10,4,2:4,::-1
E( S( 5, 10 ), 4, S( 2, 4 ), S( null, null, -1 ) ),

// :,:,2,:
E( null, null, 2, null ),

// 1,2,3,:
E( 1, 2, 3, null ),

// 1,3,::2,4::2
E( 1, 3, S( null, null, 2 ), S( 4, null, 2 ) )
];

// Retrieve the flags for each slice...
var s;
var i;
for ( i = 0; i < slices.length; i++ ) {
s = slice( x, slices[ i ] );
console.log( '%s', JSON.stringify( flags( s ) ) );
}
```

</section>

<!-- /.examples -->

<!-- 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. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor

</section>

<!-- /.links -->
56 changes: 56 additions & 0 deletions flags/benchmark/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var zeros = require( './../../zeros' );
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
var pkg = require( './../package.json' ).name;
var flags = require( './../lib' );


// MAIN //

bench( pkg, function benchmark( b ) {
var values;
var out;
var i;

values = [
zeros( [ 10, 10, 10, 1 ] ),
zeros( [ 5, 5, 5, 1, 1 ] ),
zeros( [ 3, 4, 5 ] )
];

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = flags( values[ i%values.length ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an object' );
}
}
b.toc();
if ( !isPlainObject( out ) ) {
b.fail( 'should return an object' );
}
b.pass( 'benchmark finished' );
b.end();
});
22 changes: 22 additions & 0 deletions flags/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

{{alias}}( x )
Returns the flags of a provided ndarray.

Parameters
----------
x: ndarray
Input ndarray.

Returns
-------
out: Object
Flags.

Examples
--------
> var out = {{alias}}( {{alias:@stdlib/ndarray/zeros}}( [ 3, 3, 3 ] ) )
{...}

See Also
--------

42 changes: 42 additions & 0 deletions flags/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// TypeScript Version: 4.1

/// <reference types="@stdlib/types"/>

import { ndarray, Flags } from '@stdlib/types/ndarray';

/**
* Returns the flags of a provided ndarray.
*
* @param x - input ndarray
* @returns flags
*
* @example
* var zeros = require( `@stdlib/ndarray/zeros` );
*
* var o = flags( zeros( [ 3, 3, 3 ] ) );
* // returns {...}
*/
declare function flags<T = unknown>( x: ndarray ): Flags<T>;


// EXPORTS //

export = flags;
47 changes: 47 additions & 0 deletions flags/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import zeros = require( './../../../zeros' );
import flags = require( './index' );


// TESTS //

// The function returns ndarray flags...
{
flags( zeros( [ 3, 2, 1 ] ) ); // $ExpectType Flags<unknown>
}

// The compiler throws an error if the function is provided a first argument which is not an ndarray...
{
flags( '5' ); // $ExpectError
flags( 5 ); // $ExpectError
flags( true ); // $ExpectError
flags( false ); // $ExpectError
flags( null ); // $ExpectError
flags( undefined ); // $ExpectError
flags( [ '1', '2' ] ); // $ExpectError
flags( {} ); // $ExpectError
flags( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
flags(); // $ExpectError
flags( zeros( [ 2, 2 ] ), {} ); // $ExpectError
}
57 changes: 57 additions & 0 deletions flags/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2023 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/* eslint-disable new-cap */

'use strict';

var zeros = require( './../../zeros' );
var slice = require( './../../slice' );
var E = require( '@stdlib/slice/multi' );
var S = require( '@stdlib/slice/ctor' );
var flags = require( './../lib' );

// Create an array:
var x = zeros( [ 10, 10, 10, 10 ] );
// returns <ndarray>

// Define some slices:
var slices = [
// :,:,:,:
E( null, null, null, null ),

// 5:10,4,2:4,::-1
E( S( 5, 10 ), 4, S( 2, 4 ), S( null, null, -1 ) ),

// :,:,2,:
E( null, null, 2, null ),

// 1,2,3,:
E( 1, 2, 3, null ),

// 1,3,::2,4::2
E( 1, 3, S( null, null, 2 ), S( 4, null, 2 ) )
];

// Retrieve the flags for each slice...
var s;
var i;
for ( i = 0; i < slices.length; i++ ) {
s = slice( x, slices[ i ] );
console.log( '%s', JSON.stringify( flags( s ) ) );
}
Loading

0 comments on commit dff88c9

Please sign in to comment.