Skip to content

Commit

Permalink
Merge pull request #117 from aya-lang/fix/length-1-numberlist-vectorize
Browse files Browse the repository at this point in the history
Broadcasting rules are properly applied to length 1 `NumberList`s
  • Loading branch information
nick-paul authored Nov 28, 2024
2 parents ed94e3d + f1745ba commit 6734779
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/aya/util/VectorizedFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,18 @@ private static List vectorizeObjList(ExecutionContext context, Operator op, Obj
//

private static List vectorizeListList(ExecutionContext context, Operator op, List a, List b, NumberListOp nlop) {
if (a.isa(NUMBERLIST) && b.isa(NUMBERLIST) && a.length() == b.length()) {
return new List(nlop.ll(asNumberList(a), asNumberList(b)));
if (a.isa(NUMBERLIST) && b.isa(NUMBERLIST)) {
final int a_len = a.length();
final int b_len = b.length();
if (a_len == b_len) {
return new List(nlop.ll(asNumberList(a), asNumberList(b)));
} else if (a_len == 1) {
return new List(nlop.nl(asNumberList(a).get(0), asNumberList(b)));
} else if (b_len == 1) {
return new List(nlop.ln(asNumberList(a), asNumberList(b).get(0)));
} else {
return vectorizeListList(context, op, a, b);
}
} else {
return vectorizeListList(context, op, a, b);
}
Expand Down

0 comments on commit 6734779

Please sign in to comment.