Skip to content

preprocess_mean throws TypeError when handling Integer types #112

Description

@Heladio-ac

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}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions