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

preprocess_mean throws TypeError when handling Integer types #112

Closed
Heladio-ac opened this issue Dec 30, 2019 · 1 comment
Closed

preprocess_mean throws TypeError when handling Integer types #112

Heladio-ac opened this issue Dec 30, 2019 · 1 comment

Comments

@Heladio-ac
Copy link

I found this error while working with integer data, it seems to occur with every type of integer.

using MultivariateStats

int_matrix = rand(Int, (2, 2))
fit(PCA, int_matrix)

Error:

ERROR: TypeError: in typeassert, expected Array{Int8,1}, got Array{Float64,1}
Stacktrace:
 [1] preprocess_mean(::Array{Int8,2}, ::Nothing) at /home/heladioac/.julia/packages/MultivariateStats/BYMwD/src/common.jl:25
 [2] #fit#10(::Symbol, ::Int64, ::Float64, ::Nothing, ::Function, ::Type{PCA}, ::Array{Int8,2}) at /home/heladioac/.julia/packages/MultivariateStats/BYMwD/src/pca.jl:148
 [3] fit(::Type{PCA}, ::Array{Int8,2}) at /home/heladioac/.julia/packages/MultivariateStats/BYMwD/src/pca.jl:138
 [4] top-level scope at none:0

The problem seems to come specifically from preprocess_mean trying to return a Vector{Int} when X contains integers, while the expression vec(mean(X, dims=2)) always returns an array of type Float64 in my computer.

preprocess_mean(X::AbstractMatrix{T}, m) where T<:Real =
    (m == nothing ? vec(mean(X, dims=2)) : m == 0 ? T[] :  m)::Vector{T}
@nalimilan
Copy link
Member

Can you try removing ::Vector{T} and see whether it works? Replacing == nothing with === nothing should allow the compiler to infer the type correctly without this.

wildart added a commit to wildart/MultivariateStats.jl that referenced this issue Mar 3, 2020
@wildart wildart closed this as completed in c4a6423 Mar 3, 2020
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

2 participants