Skip to content

Commit c48b28f

Browse files
authored
Fix constructors (#77)
1 parent 66104ba commit c48b28f

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

.github/workflows/Testing.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
- '1.2'
2121
- '1.3'
2222
- '1.4'
23+
- '1'
2324
- 'nightly'
2425
os:
2526
- ubuntu-latest

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
33
license = "MIT"
44
desc = "C shim for task copying in Turing"
55
repo = "https://github.com/TuringLang/Libtask.jl.git"
6-
version = "0.4.2"
6+
version = "0.4.3"
77

88
[deps]
99
BinaryProvider = "b99e7846-7c00-51b0-8f62-c81ae34c0232"

src/tarray.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,10 @@ struct TArray{T,N} <: AbstractArray{T,N}
2929
TArray{T,N}() where {T,N} = new(gensym(), current_task())
3030
end
3131

32-
TArray{T,1}(d::Integer) where T = TArray(T, d)
3332
TArray{T}(d::Integer...) where T = TArray(T, d)
34-
TArray{T}(UndefInitializer, d::Integer...) where T = TArray(T, d)
35-
TArray{T,N}(d::Integer...) where {T,N} = length(d)==N ? TArray(T,d) : error("Malformed dims")
36-
TArray{T,N}(UndefInitializer, d::Integer...) where {T,N} = length(d)==N ? TArray(T,d) : error("Malformed dims")
33+
TArray{T}(::UndefInitializer, d::Integer...) where T = TArray(T, d)
34+
TArray{T,N}(d::Vararg{<:Integer,N}) where {T,N} = TArray(T, d)
35+
TArray{T,N}(::UndefInitializer, d::Vararg{<:Integer,N}) where {T,N} = TArray{T,N}(d)
3736
TArray{T,N}(dim::NTuple{N,Int}) where {T,N} = TArray(T, dim)
3837

3938
function TArray(T::Type, dim)

test/tarray.jl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,47 @@
3636

3737
@testset "other methods" begin
3838
ta2 = TArray{Int}(4, 4)
39+
@test ta2 isa TArray{Int,2}
40+
@test size(ta2) == (4, 4)
41+
42+
ta2 = TArray{Int}(undef, 4, 4)
43+
@test ta2 isa TArray{Int,2}
44+
@test size(ta2) == (4, 4)
45+
46+
ta2 = TArray{Int,2}(4, 4)
47+
@test ta2 isa TArray{Int,2}
48+
@test size(ta2) == (4, 4)
49+
50+
ta2 = TArray{Int,2}(undef, 4, 4)
51+
@test ta2 isa TArray{Int,2}
52+
@test size(ta2) == (4, 4)
53+
54+
@test_throws MethodError TArray{Int,2}(4)
55+
@test_throws MethodError TArray{Int,2}(undef, 4)
3956

4057
ta3 = TArray{Int, 4}(4, 3, 2, 1)
4158
ta4 = get(ta3)
4259
@test ta3[3] == ta4[3]
4360

4461
ta5 = TArray{Int}(4)
62+
@test ta5 isa TArray{Int,1}
63+
@test size(ta5) == (4,)
64+
65+
ta5 = TArray{Int}(undef, 4)
66+
@test ta5 isa TArray{Int,1}
67+
@test size(ta5) == (4,)
68+
69+
ta5 = TArray{Int,1}(4)
70+
@test ta5 isa TArray{Int,1}
71+
@test size(ta5) == (4,)
72+
73+
ta5 = TArray{Int,1}(undef, 4)
74+
@test ta5 isa TArray{Int,1}
75+
@test size(ta5) == (4,)
76+
77+
@test_throws MethodError TArray{Int,1}(4, 4)
78+
@test_throws MethodError TArray{Int,1}(undef, 4, 4)
79+
4580
for i in 1:4
4681
ta5[i] = i
4782
end

0 commit comments

Comments
 (0)