diff options
| -rw-r--r-- | alv-lib/math.moon | 4 | ||||
| -rw-r--r-- | spec/lib/math_spec.moon | 13 |
2 files changed, 15 insertions, 2 deletions
diff --git a/alv-lib/math.moon b/alv-lib/math.moon index 2cf6e26..eaab36d 100644 --- a/alv-lib/math.moon +++ b/alv-lib/math.moon @@ -152,7 +152,7 @@ add = Constant.meta summary: "Add values." examples: { '(+ a b [c…])', '(add a b [c…])' } description: "Sum all arguments." - value: func_op (reduce_fn (a, b) -> a + b), num\rep 2, nil + value: func_op (reduce_fn (a, b) -> a + b), num*0 sub = Constant.meta meta: @@ -182,7 +182,7 @@ For every pair of arguments, from left to right: - If both arguments are matrices, multiply them using matrix multiplication. - `(* num[L][M] num[M][N]) → num[M][N]`" value: class extends PureOp - pattern: any!\rep 2, nil + pattern: any!*0 type: (inputs) => types = [input\type! for input in *inputs] diff --git a/spec/lib/math_spec.moon b/spec/lib/math_spec.moon index 40c7abd..038fc5a 100644 --- a/spec/lib/math_spec.moon +++ b/spec/lib/math_spec.moon @@ -153,6 +153,19 @@ describe "math", -> (- [[1 2] [1 2]] [1 2])' + describe "add, sub, mul", -> + it "handle single arguments", -> + COPILOT\eval_once ' + (expect= [3 4 5] + (+ [3 4 5])) + + (expect= [0 1 -2] + (- [0 -1 2])) + + (expect= [1 2 3] + (* [1 2 3])) + ' + describe "mul", -> it "handles scalars and matrices", -> with COPILOT\eval_once ' |
