Skip to content

Commit 5254220

Browse files
committed
Auto-generated commit
1 parent d28f1af commit 5254220

24 files changed

+3791
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
### Features
1212

13+
- [`475f496`](https://github.com/stdlib-js/stdlib/commit/475f4962d86ed3c562800dce759c958a52e6a15e) - add `ones` to namespace
14+
- [`ded14cf`](https://github.com/stdlib-js/stdlib/commit/ded14cff1642c79ac122cc05b65e911cc24ec2ac) - add `ndarray/ones`
1315
- [`e00d73a`](https://github.com/stdlib-js/stdlib/commit/e00d73a3cb8c5355a46771ed5630d178e25ec0f4) - add `onesLike` to namespace
1416
- [`d200536`](https://github.com/stdlib-js/stdlib/commit/d200536a79672d3a31022f894a63acdf08b79159) - add `ndarray/base/ones-like`
1517
- [`baef022`](https://github.com/stdlib-js/stdlib/commit/baef0223f86db141fa6a1dabc15ec6c5fa2f0f59) - update `ndarray/base` TypeScript declarations [(#11131)](https://github.com/stdlib-js/stdlib/pull/11131)
@@ -807,6 +809,8 @@ A total of 44 issues were closed in this release:
807809

808810
<details>
809811

812+
- [`475f496`](https://github.com/stdlib-js/stdlib/commit/475f4962d86ed3c562800dce759c958a52e6a15e) - **feat:** add `ones` to namespace _(by Athan Reines)_
813+
- [`ded14cf`](https://github.com/stdlib-js/stdlib/commit/ded14cff1642c79ac122cc05b65e911cc24ec2ac) - **feat:** add `ndarray/ones` _(by Athan Reines)_
810814
- [`bbd8f0e`](https://github.com/stdlib-js/stdlib/commit/bbd8f0eec8d6d52201d7706a349fdb9cac737d9c) - **refactor:** avoid unnecessary offset calculation _(by Athan Reines)_
811815
- [`8d3124d`](https://github.com/stdlib-js/stdlib/commit/8d3124d525abb511f0257649bfc4e0bf6c0ce87b) - **docs:** add comment _(by Athan Reines)_
812816
- [`372443f`](https://github.com/stdlib-js/stdlib/commit/372443fe38ff5fac2c1a5214593e4aecbf7e3096) - **refactor:** more strictly enforce dtype and shape constraints and handle dtype instances _(by Athan Reines)_

lib/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,15 @@ setReadOnly( ns, 'numelDimension', require( './../numel-dimension' ) );
594594
*/
595595
setReadOnly( ns, 'offset', require( './../offset' ) );
596596

597+
/**
598+
* @name ones
599+
* @memberof ns
600+
* @readonly
601+
* @type {Function}
602+
* @see {@link module:@stdlib/ndarray/ones}
603+
*/
604+
setReadOnly( ns, 'ones', require( './../ones' ) );
605+
597606
/**
598607
* @name order
599608
* @memberof ns

ones/README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2026 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+
# ones
22+
23+
> Create a ones-filled [ndarray][@stdlib/ndarray/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes].
24+
25+
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
26+
27+
<section class="intro">
28+
29+
</section>
30+
31+
<!-- /.intro -->
32+
33+
<!-- Package usage documentation. -->
34+
35+
<section class="usage">
36+
37+
## Usage
38+
39+
```javascript
40+
var ones = require( '@stdlib/ndarray/ones' );
41+
```
42+
43+
#### ones( shape\[, options] )
44+
45+
Creates a ones-filled [ndarray][@stdlib/ndarray/ctor] having a specified shape and [data type][@stdlib/ndarray/dtypes].
46+
47+
```javascript
48+
var getShape = require( '@stdlib/ndarray/shape' );
49+
var getDType = require( '@stdlib/ndarray/dtype' );
50+
51+
var arr = ones( [ 2, 2 ] );
52+
// returns <ndarray>[ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]
53+
54+
var sh = getShape( arr );
55+
// returns [ 2, 2 ]
56+
57+
var dt = String( getDType( arr ) );
58+
// returns 'float64'
59+
```
60+
61+
The specified output [ndarray][@stdlib/ndarray/ctor] shape may be either an array-like object or an integer value.
62+
63+
```javascript
64+
var getShape = require( '@stdlib/ndarray/shape' );
65+
var getDType = require( '@stdlib/ndarray/dtype' );
66+
67+
var arr = ones( 2 );
68+
// returns <ndarray>[ 1.0, 1.0 ]
69+
70+
var sh = getShape( arr );
71+
// returns [ 2 ]
72+
73+
var dt = String( getDType( arr ) );
74+
// returns 'float64'
75+
```
76+
77+
The function accepts the following options:
78+
79+
- **dtype**: underlying [data type][@stdlib/ndarray/dtypes]. Must be a numeric or "generic" [data type][@stdlib/ndarray/dtypes]. Default: `'float64'`.
80+
- **order**: specifies whether an [ndarray][@stdlib/ndarray/ctor] is `'row-major'` (C-style) or `'column-major'` (Fortran-style). Default: `'row-major'`.
81+
- **mode**: specifies how to handle indices which exceed array dimensions (see [ndarray][@stdlib/ndarray/ctor]). Default: `'throw'`.
82+
- **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 constructor recycles modes using modulo arithmetic. Default: `[ options.mode ]`.
83+
- **readonly**: boolean indicating whether an array should be **read-only**. Default: `false`.
84+
85+
By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a [`float64`][@stdlib/ndarray/dtypes] data type. To specify an alternative [data type][@stdlib/ndarray/dtypes], provide a `dtype` option.
86+
87+
```javascript
88+
var getShape = require( '@stdlib/ndarray/shape' );
89+
var getDType = require( '@stdlib/ndarray/dtype' );
90+
91+
var arr = ones( [ 2, 2 ], {
92+
'dtype': 'float32'
93+
});
94+
// returns <ndarray>[ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]
95+
96+
var sh = getShape( arr );
97+
// returns [ 2, 2 ]
98+
99+
var dt = String( getDType( arr ) );
100+
// returns 'float32'
101+
```
102+
103+
</section>
104+
105+
<!-- /.usage -->
106+
107+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
108+
109+
<section class="notes">
110+
111+
</section>
112+
113+
<!-- /.notes -->
114+
115+
<!-- Package usage examples. -->
116+
117+
<section class="examples">
118+
119+
## Examples
120+
121+
<!-- eslint no-undef: "error" -->
122+
123+
```javascript
124+
var dtypes = require( '@stdlib/ndarray/dtypes' );
125+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
126+
var ones = require( '@stdlib/ndarray/ones' );
127+
128+
// Get a list of data types:
129+
var dt = dtypes( 'integer_and_generic' );
130+
131+
// Generate ones-filled arrays...
132+
var arr;
133+
var i;
134+
for ( i = 0; i < dt.length; i++ ) {
135+
arr = ones( [ 2, 2 ], {
136+
'dtype': dt[ i ]
137+
});
138+
console.log( ndarray2array( arr ) );
139+
}
140+
```
141+
142+
</section>
143+
144+
<!-- /.examples -->
145+
146+
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
147+
148+
<section class="references">
149+
150+
</section>
151+
152+
<!-- /.references -->
153+
154+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
155+
156+
<section class="related">
157+
158+
</section>
159+
160+
<!-- /.related -->
161+
162+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
163+
164+
<section class="links">
165+
166+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
167+
168+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
169+
170+
</section>
171+
172+
<!-- /.links -->

0 commit comments

Comments
 (0)