Skip to content
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

ZScoreTransform and UnitRangeTransform do not support CuArray #619

Closed
sdewaele opened this issue Nov 26, 2020 · 1 comment
Closed

ZScoreTransform and UnitRangeTransform do not support CuArray #619

sdewaele opened this issue Nov 26, 2020 · 1 comment

Comments

@sdewaele
Copy link
Contributor

ZScoreTransform and UnitRangeTransform do not support CuArrrays. For example, with StatsBase v0.33.2:

using CUDA
using StatsBase

A = 5randn(2,4).+2
t = fit(ZScoreTransform,A;dims=2)

fails with

┌ Warning: Performing scalar operations on GPU arrays: This is very slow, consider disallowing these operations with `allowscalar(false)`
└ @ GPUArrays ~/.julia/packages/GPUArrays/jhRU7/src/host/indexing.jl:43
ERROR: MethodError: no method matching ZScoreTransform(::Int64, ::Int64, ::CuArray{Float32,1}, ::CuArray{Float32,1})
Closest candidates are:
  ZScoreTransform(::Int64, ::Int64, ::Array{T,1}, ::Array{T,1}) where T at /home/student/.julia/packages/StatsBase/EA8Mh/src/transformations.jl:58
Stacktrace:
 [1] fit(::Type{ZScoreTransform}, ::CuArray{Float32,2}; dims::Int64, center::Bool, scale::Bool) at /home/student/.julia/packages/StatsBase/EA8Mh/src/transformations.jl:127
 [2] top-level scope at REPL[4]:1

To fix this, the ZScoreTransform would have to allow AbstractArrays. Also, specifically for CuArrays, to prevent bad performance due to indexing, mean_and_std needs to be updated. See this gist for a possible implementation. I can put together a PR if desired. One question with regards to this change: Is it okay to replace stdm by Statistics.std using the mean option? This will facilitate solving this issue.

See also JuliaGPU/CUDA.jl#426.

@sdewaele
Copy link
Contributor Author

Fully resolved by PR #622 for ZScoreTransform. UnitRangeTransform has been generalized so it can handle CuArray.

Implement _compute_extrema to make UnitRangeTransform fully functional for CuArray. Note that this implementation is not included in StatsBase because it is not desirable to take on a dependency on CUDA.jl for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant