-
Notifications
You must be signed in to change notification settings - Fork 0
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
Type Instability Using sum()
as the Kernel Function
#11
Comments
right, type inference through
Other suggestions welcome. |
I think if I use the in place version it won't have such issue. |
By the way, the annotation you suggested So if we have |
Not in your output container type, but the executed code might still by type-unstable before implicitly converting to the container output.
No, the type annotation on your window function helps the compiler to generate fast code, while converting the output with |
I was under the impression function types only means the last step of the function will be See the comment by Steven G. Johnson: |
It is exactly as you say: return-type declarations are a Also in this case, the type annotation is not on the return type but on the last value computed before returning. See here: julia> convert(Float64, 1)
1.0
julia> (x -> x::Float64)(1)
ERROR: TypeError: in typeassert, expected Float64, got a value of type Int64 Nevertheless, a return type type annotation is sufficient as well in your example from above: function g(mW)::Float64
sum(mW) / kernelNumPx
end
mK = Kernel{(-kernelRadius:kernelRadius, -kernelRadius:kernelRadius)}(g);
typeof(map(mK, mI)) # Matrix{Float64} (alias for Array{Float64, 2}) |
So in the case above your way of doing That's great! I just love this package. |
yes, it is called "type assertion" and is a standard Julia feature. |
In the following code there is type instability of the
map()
:The output is given by:
The text was updated successfully, but these errors were encountered: