Skip to content

Commit fb64c4f

Browse files
committed
Auto-generated commit
1 parent 7cc8804 commit fb64c4f

File tree

14 files changed

+640
-5
lines changed

14 files changed

+640
-5
lines changed

base/lib/index.js

+9
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ setReadOnly( ns, 'logspace', require( './../../base/logspace' ) );
387387
*/
388388
setReadOnly( ns, 'nCartesianProduct', require( './../../base/n-cartesian-product' ) );
389389

390+
/**
391+
* @name oneTo
392+
* @memberof ns
393+
* @readonly
394+
* @type {Function}
395+
* @see {@link module:@stdlib/array/base/one-to}
396+
*/
397+
setReadOnly( ns, 'oneTo', require( './../../base/one-to' ) );
398+
390399
/**
391400
* @name ones
392401
* @memberof ns

base/one-to/README.md

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2023 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# oneTo
22+
23+
> Generate a linearly spaced numeric array whose elements increment by 1 starting from one.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var oneTo = require( '@stdlib/array/base/one-to' );
31+
```
32+
33+
#### oneTo( n )
34+
35+
Generates a linearly spaced numeric array whose elements increment by `1` starting from one.
36+
37+
```javascript
38+
var arr = oneTo( 6 );
39+
// returns [ 1, 2, 3, 4, 5, 6 ]
40+
```
41+
42+
If `n <= 0`, the function returns an empty array.
43+
44+
```javascript
45+
var arr = oneTo( 0 );
46+
// returns []
47+
48+
arr = oneTo( -1 );
49+
// returns []
50+
```
51+
52+
If `n` is a non-integer value greater than zero, the function returns an array having `ceil(n)` elements.
53+
54+
```javascript
55+
var arr = oneTo( 5.1 );
56+
// returns [ 1, 2, 3, 4, 5, 6 ]
57+
```
58+
59+
</section>
60+
61+
<!-- /.usage -->
62+
63+
<section class="notes">
64+
65+
</section>
66+
67+
<!-- /.notes -->
68+
69+
<section class="examples">
70+
71+
## Examples
72+
73+
<!-- eslint no-undef: "error" -->
74+
75+
```javascript
76+
var sort2hp = require( '@stdlib/blas/ext/base/gsort2hp' );
77+
var filledBy = require( '@stdlib/array/base/filled-by' );
78+
var randu = require( '@stdlib/random/base/randu' );
79+
var oneTo = require( '@stdlib/array/base/one-to' );
80+
81+
// Generate an array of random numbers:
82+
var x = filledBy( 10, randu );
83+
84+
// Generate a linearly-spaced array:
85+
var y = oneTo( x.length );
86+
87+
// Create a temporary array to avoid mutation:
88+
var tmp = x.slice();
89+
90+
// Sort `y` according to the sort order of `x`:
91+
sort2hp( x.length, 1, tmp, 1, y, 1 );
92+
93+
console.log( x );
94+
console.log( y );
95+
```
96+
97+
</section>
98+
99+
<!-- /.examples -->
100+
101+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
102+
103+
<section class="related">
104+
105+
</section>
106+
107+
<!-- /.related -->
108+
109+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
110+
111+
<section class="links">
112+
113+
</section>
114+
115+
<!-- /.links -->

base/one-to/benchmark/benchmark.js

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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' );
24+
var isArray = require( '@stdlib/assert/is-array' );
25+
var pkg = require( './../package.json' ).name;
26+
var oneTo = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var i;
33+
var v;
34+
35+
b.tic();
36+
for ( i = 0; i < b.iterations; i++ ) {
37+
v = oneTo( 100 );
38+
if ( typeof v !== 'object' ) {
39+
b.fail( 'should return an array' );
40+
}
41+
}
42+
b.toc();
43+
if ( !isArray( v ) ) {
44+
b.fail( 'should return an array' );
45+
}
46+
b.pass( 'benchmark finished' );
47+
b.end();
48+
});
+93
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isArray = require( '@stdlib/assert/is-array' );
26+
var pkg = require( './../package.json' ).name;
27+
var oneTo = require( './../lib' );
28+
29+
30+
// FUNCTIONS //
31+
32+
/**
33+
* Creates a benchmark function.
34+
*
35+
* @private
36+
* @param {PositiveInteger} len - array length
37+
* @returns {Function} benchmark function
38+
*/
39+
function createBenchmark( len ) {
40+
return benchmark;
41+
42+
/**
43+
* Benchmark function.
44+
*
45+
* @private
46+
* @param {Benchmark} b - benchmark instance
47+
*/
48+
function benchmark( b ) {
49+
var v;
50+
var i;
51+
52+
b.tic();
53+
for ( i = 0; i < b.iterations; i++ ) {
54+
v = oneTo( len );
55+
if ( typeof v !== 'object' ) {
56+
b.fail( 'should return an array' );
57+
}
58+
}
59+
b.toc();
60+
if ( !isArray( v ) ) {
61+
b.fail( 'should return an array' );
62+
}
63+
b.pass( 'benchmark finished' );
64+
b.end();
65+
}
66+
}
67+
68+
69+
// MAIN //
70+
71+
/**
72+
* Main execution sequence.
73+
*
74+
* @private
75+
*/
76+
function main() {
77+
var len;
78+
var min;
79+
var max;
80+
var f;
81+
var i;
82+
83+
min = 1; // 10^min
84+
max = 6; // 10^max
85+
86+
for ( i = min; i <= max; i++ ) {
87+
len = pow( 10, i );
88+
f = createBenchmark( len );
89+
bench( pkg+':len='+len, f );
90+
}
91+
}
92+
93+
main();

