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 Jan 18, 2024
1 parent ccb7714 commit 9cee86c
Show file tree
Hide file tree
Showing 24 changed files with 2,109 additions and 75 deletions.
14 changes: 14 additions & 0 deletions base/one-to/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ var arr = oneTo( 5.1 );
// returns [ 1, 2, 3, 4, 5, 6 ]
```

#### oneTo.assign( out, stride, offset )

Fills an array with linearly spaced numeric elements which increment by 1 starting from one.

```javascript
var out = [ 0, 0, 0, 0, 0, 0 ];

var arr = oneTo.assign( out, -1, out.length-1 );
// returns [ 6, 5, 4, 3, 2, 1 ]

var bool = ( arr === out );
// returns true
```

</section>

<!-- /.usage -->
Expand Down
95 changes: 95 additions & 0 deletions base/one-to/benchmark/benchmark.assign.length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 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 isArray = require( '@stdlib/assert/is-array' );
var zeros = require( './../../../base/zeros' );
var pkg = require( './../package.json' ).name;
var oneTo = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var out = zeros( len );
return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = oneTo.assign( out, 1, 0 );
if ( typeof v !== 'object' ) {
b.fail( 'should return an array' );
}
}
b.toc();
if ( !isArray( v ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

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

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

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':assign:len='+len, f );
}
}

main();
23 changes: 23 additions & 0 deletions base/one-to/benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

var bench = require( '@stdlib/bench' );
var isArray = require( '@stdlib/assert/is-array' );
var zeros = require( './../../../base/zeros' );
var pkg = require( './../package.json' ).name;
var oneTo = require( './../lib' );

Expand All @@ -46,3 +47,25 @@ bench( pkg, function benchmark( b ) {
b.pass( 'benchmark finished' );
b.end();
});

bench( pkg+':assign', function benchmark( b ) {
var out;
var i;
var v;

out = zeros( 100 );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = oneTo.assign( out, 1, 0 );
if ( typeof v !== 'object' ) {
b.fail( 'should return an array' );
}
}
b.toc();
if ( !isArray( v ) ) {
b.fail( 'should return an array' );
}
b.pass( 'benchmark finished' );
b.end();
});
28 changes: 28 additions & 0 deletions base/one-to/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@
> var arr = {{alias}}( 6 )
[ 1, 2, 3, 4, 5, 6 ]


{{alias}}.assign( out, stride, offset )
Fills an array with linearly spaced numeric elements which increment by 1
starting from one.

Parameters
----------
out: ArrayLikeObject
Output array.

stride: integer
Output array stride.

offset: integer
Output array index offset.

Returns
-------
out: ArrayLikeObject
Output array.

Examples
--------
> var out = [ 0, 0, 0, 0, 0, 0 ];
> {{alias}}.assign( out, -1, out.length-1 );
> out
[ 6, 5, 4, 3, 2, 1 ]

See Also
--------

Loading

0 comments on commit 9cee86c

Please sign in to comment.