Skip to content

Commit

Permalink
fix a bug in fixed pervasives
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Jun 18, 2024
1 parent 8592f89 commit faeb109
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions site/src/tutorial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,8 +1019,8 @@ fn TutorialAdvancedStack() -> impl IntoView {
<Editor example="+dggdp 1 2 3 4 5"/>
<p>"In general, planet notation as complex as the mathematical function example above should only be used when it is necessary. For examples like that with 4+ values, it is. However, when working with fewer values, you can get very far with just "<Prim prim=Dup/>" and "<Prim prim=Flip/>". Maybe sprinkle some "<Prim prim=Over/>"s and "<Prim prim=Dip/>"s in there too."</p>

<Hd id="on"><Prim prim=On/></Hd>
<p>"As you write more Uiua code, you'll find that there is a pattern you'll encounter over and over again. It involves calling a function, then calling another function that re-uses an argument to the first function."</p>
<Hd id="on-and-by"><Prim prim=On/>" and "<Prim prim=By/></Hd>
<p>"As you write more Uiua code, you'll find that there is a kind of pattern you'll encounter over and over again. It involves calling a function, then calling another function that re-uses an argument to the first function."</p>
<p>"One simple example is getting "<code>"n"</code>" numbers between "<code>"0"</code>" and "<code>"1"</code>". One way you may think to solve this is with "<Prim prim=Dup/>" and "<Prim prim=Flip/>"."</p>
<Editor example="÷:⇡. 5"/> // Should fail
<p>"This solution works, but as the style diagnostic suggests, it is not quite idiomatic."</p>
Expand Down
10 changes: 5 additions & 5 deletions src/algorithm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,10 @@ where
return Ok(());
}
if expand_fixed && arr.row_count() == 1 && ctx.scalar_fill::<T>().is_err() {
let fixes = (arr.shape.iter())
.take_while(|&&dim| dim == 1)
.count()
.min(arr.shape.len());
let mut fixes = (arr.shape.iter()).take_while(|&&dim| dim == 1).count();
if fixes == arr.rank() {
fixes = (fixes - 1).max(1)
}
let same_under_fixes = (target.iter().skip(fixes))
.zip(arr.shape[fixes..].iter())
.all(|(b, a)| b == a);
Expand Down Expand Up @@ -402,7 +402,7 @@ where
}
let a_shape = a.shape().clone();
let b_shape = b.shape().clone();
let a_err = fill_array_shape(a, b.shape(), true, ctx).err();
let a_err = fill_array_shape(a, &b_shape, true, ctx).err();
let b_err = fill_array_shape(b, &a_shape, true, ctx).err();
if shape_prefixes_match(&a.shape, &b.shape) {
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/pervade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ where
// A is fixed
if a.row_count() == 1 && b.row_count() != 1 {
let fix_count = a.shape.iter().take_while(|&&d| d == 1).count();
if b.rank() > fix_count {
if b.rank() > fix_count && b.rank() >= a.rank() {
if (a.shape().iter())
.zip(b.shape())
.skip(fix_count)
Expand Down Expand Up @@ -148,7 +148,7 @@ where
// B is fixed
if a.row_count() != 1 && b.row_count() == 1 {
let fix_count = b.shape.iter().take_while(|&&d| d == 1).count();
if a.rank() > fix_count {
if a.rank() > fix_count && a.rank() >= b.rank() {
if (a.shape().iter())
.zip(b.shape())
.skip(fix_count)
Expand Down
16 changes: 8 additions & 8 deletions tests/units.ua
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
⍤⟜≍: ↯2_0_2e ×2↯2_0_2e

# Fixed pervasive math
+ ¤100_200 [[1_2 3_4] [5_6 7_8] [9_10 11_12]]
⍤⟜≍: [[101_102 203_204] [105_106 207_208] [109_110 211_212]]
+ ¤¤100_200 [[1_2 3_4] [5_6 7_8] [9_10 11_12]]
⍤⟜≍: [[101_202 103_204] [105_206 107_208] [109_210 111_212]]
⍤⟜≍: [11_12_13 24_25_26] + 10_20 [1_2_3 4_5_6]
⍤⟜≍: [11_22_33 14_25_36] + ¤10_20_30 [1_2_3 4_5_6]
⍤⟜≍: [3_2_1 4_3_2 5_4_3] - ¤[1 2 3] [4 5 6]
⍤⟜≍: ⊃≡++ ¤100_200 [[1_2 3_4] [5_6 7_8] [9_10 11_12]]
⍤⟜≍: ⊃≡≡++ ¤¤100_200 [[1_2 3_4] [5_6 7_8] [9_10 11_12]]
⍤⟜≍: ⊃≡++ 10_20 [1_2_3 4_5_6]
⍤⟜≍: ⊃≡++ ¤10_20_30 [1_2_3 4_5_6]
⍤⟜≍: ⊃≡-- ¤[1 2 3] [4 5 6]
⍤⟜≍: 0_3 △ +¤ ↯3 0 ↯0_3 0
⍤⟜≍: 1_3 △ +¤ ↯3 0 ↯1_3 0
⍤⟜≍: ⇡10 + ¤¤0 ⇡10
⍤⟜≍: ⊃≡≡++ ¤¤0 ⇡10
⍤⟜≍: ⊃≡++ [0_1_2 3_4_5] ¤ [0_3_6 1_4_7 2_5_8]
⍤⟜≍: ⊃≡++ ¤ [0_1_2 3_4_5 6_7_8] [0_3_6 1_4_7 2_5_8]
⍤⟜≍: [11_12_13 21_22_23 31_32_33 41_42_43] + ¤[1 2 3] [10 20 30 40]
⍤⟜≍: [11_21_31_41 12_22_32_42 13_23_33_43] + ⊙¤[1 2 3] [10 20 30 40]
⍤⟜≍: [11_22_33 41_52_63] + ¤[1 2 3] [10_20_30 40_50_60]
Expand Down

0 comments on commit faeb109

Please sign in to comment.