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

Test on dimnames for KeyedArrays #62

Merged
merged 1 commit into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions test/linear_combination.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,13 @@

@testset "dims = 1" begin
@test FeatureTransforms.apply(A, lc; dims=1) == [-3, -3]
@test FeatureTransforms.apply(A, lc; dims=:foo) == [-3, -3]
@test lc(A; dims=1) == [-3, -3]
end

@testset "dims = 2" begin
@test FeatureTransforms.apply(A, lc; dims=2) == [-1, -1]
@test FeatureTransforms.apply(A, lc; dims=:bar) == [-1, -1]
@test lc(A; dims=2) == [-1, -1]
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/one_hot_encoding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
A = KeyedArray(M, foo=["a", "b"], bar=["x", "y"])
expected = [1 0 0 0 0; 0 0 0 1 0; 0 1 0 0 0; 0 0 0 0 1]

@testset "dims = $d" for d in (1, 2, Colon())
@testset "dims = $d" for d in (1, 2, Colon(), :foo, :bar)
transformed = FeatureTransforms.apply(A, ohe; dims=d)
# This transform doesn't preserve the type it operates on
@test transformed isa AbstractArray
Expand Down
2 changes: 1 addition & 1 deletion test/periodic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
bar=["x", "y"]
)

@testset "dims = $d" for d in (Colon(), :foo, :bar)
@testset "dims = $d" for d in (Colon(), :foo, :bar, 1, 2)
transformed = FeatureTransforms.apply(A, p; dims=d)
@test transformed isa KeyedArray
@test transformed ≈ expected atol=1e-14
Expand Down
2 changes: 1 addition & 1 deletion test/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
A = KeyedArray([1 2 3; 4 5 6], foo=["a", "b"], bar=["x", "y", "z"])
expected = KeyedArray([1 8 27; 64 125 216], foo=["a", "b"], bar=["x", "y", "z"])

@testset "dims = $d" for d in (Colon(), :foo, :bar)
@testset "dims = $d" for d in (Colon(), :foo, :bar, 1, 2)
transformed = FeatureTransforms.apply(A, p; dims=d)
@test transformed isa KeyedArray
@test transformed == expected
Expand Down
36 changes: 19 additions & 17 deletions test/scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,31 +412,33 @@
@test _A ≈ A_expected atol=1e-5
end

@testset "dims = :" begin
scaling = MeanStdScaling(A, dims=:)
@test FeatureTransforms.apply(A, scaling; dims=:) ≈ A_expected atol=1e-5
end

@testset "dims = 1" begin
scaling = MeanStdScaling(A; dims=1)
@test FeatureTransforms.apply(A, scaling; dims=1) ≈ A_expected atol=1e-5
end

@testset "dims = 2" begin
scaling = MeanStdScaling(A; dims=2)
@test FeatureTransforms.apply(A, scaling; dims=2) ≈ A_expected atol=1e-5
@testset "dims = $d" for d in (Colon(), 1, 2, :foo, :bar)
scaling = MeanStdScaling(A, dims=d)
@test FeatureTransforms.apply(A, scaling; dims=d) ≈ A_expected atol=1e-5
end

@testset "inds" begin
scaling = MeanStdScaling(A)
@test FeatureTransforms.apply(A, scaling; inds=[2, 3]) ≈ [-0.559017, -1.11803] atol=1e-5
@test FeatureTransforms.apply(A, scaling; dims=:, inds=[2, 3]) ≈ [-0.559017, -1.11803] atol=1e-5

scaling = MeanStdScaling(A; dims=1, inds=[2])
@test FeatureTransforms.apply(A, scaling; dims=1, inds=[2]) ≈ [-1.0 0.0 1.0] atol=1e-5
@testset "dims=$d" for d in (1, :foo)
scaling = MeanStdScaling(A; dims=d, inds=[2])
@test isapprox(
FeatureTransforms.apply(A, scaling; dims=d, inds=[2]),
[-1.0 0.0 1.0],
atol=1e-5
)
end

scaling = MeanStdScaling(A; dims=2, inds=[2])
@test FeatureTransforms.apply(A, scaling; dims=2, inds=[2]) ≈ [-0.70711 0.70711]' atol=1e-5
@testset "dims=$d" for d in (2, :bar)
scaling = MeanStdScaling(A; dims=2, inds=[2])
@test isapprox(
FeatureTransforms.apply(A, scaling; dims=2, inds=[2]),
[-0.70711 0.70711]',
atol=1e-5
)
end
end

@testset "Re-apply" begin
Expand Down
4 changes: 3 additions & 1 deletion test/temporal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
@test FeatureTransforms.apply(A, hod) == expected
@test hod(A) == expected

@testset "dims = $d" for d in (Colon(), 1, 2)
@testset "dims = $d" for d in (Colon(), 1, 2, :foo, :bar)
transformed = FeatureTransforms.apply(A, hod; dims=d)
@test transformed isa KeyedArray
@test transformed == expected
Expand All @@ -125,6 +125,8 @@
@test FeatureTransforms.apply(A, hod; dims=:, inds=[2, 3]) == [2, 9]
@test FeatureTransforms.apply(A, hod; dims=1, inds=[2]) == [2 10 12]
@test FeatureTransforms.apply(A, hod; dims=2, inds=[2]) == reshape([9, 10], 2, 1)
@test FeatureTransforms.apply(A, hod; dims=:foo, inds=[2]) == [2 10 12]
@test FeatureTransforms.apply(A, hod; dims=:bar, inds=[2]) == reshape([9, 10], 2, 1)
end
end

Expand Down