Skip to content

Commit b16c3f5

Browse files
committed
Auto-generated commit
1 parent 32f3823 commit b16c3f5

11 files changed

Lines changed: 2705 additions & 0 deletions

File tree

CHANGELOG.md

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

1111
### Features
1212

13+
- [`82f105c`](https://github.com/stdlib-js/stdlib/commit/82f105ccb1920ec6f48d0af692819a1da40d3b7f) - add `ndarray/broadcast-scalar-like` [(#11630)](https://github.com/stdlib-js/stdlib/pull/11630)
1314
- [`1615c51`](https://github.com/stdlib-js/stdlib/commit/1615c51bd03478de8adedf82e5718ea48ecba290) - add `ndarray/base/reinterpret-complex128` [(#11629)](https://github.com/stdlib-js/stdlib/pull/11629)
1415
- [`1ab30a1`](https://github.com/stdlib-js/stdlib/commit/1ab30a16866d523544f06017e56a70e68d9933cf) - add `rotl90` to namespace
1516
- [`9ef9c56`](https://github.com/stdlib-js/stdlib/commit/9ef9c56b8d3fccad2b75d4f4316f7a99fa5bc660) - add `ndarray/base/rotl90` [(#11633)](https://github.com/stdlib-js/stdlib/pull/11633)
@@ -866,6 +867,7 @@ A total of 49 issues were closed in this release:
866867

867868
<details>
868869

870+
- [`82f105c`](https://github.com/stdlib-js/stdlib/commit/82f105ccb1920ec6f48d0af692819a1da40d3b7f) - **feat:** add `ndarray/broadcast-scalar-like` [(#11630)](https://github.com/stdlib-js/stdlib/pull/11630) _(by Muhammad Haris, Athan Reines)_
869871
- [`b7f85c2`](https://github.com/stdlib-js/stdlib/commit/b7f85c29d4147a1c0194329881eb07ef695ddaee) - **fix:** use correct validation package _(by Athan Reines)_
870872
- [`1615c51`](https://github.com/stdlib-js/stdlib/commit/1615c51bd03478de8adedf82e5718ea48ecba290) - **feat:** add `ndarray/base/reinterpret-complex128` [(#11629)](https://github.com/stdlib-js/stdlib/pull/11629) _(by Muhammad Haris)_
871873
- [`59d0640`](https://github.com/stdlib-js/stdlib/commit/59d0640a16660401392d422f98261c2f9c8cb4be) - **docs:** propagate recent fixes to sibling packages [(#11671)](https://github.com/stdlib-js/stdlib/pull/11671) _(by Philipp Burckhardt)_

broadcast-scalar-like/README.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
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+
# broadcastScalarLike
22+
23+
> Broadcast a scalar value to an [ndarray][@stdlib/ndarray/ctor] having the same shape and [data-type][@stdlib/ndarray/dtypes] as a provided input [ndarray][@stdlib/ndarray/ctor].
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 broadcastScalarLike = require( '@stdlib/ndarray/broadcast-scalar-like' );
41+
```
42+
43+
#### broadcastScalarLike( x, value\[, options] )
44+
45+
Broadcasts a scalar value to an [ndarray][@stdlib/ndarray/ctor] having the same shape and [data-type][@stdlib/ndarray/dtypes] as a provided input [ndarray][@stdlib/ndarray/ctor].
46+
47+
```javascript
48+
var getDType = require( '@stdlib/ndarray/dtype' );
49+
var empty = require( '@stdlib/ndarray/empty' );
50+
51+
var x = empty( [ 2, 2 ], {
52+
'dtype': 'float32'
53+
});
54+
// returns <ndarray>
55+
56+
var y = broadcastScalarLike( x, 1.0 );
57+
// returns <ndarray>[ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]
58+
59+
var dt = String( getDType( y ) );
60+
// returns 'float32'
61+
```
62+
63+
The function accepts the following arguments:
64+
65+
- **x**: input [ndarray][@stdlib/ndarray/ctor].
66+
- **value**: scalar value.
67+
68+
The function accepts the following options:
69+
70+
- **dtype**: output array [data type][@stdlib/ndarray/dtypes]. By default, the output array has the same [data type][@stdlib/ndarray/dtypes] as the provided input ndarray.
71+
- **shape**: output array shape. By default, the output array has the same shape as the provided input ndarray.
72+
- **order**: array order (i.e., memory layout). Must be either `row-major` (C-style) or `column-major` (Fortran-style). By default, the output array has the same order as the provided input ndarray.
73+
- **readonly**: boolean indicating whether an array should be **read-only**. Default: `false`.
74+
75+
To explicitly specify the [data type][@stdlib/ndarray/dtypes] of the returned [ndarray][@stdlib/ndarray/ctor], provide a `dtype` option.
76+
77+
```javascript
78+
var getDType = require( '@stdlib/ndarray/dtype' );
79+
var zeros = require( '@stdlib/ndarray/zeros' );
80+
81+
var x = zeros( [ 2, 2 ] );
82+
// returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
83+
84+
var y = broadcastScalarLike( x, 1.0, {
85+
'dtype': 'float32'
86+
});
87+
// returns <ndarray>[ [ 1.0, 1.0 ], [ 1.0, 1.0 ] ]
88+
89+
var dt = String( getDType( y ) );
90+
// returns 'float32'
91+
```
92+
93+
To explicitly specify the shape of the returned [ndarray][@stdlib/ndarray/ctor], provide a `shape` option.
94+
95+
```javascript
96+
var zeros = require( '@stdlib/ndarray/zeros' );
97+
98+
var x = zeros( [ 2, 2 ] );
99+
// returns <ndarray>[ [ 0.0, 0.0 ], [ 0.0, 0.0 ] ]
100+
101+
var y = broadcastScalarLike( x, 1.0, {
102+
'shape': [ 3, 3 ]
103+
});
104+
// returns <ndarray>[ [ 1.0, 1.0, 1.0 ], [ 1.0, 1.0, 1.0 ], [ 1.0, 1.0, 1.0 ] ]
105+
```
106+
107+
</section>
108+
109+
<!-- /.usage -->
110+
111+
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
112+
113+
<section class="notes">
114+
115+
## Notes
116+
117+
- If `value` is a number and the resolved [data type][@stdlib/ndarray/dtypes] is a complex [data type][@stdlib/ndarray/dtypes], the function returns an [ndarray][@stdlib/ndarray/ctor] containing a complex number whose real component equals the provided scalar `value` and whose imaginary component is zero.
118+
- The function does not guard against precision loss when `value` is a number and the resolved [data type][@stdlib/ndarray/dtypes] is an integer [data type][@stdlib/ndarray/dtypes].
119+
120+
</section>
121+
122+
<!-- /.notes -->
123+
124+
<!-- Package usage examples. -->
125+
126+
<section class="examples">
127+
128+
## Examples
129+
130+
<!-- eslint no-undef: "error" -->
131+
132+
```javascript
133+
var dtypes = require( '@stdlib/ndarray/dtypes' );
134+
var empty = require( '@stdlib/ndarray/empty' );
135+
var broadcastScalarLike = require( '@stdlib/ndarray/broadcast-scalar-like' );
136+
137+
// Get a list of data types:
138+
var dt = dtypes( 'integer_and_generic' );
139+
140+
// Create an input array:
141+
var x = empty( [ 2, 2 ] );
142+
143+
// Generate broadcasted arrays...
144+
var y;
145+
var i;
146+
for ( i = 0; i < dt.length; i++ ) {
147+
y = broadcastScalarLike( x, i, {
148+
'dtype': dt[ i ]
149+
});
150+
console.log( y.get( 0, 1 ) );
151+
}
152+
```
153+
154+
</section>
155+
156+
<!-- /.examples -->
157+
158+
<!-- 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. -->
159+
160+
<section class="references">
161+
162+
</section>
163+
164+
<!-- /.references -->
165+
166+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
167+
168+
<section class="related">
169+
170+
</section>
171+
172+
<!-- /.related -->
173+
174+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
175+
176+
<section class="links">
177+
178+
[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/ndarray/tree/main/ctor
179+
180+
[@stdlib/ndarray/dtypes]: https://github.com/stdlib-js/ndarray/tree/main/dtypes
181+
182+
<!-- <related-links> -->
183+
184+
<!-- </related-links> -->
185+
186+
</section>
187+
188+
<!-- /.links -->

0 commit comments

Comments
 (0)