-
Notifications
You must be signed in to change notification settings - Fork 21
Improve operators #119
Improve operators #119
Conversation
null_safe_op(f::Any, ::Type)::Bool | ||
null_safe_op(f::Any, ::Type, ::Type)::Bool | ||
|
||
Returns whether an operation `f` can safely be applied to any value of the passed type(s). |
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.
Minor nit: maybe we should distinguish between value and bit pattern? Consider the following type:
immutable OneType
x::Int
function OneType()
new(1)
end
end
The only legal value of this type is 1
, but our uninitialized constructors will generate bit patterns that are not legal values.
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.
Maybe we should mention "bit pattern" below instead of "domain"? I think "value" is good as a first approximation to give the idea of the requirements.
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.
OK, I've updated the docstring.
Current coverage is 81.61%@@ master #119 diff @@
==========================================
Files 13 13
Lines 729 729
Methods 0 0
Messages 0 0
Branches 0 0
==========================================
- Hits 598 595 -3
- Misses 131 134 +3
Partials 0 0
|
92e3b27
to
bb9ba46
Compare
Introduce a new null_safe_op() function which is used instead of isbits() to decide whether to take the fast path (without a branch) or the slow path in lifted operators. This is more correct (and thus safer), and allows supporting operations on any type. Also add an extensive set of tests for both paths. On Julia 0.4, operators for which no functor exist cannot be identified by null_safe_op(): for these, fall back to the slow path on that version. This PR introduces cbrt as a new supported operation since it has a special operator ∛. It also keeps abs(), abs2(), scalarmin() and scalarmax(), which should probably be deprecated once we have a more general solution for lifting.
Nullable{Union{}} is always null so we can return null immediately if one of the arguments is of that type. For unary operators, return Nullabl(). For binary operators, return Nullable{S}() with S the element type of the other argument, which carries more information.
With support merged in Julia, tests now pass. Will tag a new release. |
Introduce a new
null_safe_op()
function which is used instead ofisbits()
to decide whether to take the fast path (without a branch)or the slow path in lifted operators. This is more correct (and thus
safer), and allows supporting operations on any type. Also add an
extensive set of tests for both paths.
On Julia 0.4, operators for which no functor exist cannot be identified
by
null_safe_op()
: for these, fall back to the slow path on that version.This PR introduces
cbrt
as a new supported operation since it has a specialoperator
∛
. It also keepsabs()
,abs2()
,scalarmin()
andscalarmax()
, whichshould probably be deprecated once we have a more general solution for
lifting.
Tests pass on Julia 0.4, but on 0.5 they need JuliaLang/julia#16995 (unrelated tests already fail too).
Fixes #74, #111, #116.