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 57e1478 commit cd71690
Show file tree
Hide file tree
Showing 16 changed files with 1,081 additions and 45 deletions.
1 change: 0 additions & 1 deletion .github/.keepalive

This file was deleted.

2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Copyright (c) 2016-2023 The Stdlib Authors.
Copyright (c) 2016-2024 The Stdlib Authors.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ var arr = zeroTo( 5.1 );
// returns [ 0, 1, 2, 3, 4, 5 ]
```

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

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

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

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

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

</section>

<!-- /.usage -->
Expand Down
95 changes: 95 additions & 0 deletions 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-harness' );
var pow = require( '@stdlib/math-base-special-pow' );
var isArray = require( '@stdlib/assert-is-array' );
var zeros = require( '@stdlib/array-base-zeros' );
var pkg = require( './../package.json' ).name;
var zeroTo = 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 = zeroTo.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 benchmark/benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

var bench = require( '@stdlib/bench-harness' );
var isArray = require( '@stdlib/assert-is-array' );
var zeros = require( '@stdlib/array-base-zeros' );
var pkg = require( './../package.json' ).name;
var zeroTo = 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 = zeroTo.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();
});
9 changes: 6 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,34 @@
> var arr = {{alias}}( 6 )
[ 0, 1, 2, 3, 4, 5 ]


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

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
[ 5, 4, 3, 2, 1, 0 ]

See Also
--------

Loading

0 comments on commit cd71690

Please sign in to comment.