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 Aug 14, 2023
1 parent bb99ebf commit e7c2f5f
Show file tree
Hide file tree
Showing 13 changed files with 709 additions and 5 deletions.
9 changes: 9 additions & 0 deletions base/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,15 @@ setReadOnly( ns, 'zeros2d', require( './../../base/zeros2d' ) );
*/
setReadOnly( ns, 'zeros3d', require( './../../base/zeros3d' ) );

/**
* @name zeros4d
* @memberof ns
* @readonly
* @type {Function}
* @see {@link module:@stdlib/array/base/zeros4d}
*/
setReadOnly( ns, 'zeros4d', require( './../../base/zeros4d' ) );

/**
* @name zerosnd
* @memberof ns
Expand Down
108 changes: 108 additions & 0 deletions base/zeros4d/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<!--
@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.
-->

# zeros4d

> Create a zero-filled four-dimensional nested array.
<!-- 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 zeros4d = require( '@stdlib/array/base/zeros4d' );
```

#### zeros4d( shape )

Returns a zero-filled four-dimensional nested array.

```javascript
var out = zeros4d( [ 1, 1, 2, 3 ] );
// returns [ [ [ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ] ] ]
```

</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" -->

```javascript
var zeros4d = require( '@stdlib/array/base/zeros4d' );

var out = zeros4d( [ 1, 1, 1, 3 ] );
// returns [ [ [ [ 0.0, 0.0, 0.0 ] ] ] ]

out = zeros4d( [ 1, 1, 3, 1 ] );
// returns [ [ [ [ 0.0 ], [ 0.0 ], [ 0.0 ] ] ] ]
```

</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">

</section>

<!-- /.links -->
95 changes: 95 additions & 0 deletions base/zeros4d/benchmark/benchmark.size.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @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 pow = require( '@stdlib/math/base/special/pow' );
var floor = require( '@stdlib/math/base/special/floor' );
var isArrayArray = require( '@stdlib/assert/is-array-array' );
var pkg = require( './../package.json' ).name;
var zeros4d = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} N - array lengths
* @returns {Function} benchmark function
*/
function createBenchmark( N ) {
return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var out;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
out = zeros4d( [ N, N, N, N ] );
if ( typeof out !== 'object' ) {
b.fail( 'should return an array of arrays' );
}
}
b.toc();
if ( !isArrayArray( out ) ) {
b.fail( 'should return an array of arrays' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var min;
var max;
var N;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
N = floor( pow( pow( 10, i ), 1.0/4.0 ) );

f = createBenchmark( N );
bench( pkg+'::equidimensional:size='+(N*N*N*N), f );
}
}

main();
22 changes: 22 additions & 0 deletions base/zeros4d/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

{{alias}}( shape )
Returns a zero-filled four-dimensional nested array.

Parameters
----------
shape: Array<integer>
Array shape.

Returns
-------
out: Array
Output array.

Examples
--------
> var out = {{alias}}( [ 1, 1, 1, 3 ] )
[ [ [ [ 0.0, 0.0, 0.0 ] ] ] ]

See Also
--------

40 changes: 40 additions & 0 deletions base/zeros4d/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* @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 { Collection } from '@stdlib/types/object';

/**
* Returns a zero-filled four-dimensional nested array.
*
* @param shape - array shape
* @returns output array
*
* @example
* var out = zeros4d( [ 1, 1, 1, 3 ] );
* // returns [ [ [ [ 0.0, 0.0, 0.0 ] ] ] ]
*/
declare function zeros4d( shape: Collection<number> ): Array<Array<Array<Array<number>>>>;


// EXPORTS //

export = zeros4d;
44 changes: 44 additions & 0 deletions base/zeros4d/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* @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 zeros4d = require( './index' );


// TESTS //

// The function returns a nested array...
{
zeros4d( [ 1, 1, 1, 3 ] ); // $ExpectType number[][][][]
}

// The compiler throws an error if the function is provided a first argument which is not an array of numbers...
{
zeros4d( 'abc' ); // $ExpectError
zeros4d( true ); // $ExpectError
zeros4d( false ); // $ExpectError
zeros4d( null ); // $ExpectError
zeros4d( [ '1' ] ); // $ExpectError
zeros4d( {} ); // $ExpectError
zeros4d( ( x: number ): number => x ); // $ExpectError
}

// The compiler throws an error if the function is provided an unsupported number of arguments...
{
zeros4d(); // $ExpectError
zeros4d( [ 1, 1, 1, 3 ], 2 ); // $ExpectError
}
29 changes: 29 additions & 0 deletions base/zeros4d/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @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';

var zeros4d = require( './../lib' );

var out = zeros4d( [ 1, 1, 1, 3 ] );
console.log( out );
// => [ [ [ [ 0.0, 0.0, 0.0 ] ] ] ]

out = zeros4d( [ 1, 1, 3, 1 ] );
console.log( out );
// => [ [ [ [ 0.0 ], [ 0.0 ], [ 0.0 ] ] ] ]
Loading

0 comments on commit e7c2f5f

Please sign in to comment.