-
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
Extend basic operations #174
Extend basic operations #174
Conversation
This is predicated on a new unary-operator function that replicates the binary-operator, but with a single argument.
... and (NUMBER, TENSOR) arguments This simplifes the workload if, e.g., adding a single number to a tensor. No need to create a tensor all of a single value just to apply the operation.
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.
lgtm, but one small request as commented.
a couple small tests are always appreciated too.
src/high-level/abstract-tensor.lisp
Outdated
@@ -245,6 +279,51 @@ If TARGET is not specified then a new tensor is created with the same element ty | |||
;; choice, like integers. | |||
(binary-operator #'expt source1 source2 target))) | |||
|
|||
(define-backend-function .max (source1 source2 &optional target) |
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.
Can you use DEFINE-EXTENSIBLE-FUNCTION without specialization here so that one has the option to micro-optimize on tensor type in the future?
Tests are for: .+ .- .* ./ .max .min .exp .log
Addressed both comments @stylewarning I'd read the Developer How-To umpteen times and missed that DEFINE-EXTENSIBLE-FUNCTION could be used without specialization. 🤦 |
Great, thanks! |
Extend basic basic operations (i.e. elementwise ops) in three ways:
number
instead of anabstract-tensor
type as one of the arguments(.+ A 10)
behaves as it reads - i.e. add 10 to each element ofA
. An alternative would have been to create a tensor the same type/shape asA
and set all elements to 10...and then...add toA
.max
and.min
(.max 0.0 A)
.exp
and.log
(natural log)unary-operator
function, which will look suspiciously like the existingbinary-operator
, but with only one argumentAdditional thoughts
.max
and.min
functions suffer from the existing issue that if the type of the arguments differ then we can get a TYPE-ERROR from the SETF. See issue #173. So rather than(.max A 0)
, it's better to be explicit and write(.max A 0.0)
.