Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
<!--

@license Apache-2.0

Copyright (c) {{YEAR}} {{COPYRIGHT}}.

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.

-->

# {{ALIAS}}

> {{README_PKG_DESC}}

<!-- 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 {{ALIAS}} = require( '@{{PKG}}' );
```

#### {{ALIAS}}( x\[, options] )

{{README_MAIN_DESC}}

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );

var x = array( {{JS_EXAMPLE_VALUES_2X2}} );
var y = {{ALIAS}}( x );
// returns <ndarray>

var arr = ndarray2array( y );
// returns {{JS_EXAMPLE_RESULTS_2X2}}
```

The function accepts the following arguments:

- **x**: input [ndarray][@stdlib/ndarray/ctor].
- **options**: function options (_optional_).

The function accepts the following options:

- **dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be a real-valued or generic [data type][@stdlib/ndarray/dtypes].
- **order**: output ndarray [order][@stdlib/ndarray/orders] (i.e., memory layout).

By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] determined by the function's output data type [policy][@stdlib/ndarray/output-dtype-policies]. To override the default behavior, set the `dtype` option.

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );
var getDType = require( '@stdlib/ndarray/dtype' );

var x = array( {{JS_EXAMPLE_VALUES_2X2}} );
var y = {{ALIAS}}( x, {
'dtype': 'generic'
});
// returns <ndarray>

var dt = getDType( y );
// returns 'generic'

var arr = ndarray2array( y );
// returns {{JS_EXAMPLE_RESULTS_2X2}}
```

By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having the same [order][@stdlib/ndarray/orders] as the input [ndarray][@stdlib/ndarray/ctor]. To return an [ndarray][@stdlib/ndarray/ctor] having a specific memory layout irrespective of the memory layout of the input [ndarray][@stdlib/ndarray/ctor], set the `order` option.

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );
var getOrder = require( '@stdlib/ndarray/order' );

var x = array( {{JS_EXAMPLE_VALUES_2X2}} );
var y = {{ALIAS}}( x, {
'order': 'column-major'
});
// returns <ndarray>

var ord = getOrder( y );
// returns 'column-major'

var arr = ndarray2array( y );
// returns {{JS_EXAMPLE_RESULTS_2X2}}
```

#### {{ALIAS}}.assign( x, y )

{{README_ASSIGN_DESC}}

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var array = require( '@stdlib/ndarray/array' );

var x = array( {{JS_EXAMPLE_VALUES_2X2}} );
var y = array( [ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ] );

var out = {{ALIAS}}.assign( x, y );
// returns <ndarray>

var bool = ( out === y );
// returns true

var arr = ndarray2array( out );
// returns {{JS_EXAMPLE_RESULTS_2X2}}
```

The function accepts the following arguments:

- **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape of the output [ndarray][@stdlib/ndarray/ctor].
- **y**: output [ndarray][@stdlib/ndarray/ctor].

The function supports broadcasting an input [ndarray][@stdlib/ndarray/ctor] to the shape of the output [ndarray][@stdlib/ndarray/ctor] without performing a physical copy of the input [ndarray][@stdlib/ndarray/ctor]'s underlying data.

```javascript
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var zeros = require( '@stdlib/ndarray/zeros' );
var array = require( '@stdlib/ndarray/array' );

// Create a 2x2 input ndarray:
var x = array( {{JS_EXAMPLE_VALUES_2X2}} );

// Create a 2x2x2 output ndarray:
var y = zeros( [ 2, 2, 2 ] );

var out = {{ALIAS}}.assign( x, y );
// returns <ndarray>

var arr = ndarray2array( out );
// returns [ {{JS_EXAMPLE_RESULTS_2X2}}, {{JS_EXAMPLE_RESULTS_2X2}} ]
```

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

## Notes

- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having a real-valued or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes].

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

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

```javascript
var random = require( '@stdlib/random/{{BASE_PRNG}}' );
var ndarray2array = require( '@stdlib/ndarray/to-array' );
var {{ALIAS}} = require( '@{{PKG}}' );

var x = random( [ 5, 5 ], {{RAND_MIN}}, {{RAND_MAX}} );
console.log( ndarray2array( x ) );

var y = {{ALIAS}}( x );
console.log( ndarray2array( y ) );
```

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

[{{PKG}}]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40{{PKG_LINK_SUFFIX}}

[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/ctor

[@stdlib/ndarray/orders]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/orders

[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/dtypes

[@stdlib/ndarray/output-dtype-policies]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/output-dtype-policies

[@stdlib/ndarray/base/broadcast-shapes]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/ndarray/base/broadcast-shapes

</section>

<!-- /.links -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* @license Apache-2.0
*
* Copyright (c) {{YEAR}} {{COPYRIGHT}}.
*
* 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.
*/

/* THIS IS A GENERATED FILE. DO NOT EDIT DIRECTLY. */

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var random = require( '@stdlib/random/{{BASE_PRNG}}' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var getData = require( '@stdlib/ndarray/data-buffer' );
var format = require( '@stdlib/string/format' );
var pkg = require( './../package.json' ).name;
var {{ALIAS}} = require( './../lib/main.js' );


// VARIABLES //

var DTYPES = [
'float64',
'float32',
'generic'
];


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} size - array size
* @param {string} dtype - data type
* @returns {Function} benchmark function
*/
function createBenchmark( size, dtype ) {
var x = random( [ size ], {{RAND_MIN}}, {{RAND_MAX}}, {
'dtype': dtype
});
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
y = {{ALIAS}}( x );
if ( typeof y !== 'object' ) {
b.fail( 'should return an ndarray' );
}
}
b.toc();
if ( isnan( getData( y )[ i%size ] ) ) {
b.fail( 'should not return NaN' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

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

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

for ( j = 0; j < DTYPES.length; j++ ) {
dt = DTYPES[ j ];
for ( i = min; i <= max; i++ ) {
size = pow( 10, i );
f = createBenchmark( size, dt );
bench( format( '%s:contiguous=true,ndims=1,dtype=%s,size=%d', pkg, dt, size ), f );
}
}
}

main();
Loading
Loading