Skip to content

Commit 87b15e2

Browse files
committed
Auto-generated commit
1 parent 977056c commit 87b15e2

16 files changed

+1081
-45
lines changed

.github/.keepalive

Lines changed: 0 additions & 1 deletion
This file was deleted.

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Copyright (c) 2016-2023 The Stdlib Authors.
1+
Copyright (c) 2016-2024 The Stdlib Authors.

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,20 @@ var arr = oneTo( 5.1 );
8787
// returns [ 1, 2, 3, 4, 5, 6 ]
8888
```
8989

90+
#### oneTo.assign( out, stride, offset )
91+
92+
Fills an array with linearly spaced numeric elements which increment by 1 starting from one.
93+
94+
```javascript
95+
var out = [ 0, 0, 0, 0, 0, 0 ];
96+
97+
var arr = oneTo.assign( out, -1, out.length-1 );
98+
// returns [ 6, 5, 4, 3, 2, 1 ]
99+
100+
var bool = ( arr === out );
101+
// returns true
102+
```
103+
90104
</section>
91105

92106
<!-- /.usage -->

benchmark/benchmark.assign.length.js

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench-harness' );
24+
var pow = require( '@stdlib/math-base-special-pow' );
25+
var isArray = require( '@stdlib/assert-is-array' );
26+
var zeros = require( '@stdlib/array-base-zeros' );
27+
var pkg = require( './../package.json' ).name;
28+
var oneTo = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var out = zeros( len );
42+
return benchmark;
43+
44+
/**
45+
* Benchmark function.
46+
*
47+
* @private
48+
* @param {Benchmark} b - benchmark instance
49+
*/
50+
function benchmark( b ) {
51+
var v;
52+
var i;
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
v = oneTo.assign( out, 1, 0 );
57+
if ( typeof v !== 'object' ) {
58+
b.fail( 'should return an array' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isArray( v ) ) {
63+
b.fail( 'should return an array' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var len;
80+
var min;
81+
var max;
82+
var f;
83+
var i;
84+
85+
min = 1; // 10^min
86+
max = 6; // 10^max
87+
88+
for ( i = min; i <= max; i++ ) {
89+
len = pow( 10, i );
90+
f = createBenchmark( len );
91+
bench( pkg+':assign:len='+len, f );
92+
}
93+
}
94+
95+
main();

benchmark/benchmark.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
var bench = require( '@stdlib/bench-harness' );
2424
var isArray = require( '@stdlib/assert-is-array' );
25+
var zeros = require( '@stdlib/array-base-zeros' );
2526
var pkg = require( './../package.json' ).name;
2627
var oneTo = require( './../lib' );
2728

@@ -46,3 +47,25 @@ bench( pkg, function benchmark( b ) {
4647
b.pass( 'benchmark finished' );
4748
b.end();
4849
});
50+
51+
bench( pkg+':assign', function benchmark( b ) {
52+
var out;
53+
var i;
54+
var v;
55+
56+
out = zeros( 100 );
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
v = oneTo.assign( out, 1, 0 );
61+
if ( typeof v !== 'object' ) {
62+
b.fail( 'should return an array' );
63+
}
64+
}
65+
b.toc();
66+
if ( !isArray( v ) ) {
67+
b.fail( 'should return an array' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
});

dist/index.js

Lines changed: 6 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/repl.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,34 @@
2323
> var arr = {{alias}}( 6 )
2424
[ 1, 2, 3, 4, 5, 6 ]
2525

26+
27+
{{alias}}.assign( out, stride, offset )
28+
Fills an array with linearly spaced numeric elements which increment by 1
29+
starting from one.
30+
31+
Parameters
32+
----------
33+
out: ArrayLikeObject
34+
Output array.
35+
36+
stride: integer
37+
Output array stride.
38+
39+
offset: integer
40+
Output array index offset.
41+
42+
Returns
43+
-------
44+
out: ArrayLikeObject
45+
Output array.
46+
47+
Examples
48+
--------
49+
> var out = [ 0, 0, 0, 0, 0, 0 ];
50+
> {{alias}}.assign( out, -1, out.length-1 );
51+
> out
52+
[ 6, 5, 4, 3, 2, 1 ]
53+
2654
See Also
2755
--------
2856

0 commit comments

Comments
 (0)