You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.
Use case - collect both sum(x) and sum(abs(x)) in one pass
a = randn(3, 3)
reduce((x0,x)->(x0[1]+x, x0[2]+abs(x)), (0.,0.), a)
works, but:
a = cu(a)
reduce((x0,x)->(x0[1]+x, x0[2]+abs(x)), (0.,0.), a)
ERROR: MethodError: Cannot `convert` an object of type Tuple{Float64,Float64} to an object of
type Float64
This may have arisen from a call to the constructor Float64(...),
since type constructors fall back to convert methods.
Stacktrace:
[1] reduce(::Function, ::Tuple{Float64,Float64}, ::CuArray{Float64,2}) at /.julia/v0
.6/CuArrays/src/reduction.jl:87
Probably harder, but would be nice to make it work along some dimension, for example to collect sum(x, 1) and sum(abs(x), 1) in one pass.
The text was updated successfully, but these errors were encountered:
This happens because the reduction code allocates scratch space which it assumes to have the same output type as the input. It also expectsv0 to have the same type. There's no particular need for this, so if you can tweak those type hints it should all work.
(You could use Core.Inference.return_type to work out the return type)
Yeah, but that's a bug, JuliaLang/julia#31427; reduce just isn't written in a generic way when it clearly should support this case. The particular case above is also pretty easy to fix.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Use case - collect both
sum(x)
andsum(abs(x))
in one passworks, but:
Probably harder, but would be nice to make it work along some dimension, for example to collect
sum(x, 1)
andsum(abs(x), 1)
in one pass.The text was updated successfully, but these errors were encountered: