Skip to content

Commit 5c0715d

Browse files
kshyattandyferris
authored andcommitted
Let randexp work with macros. Add tests. (#188)
1 parent e3365b7 commit 5c0715d

File tree

12 files changed

+24
-12
lines changed

12 files changed

+24
-12
lines changed

src/MArray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ macro MArray(ex)
239239
$(esc(Expr(:call, Expr(:curly, :MArray, Tuple{rng_lengths...}, T), Expr(:tuple, exprs...))))
240240
end
241241
elseif isa(ex, Expr) && ex.head == :call
242-
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn
242+
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn || ex.args[1] == :randexp
243243
if length(ex.args) == 1
244244
error("@MArray got bad expression: $(ex.args[1])()")
245245
else
@@ -283,7 +283,7 @@ macro MArray(ex)
283283
error("Bad eye() expression for @MArray")
284284
end
285285
else
286-
error("@MArray only supports the zeros(), ones(), rand(), randn() and eye() functions.")
286+
error("@MArray only supports the zeros(), ones(), rand(), randn(), randexp(), and eye() functions.")
287287
end
288288
else
289289
error("Bad input for @MArray")

src/MMatrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ macro MMatrix(ex)
185185
$(esc(Expr(:call, Expr(:curly, :MMatrix, length(rng1), length(rng2), T), Expr(:tuple, exprs...))))
186186
end
187187
elseif isa(ex, Expr) && ex.head == :call
188-
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn
188+
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn || ex.args[1] == :randexp
189189
if length(ex.args) == 3
190190
return quote
191191
$(ex.args[1])(MMatrix{$(esc(ex.args[2])),$(esc(ex.args[3]))})
@@ -227,7 +227,7 @@ macro MMatrix(ex)
227227
error("Bad eye() expression for @MMatrix")
228228
end
229229
else
230-
error("@MMatrix only supports the zeros(), ones(), fill(), rand(), randn() and eye() functions.")
230+
error("@MMatrix only supports the zeros(), ones(), rand(), randn(), randexp(), and eye() functions.")
231231
end
232232
else
233233
error("Bad input for @MMatrix")

src/MVector.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ macro MVector(ex)
9696
$(esc(Expr(:call, Expr(:curly, :MVector, length(rng), T), Expr(:tuple, exprs...))))
9797
end
9898
elseif isa(ex, Expr) && ex.head == :call
99-
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand ||ex.args[1] == :randn
99+
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn || ex.args[1] == :randexp
100100
if length(ex.args) == 2
101101
return quote
102102
$(esc(ex.args[1]))(MVector{$(esc(ex.args[2]))})
@@ -117,7 +117,7 @@ macro MVector(ex)
117117
error("@MVector expected a 1-dimensional array expression")
118118
end
119119
else
120-
error("@MVector only supports the zeros(), ones(), fill(), rand() and randn() functions.")
120+
error("@MVector only supports the zeros(), ones(), rand(), randn(), randexp(), and eye() functions.")
121121
end
122122
else
123123
error("Use @MVector [a,b,c] or @MVector([a,b,c])")

src/SArray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ macro SArray(ex)
202202
$(esc(Expr(:call, Expr(:curly, :SArray, Tuple{rng_lengths...}, T), Expr(:tuple, exprs...))))
203203
end
204204
elseif isa(ex, Expr) && ex.head == :call
205-
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn
205+
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn || ex.args[1] == :randexp
206206
if length(ex.args) == 1
207207
error("@SArray got bad expression: $(ex.args[1])()")
208208
else
@@ -246,7 +246,7 @@ macro SArray(ex)
246246
error("Bad eye() expression for @SArray")
247247
end
248248
else
249-
error("@SArray only supports the zeros(), ones(), rand(), randn() and eye() functions.")
249+
error("@SArray only supports the zeros(), ones(), rand(), randn(), randexp(), and eye() functions.")
250250
end
251251
else
252252
error("Bad input for @SArray")

src/SMatrix.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ macro SMatrix(ex)
159159
$(esc(Expr(:call, Expr(:curly, :SMatrix, length(rng1), length(rng2), T), Expr(:tuple, exprs...))))
160160
end
161161
elseif isa(ex, Expr) && ex.head == :call
162-
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn
162+
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn || ex.args[1] == :randexp
163163
if length(ex.args) == 3
164164
return quote
165165
$(ex.args[1])(SMatrix{$(esc(ex.args[2])),$(esc(ex.args[3]))})
@@ -201,7 +201,7 @@ macro SMatrix(ex)
201201
error("Bad eye() expression for @SMatrix")
202202
end
203203
else
204-
error("@SMatrix only supports the zeros(), ones(), fill(), rand(), randn() and eye() functions.")
204+
error("@SMatrix only supports the zeros(), ones(), rand(), randn(), randexp(), and eye() functions.")
205205
end
206206
else
207207
error("Bad input for @SMatrix")

src/SVector.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ macro SVector(ex)
8787
$(esc(Expr(:call, Expr(:curly, :SVector, length(rng), T), Expr(:tuple, exprs...))))
8888
end
8989
elseif isa(ex, Expr) && ex.head == :call
90-
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand ||ex.args[1] == :randn
90+
if ex.args[1] == :zeros || ex.args[1] == :ones || ex.args[1] == :rand || ex.args[1] == :randn || ex.args[1] == :randexp
9191
if length(ex.args) == 2
9292
return quote
9393
$(esc(ex.args[1]))(SVector{$(esc(ex.args[2]))})
@@ -108,7 +108,7 @@ macro SVector(ex)
108108
error("@SVector expected a 1-dimensional array expression")
109109
end
110110
else
111-
error("@SVector only supports the zeros(), ones(), fill(), rand() and randn() functions.")
111+
error("@SVector only supports the zeros(), ones(), rand(), randn(), randexp(), and eye() functions.")
112112
end
113113
else # TODO Expr(:call, :zeros), Expr(:call, :ones), Expr(:call, :eye) ?
114114
error("Use @SVector [a,b,c], @SVector Type[a,b,c] or a comprehension like [f(i) for i = i_min:i_max]")

test/MArray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@
5656
@test ((@MArray eye(2,2))::MArray{Tuple{2,2}, Float64}).data === (1.0, 0.0, 0.0, 1.0)
5757
@test isa(@MArray(rand(2,2,1)), MArray{Tuple{2,2,1}, Float64})
5858
@test isa(@MArray(randn(2,2,1)), MArray{Tuple{2,2,1}, Float64})
59+
@test isa(@MArray(randexp(2,2,1)), MArray{Tuple{2,2,1}, Float64})
5960

6061
@test ((@MArray zeros(Float32, 2, 2, 1))::MArray{Tuple{2,2,1},Float32}).data === (0.0f0, 0.0f0, 0.0f0, 0.0f0)
6162
@test ((@MArray ones(Float32, 2, 2, 1))::MArray{Tuple{2,2,1},Float32}).data === (1.0f0, 1.0f0, 1.0f0, 1.0f0)
6263
@test ((@MArray eye(Float32, 2))::MArray{Tuple{2,2}, Float32}).data === (1.0f0, 0.0f0, 0.0f0, 1.0f0)
6364
@test ((@MArray eye(Float32, 2, 2))::MArray{Tuple{2,2}, Float32}).data === (1.0f0, 0.0f0, 0.0f0, 1.0f0)
6465
@test isa(@MArray(rand(Float32, 2, 2, 1)), MArray{Tuple{2,2,1}, Float32})
6566
@test isa(@MArray(randn(Float32, 2, 2, 1)), MArray{Tuple{2,2,1}, Float32})
67+
@test isa(@MArray(randexp(Float32, 2, 2, 1)), MArray{Tuple{2,2,1}, Float32})
6668

6769
m = [1 2; 3 4]
6870
@test MArray{Tuple{2,2}}(m) == @MArray [1 2; 3 4]

test/MMatrix.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@
5454
@test ((@MMatrix eye(2,2))::MMatrix{2, 2, Float64}).data === (1.0, 0.0, 0.0, 1.0)
5555
@test isa(@MMatrix(rand(2,2)), MMatrix{2, 2, Float64})
5656
@test isa(@MMatrix(randn(2,2)), MMatrix{2, 2, Float64})
57+
@test isa(@MMatrix(randexp(2,2)), MMatrix{2, 2, Float64})
5758

5859
@test ((@MMatrix zeros(Float32, 2, 2))::MMatrix{2,2,Float32}).data === (0.0f0, 0.0f0, 0.0f0, 0.0f0)
5960
@test ((@MMatrix ones(Float32, 2, 2))::MMatrix{2,2,Float32}).data === (1.0f0, 1.0f0, 1.0f0, 1.0f0)
6061
@test ((@MMatrix eye(Float32, 2))::MMatrix{2, 2, Float32}).data === (1.0f0, 0.0f0, 0.0f0, 1.0f0)
6162
@test ((@MMatrix eye(Float32, 2, 2))::MMatrix{2, 2, Float32}).data === (1.0f0, 0.0f0, 0.0f0, 1.0f0)
6263
@test isa(@MMatrix(rand(Float32, 2, 2)), MMatrix{2, 2, Float32})
6364
@test isa(@MMatrix(randn(Float32, 2, 2)), MMatrix{2, 2, Float32})
65+
@test isa(@MMatrix(randexp(Float32, 2, 2)), MMatrix{2, 2, Float32})
6466

6567
@test MMatrix(SMatrix{1,1,Int,1}((1,))).data == (1,)
6668
end

test/MVector.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@
2727
@test ((@MVector fill(2.5, 2))::MVector{2, Float64}).data === (2.5, 2.5)
2828
@test isa(@MVector(rand(2)), MVector{2, Float64})
2929
@test isa(@MVector(randn(2)), MVector{2, Float64})
30+
@test isa(@MVector(randexp(2)), MVector{2, Float64})
3031

3132
@test ((@MVector zeros(Float32, 2))::MVector{2,Float32}).data === (0.0f0, 0.0f0)
3233
@test ((@MVector ones(Float32, 2))::MVector{2,Float32}).data === (1.0f0, 1.0f0)
3334
@test isa(@MVector(rand(Float32, 2)), MVector{2, Float32})
3435
@test isa(@MVector(randn(Float32, 2)), MVector{2, Float32})
36+
@test isa(@MVector(randexp(Float32, 2)), MVector{2, Float32})
3537
@test (ex = macroexpand(:(@MVector fill(1.5, 2, 3))); isa(ex, Expr) && ex.head == :error)
3638
@test (ex = macroexpand(:(@MVector ones(2, 3, 4))); isa(ex, Expr) && ex.head == :error)
3739
@test (ex = macroexpand(:(@MVector [i*j for i in 1:2, j in 2:3])); isa(ex, Expr) && ex.head == :error)

test/SArray.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@
5454
@test ((@SArray eye(2,2))::SArray{Tuple{2,2}, Float64}).data === (1.0, 0.0, 0.0, 1.0)
5555
@test isa(@SArray(rand(2,2,1)), SArray{Tuple{2,2,1}, Float64})
5656
@test isa(@SArray(randn(2,2,1)), SArray{Tuple{2,2,1}, Float64})
57+
@test isa(@SArray(randexp(2,2,1)), SArray{Tuple{2,2,1}, Float64})
5758

5859
@test ((@SArray zeros(Float32, 2, 2, 1))::SArray{Tuple{2,2,1},Float32}).data === (0.0f0, 0.0f0, 0.0f0, 0.0f0)
5960
@test ((@SArray ones(Float32, 2, 2, 1))::SArray{Tuple{2,2,1},Float32}).data === (1.0f0, 1.0f0, 1.0f0, 1.0f0)
6061
@test ((@SArray eye(Float32, 2))::SArray{Tuple{2,2}, Float32}).data === (1.0f0, 0.0f0, 0.0f0, 1.0f0)
6162
@test ((@SArray eye(Float32, 2, 2))::SArray{Tuple{2,2}, Float32}).data === (1.0f0, 0.0f0, 0.0f0, 1.0f0)
6263
@test isa(@SArray(rand(Float32, 2, 2, 1)), SArray{Tuple{2,2,1}, Float32})
6364
@test isa(@SArray(randn(Float32, 2, 2, 1)), SArray{Tuple{2,2,1}, Float32})
65+
@test isa(@SArray(randexp(Float32, 2, 2, 1)), SArray{Tuple{2,2,1}, Float32})
6466

6567
m = [1 2; 3 4]
6668
@test SArray{Tuple{2,2}}(m) === @SArray [1 2; 3 4]

0 commit comments

Comments
 (0)