-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add asymmetric operands to pointwise binary ops #290
Add asymmetric operands to pointwise binary ops #290
Conversation
Update functions in binops.rs to allow using different types for left-hand side and right-hand side operators. This is important when adding, multiplying, subtracting... matrices and vectors of different types.
Move from requiring AddAssign to just Add, so that we can drop the requirement for Clone.
Change from SubAssign to Sub as a bound for matrix subtraction.
0f33800
to
add48d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, and fits well in with the other generalisations made in this crate since the last release. It is not ideal to break type inference for existing code, although this is a minor cost for this additional functionality. We have already accumulated some breaking changes, so this is OK.
Could you add a couple of tests illuminating the added functionality? A couple of newtypes wrapping e.g. i16 + i32 = i64
would be nice.
Done. Please note that the current incarnation only implements vector addition and subtraction. The other operations, and extending to also cover matrices, can be added if there is interest. I didn't need it right away for my own project, so I held off for now. |
let (oval, lr_elems) = items; | ||
let binop_val = match lr_elems { | ||
Left((_, val)) => binop(val, &N::zero()), | ||
Right((_, val)) => binop(&N::zero(), val), | ||
Both((_, lval, rval)) => binop(lval, rval), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted on this weird iteration
Thanks for your great work on this @tchernobog! |
Alters the existing pointwise addition, subtraction, and multiplication binary operators so that they allow for different left-hand and right-hand side operands.
Note that in some cases this can lead to minor backwards incompatibilities due to the need to specify the type of one operand as it cannot be inferred automatically (e.g. when using an "eye" matrix). Please consider bumping the minor version number if merging.