Skip to content

Commit

Permalink
allow always joining a scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Nov 20, 2023
1 parent cd9e291 commit 38118ca
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 5 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

Uiua is not yet stable.

<!-- This version is not yet released.
If you are reading this on the website, then these changes are live here. -->
## 0.4.0 - 2023-11-??
This version is not yet released.
If you are reading this on the website, then these changes are live here.
### Language
- [`join` ``](https://uiua.org/docs/join) now always works with a scalar regardless of the shape of the other array

## 0.3.0 - 2023-11-19
### Language
Expand Down
8 changes: 8 additions & 0 deletions src/algorithm/dyadic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ impl<T: ArrayValue> Array<T> {
self.fill_to_shape(row_shape, fill.clone());
other.fill_to_shape(&target_shape, fill);
target_shape
} else if self.rank() == 0 {
let val = self.data.into_iter().next().unwrap();
self.data = cowslice![val; other.shape().iter().skip(1).product()];
other.shape
} else {
if other.rank() - self.rank() > 1 {
return Err(C::fill_error(ctx.error(format!(
Expand Down Expand Up @@ -440,6 +444,10 @@ impl<T: ArrayValue> Array<T> {
self.fill_to_shape(&target_shape, fill.clone());
other.fill_to_shape(row_shape, fill);
target_shape
} else if other.rank() == 0 {
let val = other.data.into_iter().next().unwrap();
other.data = cowslice![val; self.shape().iter().skip(1).product()];
take(&mut self.shape)
} else {
if self.rank() <= other.rank() || self.rank() - other.rank() > 1 {
return Err(C::fill_error(ctx.error(format!(
Expand Down
6 changes: 6 additions & 0 deletions tests/units.ua
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,9 @@ ParseOrZero ← ⍣parse⋅⋅0
⍤⊃⋅∘≍ □↯1_¯1_4⇡24 ⍜(☇1)□ ↯2_3_4⇡24
⍤⊃⋅∘≍ ↯2_3≡□↯¯1_4⇡24 ⍜(☇1)≡□ ↯2_3_4⇡24
⍤⊃⋅∘≍ ≡□↯2_3_4⇡24 ⍜(☇2)≡□ ↯2_3_4⇡24

⍤⊃⋅∘≍ [3 5] ⊂ 3 5
⍤⊃⋅∘≍ [1 2 3 4] ⊂ 1 2_3_4
⍤⊃⋅∘≍ [1 2 3 4] ⊂ 1_2_3 4
⍤⊃⋅∘≍ [0_0_0 0_1_2 3_4_5] ⊂ 0 ↯2_3⇡6
⍤⊃⋅∘≍ [0_1_2 3_4_5 0_0_0] ⊂:0 ↯2_3⇡6

0 comments on commit 38118ca

Please sign in to comment.