<!--

@license Apache-2.0

Copyright (c) 2026 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.

-->

# oneTo

> Return a new [ndarray][@stdlib/ndarray/ctor] filled with linearly spaced numeric elements which increment by `1` starting from one along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.

<section class="usage">

## Usage

```javascript
var oneTo = require( '@stdlib/blas/ext/one-to' );
```

#### oneTo( shape\[, options] )

Returns a new [ndarray][@stdlib/ndarray/ctor] filled with linearly spaced numeric elements which increment by `1` starting from one along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.

```javascript
var x = oneTo( [ 2, 3 ] );
// returns <ndarray>[ [ 1.0, 2.0, 3.0 ], [ 1.0, 2.0, 3.0 ] ]
```

The function has the following parameters:

-   **shape**: array shape.
-   **options**: function options (_optional_).

The function accepts the following options:

-   **dims**: list of dimensions over which to perform operation. If not provided, the function generates values along the last dimension. Default: `[-1]`.
-   **dtype**: output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes]. Must be a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. Default: `'float64'`.
-   **order**: specifies whether an [ndarray][@stdlib/ndarray/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). Default: `'row-major'`.
-   **mode**: specifies how to handle indices which exceed array dimensions (see [`ndarray`][@stdlib/ndarray/ctor]). Default: `'throw'`.
-   **submode**: a mode array which specifies for each dimension how to handle subscripts which exceed array dimensions  (see [`ndarray`][@stdlib/ndarray/ctor]). If provided fewer modes than dimensions, the function recycles modes using modulo arithmetic. Default: `[ options.mode ]`.

By default, the function generates values along the last dimension of an output [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option.

```javascript
var x = oneTo( [ 2, 2 ], {
    'dims': [ 0, 1 ]
});
// returns <ndarray>[ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ]
```

To specify the output [ndarray][@stdlib/ndarray/ctor] [data type][@stdlib/ndarray/dtypes], provide a `dtype` option.

```javascript
var x = oneTo( [ 3 ], {
    'dtype': 'float32'
});
// returns <ndarray>[ 1.0, 2.0, 3.0 ]
```

#### oneTo.assign( x\[, options] )

Fills an [ndarray][@stdlib/ndarray/ctor] with linearly spaced numeric elements which increment by `1` starting from one along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.

```javascript
var zeros = require( '@stdlib/ndarray/zeros' );

var x = zeros( [ 2, 3 ] );
// returns <ndarray>[ [ 0.0, 0.0, 0.0 ], [ 0.0, 0.0, 0.0 ] ]

var out = oneTo.assign( x );
// returns <ndarray>[ [ 1.0, 2.0, 3.0 ], [ 1.0, 2.0, 3.0 ] ]

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

The function has the following parameters:

-   **x**: input [ndarray][@stdlib/ndarray/ctor]. Must have a numeric or "generic" [data type][@stdlib/ndarray/dtypes].
-   **options**: function options (_optional_).

The function accepts the following options:

-   **dims**: list of dimensions over which to perform operation. If not provided, the function generates values along the last dimension. Default: `[-1]`.

</section>

<!-- /.usage -->

<section class="notes">

## Notes

-   The function iterates over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before performing the operation.

</section>

<!-- /.notes -->

<section class="examples">

## Examples

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

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

// Create a new ndarray:
var x = oneTo( [ 5, 5 ], {
    'dtype': 'generic'
});
console.log( ndarray2array( x ) );

// Generate values over a specific dimension:
x = oneTo( [ 5, 5 ], {
    'dtype': 'generic',
    'dims': [ 0 ]
});
console.log( ndarray2array( x ) );

// Generate values over all dimensions:
x = oneTo( [ 5, 5 ], {
    'dtype': 'generic',
    'dims': [ 0, 1 ]
});
console.log( ndarray2array( x ) );
```

</section>

<!-- /.examples -->

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

[@stdlib/ndarray/ctor]: https://www.npmjs.com/package/@stdlib/ndarray-ctor

[@stdlib/ndarray/dtypes]: https://www.npmjs.com/package/@stdlib/ndarray-dtypes

</section>

<!-- /.links -->