base/one-to/docs/repl.txt

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
{{alias}}( n )
3+
Generates a linearly spaced numeric array whose elements increment by 1
4+
starting from one.
5+
6+
If `n` is a non-integer value greater than zero, the function returns an
7+
array having `ceil(n)` elements.
8+
9+
If `n` is less than or equal to zero, the function returns an empty array.
10+
11+
Parameters
12+
----------
13+
n: number
14+
Number of elements.
15+
16+
Returns
17+
-------
18+
out: Array
19+
Linearly spaced numeric array.
20+
21+
Examples
22+
--------
23+
> var arr = {{alias}}( 6 )
24+
[ 1, 2, 3, 4, 5, 6 ]
25+
26+
See Also
27+
--------
28+

base/one-to/docs/types/index.d.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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+
// TypeScript Version: 4.1
20+
21+
/**
22+
* Generates a linearly spaced numeric array whose elements increment by 1 starting from one.
23+
*
24+
* @param n - number of elements
25+
* @returns linearly spaced numeric array
26+
*
27+
* @example
28+
* var arr = oneTo( 6 );
29+
* // returns [ 1, 2, 3, 4, 5, 6 ]
30+
*/
31+
declare function oneTo( n: number ): Array<number>;
32+
33+
34+
// EXPORTS //
35+
36+
export = oneTo;

base/one-to/docs/types/test.ts

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2023 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+
import oneTo = require( './index' );
20+
21+
22+
// TESTS //
23+
24+
// The function returns an array of numbers...
25+
{
26+
oneTo( 11 ); // $ExpectType number[]
27+
}
28+
29+
// The compiler throws an error if the function is not provided a number...
30+
{
31+
oneTo( true ); // $ExpectError
32+
oneTo( false ); // $ExpectError
33+
oneTo( '5' ); // $ExpectError
34+
oneTo( [] ); // $ExpectError
35+
oneTo( {} ); // $ExpectError
36+
oneTo( ( x: number ): number => x ); // $ExpectError
37+
}
38+
39+
// The compiler throws an error if the function is provided an unsupported number of arguments...
40+
{
41+
oneTo(); // $ExpectError
42+
oneTo( 3, 4 ); // $ExpectError
43+
oneTo( 3, 4, 1 ); // $ExpectError
44+
}

0 commit comments

Comments
 (0)