diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 644faa5..b85578e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,7 @@ jobs: with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: actions/cache@v1 + - uses: actions/cache@v3 env: cache-name: cache-artifacts with: diff --git a/docs/src/pca.md b/docs/src/pca.md index 6805e33..d50cf82 100644 --- a/docs/src/pca.md +++ b/docs/src/pca.md @@ -117,6 +117,10 @@ predict(::KernelPCA) predict(::KernelPCA, ::AbstractVecOrMat{T}) where {T<:Real} reconstruct(::KernelPCA, ::AbstractVecOrMat{T}) where {T<:Real} size(::KernelPCA) +``` +!!! note + If `reconstruct` is called with an input that is not an `AbstractVecOrMat` of real numbers, an `ArgumentError` is thrown indicating the invalid input type and the expected type. +``` projection(::KernelPCA) eigvals(::KernelPCA) eigvecs(::KernelPCA) @@ -164,6 +168,10 @@ fit size(::PPCA) mean(::PPCA) var(::PPCA) +``` +!!! note + If `reconstruct` is called with an input that is not an `AbstractVecOrMat` of real numbers, an `ArgumentError` is thrown indicating the invalid input type and the expected type. +``` cov(::PPCA) projection(::PPCA) loadings(::PPCA) @@ -188,6 +196,9 @@ Here, ``\mathbf{W}`` is the factor loadings or weight matrix. predict(::PPCA, ::AbstractVecOrMat{T}) where {T<:Real} reconstruct(::PPCA, ::AbstractVecOrMat{T}) where {T<:Real} ``` +``` +!!! note + If `reconstruct` is called with an input that is not an `AbstractVecOrMat` of real numbers, an `ArgumentError` is thrown indicating the invalid input type and the expected type. Auxiliary functions: diff --git a/src/types.jl b/src/types.jl index dbaecb1..012286e 100644 --- a/src/types.jl +++ b/src/types.jl @@ -23,8 +23,14 @@ projection(model::AbstractDimensionalityReduction) = error("'projection' is not reconstruct(model::AbstractDimensionalityReduction, y) Return the model response (a.k.a. the dependent variable). +Throws an `ArgumentError` if `y` is not an `AbstractVecOrMat` of real numbers, indicating the invalid +input type and the expected type. """ -reconstruct(model::AbstractDimensionalityReduction, y) = error("'reconstruct' is not defined for $(typeof(model)).") +function reconstruct(model::AbstractDimensionalityReduction, y) + throw(ArgumentError("Invalid input type $(typeof(y)) for reconstruct(::$(typeof(model))). " * + "Expected an AbstractVecOrMat of real numbers." + )) +end abstract type LinearDimensionalityReduction <: AbstractDimensionalityReduction end diff --git a/test/pca.jl b/test/pca.jl index 865b965..4d5bfe5 100644 --- a/test/pca.jl +++ b/test/pca.jl @@ -43,6 +43,12 @@ import SparseArrays @test reconstruct(M, Y[:,1]) ≈ P * Y[:,1] @test reconstruct(M, Y) ≈ P * Y + @test_throws ArgumentError reconstruct(M, 123) + @test_throws ArgumentError reconstruct(M, Dict()) + @test_throws ArgumentError reconstruct(M, "abc") + @test_throws ArgumentError reconstruct(M, 8923.29) + @test_throws ArgumentError reconstruct(M, 1+2im) + ## PCA with non-zero mean