Skip to content

Commit 90b1f9d

Browse files
committed
Fixes for #8
1 parent 46f079d commit 90b1f9d

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

src/tarray.jl

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

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

3837
function TArray(T::Type, dim)
@@ -46,10 +45,6 @@ end
4645
#
4746
# Indexing Interface Implementation
4847
#
49-
# function Base.getindex(S::TArray, i::Real)
50-
# t, d = task_local_storage(S.ref)
51-
# return getindex(d, i)
52-
# end
5348

5449
function Base.getindex(S::TArray{T, N}, I::Vararg{Int,N}) where {T, N}
5550
t, d = task_local_storage(S.ref)
@@ -68,24 +63,6 @@ function Base.setindex!(S::TArray{T, N}, x, I::Vararg{Int,N}) where {T, N}
6863
newd[I...] = x
6964
end
7065

71-
function Base.firstindex(S::TArray)
72-
_, d = task_local_storage(S.ref)
73-
firstindex(d)
74-
end
75-
76-
function Base.lastindex(S::TArray)
77-
_, d = task_local_storage(S.ref)
78-
lastindex(d)
79-
end
80-
81-
#
82-
# Iterator Interface Implementation
83-
#
84-
function Base.iterate(S::TArray, state=1)
85-
_, d = task_local_storage(S.ref)
86-
return iterate(d, state)
87-
end
88-
8966
function Base.push!(S::TArray, x)
9067
n, d = task_local_storage(S.ref)
9168
cn = n_copies()
@@ -134,13 +111,15 @@ Base.ndims(S::TArray) = Base.ndims(task_local_storage(S.ref)[2])
134111
# Base.get(t::Task, S::TArray) = (t.storage[S.ref][2])
135112
Base.get(S::TArray) = (current_task().storage[S.ref][2])
136113

114+
# Implements eltype, firstindex, lastindex, and iterate
115+
# functions.
116+
for F in (:eltype, :firstindex, :lastindex, :iterate)
117+
@eval Base.$F(a::TArray, args...) = $F(get(a), args...)
118+
end
119+
137120
#
138121
# Similarity implementation
139122
#
140-
function Base.eltype(S::TArray)
141-
_, d = task_local_storage(S.ref)
142-
return eltype(d)
143-
end
144123

145124
Base.similar(S::TArray) = tzeros(eltype(S), size(S))
146125
Base.similar(S::TArray, ::Type{T}) where {T} = tzeros(T, size(S))

0 commit comments

Comments
 (0)