Skip to content

Commit c85b0d7

Browse files
authored
Merge pull request #129 from theogf/transform_vector_of_vector
Apply Transform on vector of vectors
2 parents 6f7be06 + 8faffe5 commit c85b0d7

File tree

7 files changed

+13
-6
lines changed

7 files changed

+13
-6
lines changed

src/transform/transform.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ include("chaintransform.jl")
77

88

99
Base.map(t::Transform, x::AbstractVector) = _map(t, x)
10+
_map(t::Transform, x::AbstractVector) = t.(x)
1011

1112
"""
1213
IdentityTransform()

test/transform/ardtransform.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
v = randn(rng, D)
1818
t = ARDTransform(v)
1919

20+
XV = [randn(rng, D) for _ in 1:5]
2021
XC = ColVecs(randn(rng, D, 7))
2122
XR = RowVecs(randn(rng, 2, D))
2223

23-
@testset "$(typeof(x))" for x in [XC, XR]
24+
@testset "$(typeof(x))" for x in [XV, XC, XR]
2425
x′ = map(t, x)
2526
@test all([t(x[n]) == v .* x[n] for n in eachindex(x)])
2627
@test all([t(x[n]) x′[n] for n in eachindex(x)])

test/transform/functiontransform.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
f = x -> sin.(x)
1616
t = FunctionTransform(f)
1717

18+
x_vecs = [randn(rng, 5) for _ in 1:6]
1819
x_cols = ColVecs(randn(rng, 4, 7))
1920
x_rows = RowVecs(randn(rng, 6, 3))
2021

21-
@testset "$(typeof(x))" for x in [x_cols, x_rows]
22+
@testset "$(typeof(x))" for x in [x_vecs, x_cols, x_rows]
2223
x′ = map(t, x)
2324
@test all([t(x[n]) f(x[n]) for n in eachindex(x)])
2425
@test all([t(x[n]) x′[n] for n in eachindex(x)])

test/transform/lineartransform.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@
1818
P = randn(rng, Dout, Din)
1919
t = LinearTransform(P)
2020

21+
x_vecs = [randn(rng, Din) for _ in 1:6]
2122
x_cols = ColVecs(randn(rng, Din, 8))
2223
x_rows = RowVecs(randn(rng, 9, Din))
2324

24-
@testset "$(typeof(x))" for x in [x_cols, x_rows]
25+
@testset "$(typeof(x))" for x in [x_vecs, x_cols, x_rows]
2526
x′ = map(t, x)
2627
@test all([t(x[n]) P * x[n] for n in eachindex(x)])
2728
@test all([t(x[n]) x′[n] for n in eachindex(x)])

test/transform/scaletransform.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
t = ScaleTransform(s)
55

66
x = randn(rng, 7)
7+
XV = [randn(rng, 6) for _ in 1:4]
78
XC = ColVecs(randn(rng, 10, 5))
89
XR = RowVecs(randn(rng, 6, 11))
910

10-
@testset "$(typeof(x))" for x in [x, XC, XR]
11+
@testset "$(typeof(x))" for x in [x, XV, XC, XR]
1112
x′ = map(t, x)
1213
@test all([t(x[n]) s .* x[n] for n in eachindex(x)])
1314
@test all([t(x[n]) x′[n] for n in eachindex(x)])

test/transform/selecttransform.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
select = [1, 3, 5]
55
t = SelectTransform(select)
66

7+
x_vecs = [randn(rng, maximum(select)) for _ in 1:3]
78
x_cols = ColVecs(randn(rng, maximum(select), 6))
89
x_rows = RowVecs(randn(rng, 4, maximum(select)))
910

10-
@testset "$(typeof(x))" for x in [x_cols, x_rows]
11+
@testset "$(typeof(x))" for x in [x_vecs, x_cols, x_rows]
1112
x′ = map(t, x)
1213
@test all([t(x[n]) == x[n][select] for n in eachindex(x)])
1314
@test all([t(x[n]) == x′[n] for n in eachindex(x)])

test/transform/transform.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
@testset "transform" begin
22
rng = MersenneTwister(123546)
33
x = randn(rng, 8)
4+
XV = [randn(rng, 5) for _ in 1:6]
45
XC = ColVecs(randn(rng, 5, 10))
56
XR = RowVecs(randn(rng, 11, 3))
6-
@testset "IdentityTransform($(typeof(x)))" for x in [x, XC, XR]
7+
@testset "IdentityTransform($(typeof(x)))" for x in [x, XV, XC, XR]
78
@test IdentityTransform()(x) == x
89
@test map(IdentityTransform(), x) == x
910
end

0 commit comments

Comments
 (0)