crystal-data / num.cr

Scientific computing in pure Crystal
MIT License
151 stars 12 forks source link

Add unary operator to negate tensor #79

Closed nogginly closed 1 year ago

nogginly commented 1 year ago

Fixes #80

@christopherzimmerman, here's a PR to add unary - (negation) operator support for CPU and OpenCL tensors. I've included test cases as well.

While -a == (0-a) and in fact the #negate method for OpenCL backend does just that, I think it's worth having the unary operator available. When I ran into this, it took me a little while to grok the compiler error and realise what was happening.

christopherzimmerman commented 1 year ago

Thanks for the PR @nogginly, agree this is a great feature to have, not sure why CI isn't working but this looks good to merge!

nogginly commented 1 year ago

@christopherzimmerman, I added both CPU and OCL test for unary operator; is it possible that OpenCL isn't available in the CI runner?

christopherzimmerman commented 1 year ago

@nogginly ah, I missed that, yes. I usually add compiler flags for tests that require additional libraries, and then don't run them as part of the standard CI, like this: {% if flag?(:opencl) %}

nogginly commented 1 year ago

Got it. Let me fix that and raise a PR.