@@ -29,10 +29,9 @@ struct TArray{T,N} <: AbstractArray{T,N}
29
29
TArray {T,N} () where {T,N} = new (gensym (), current_task ())
30
30
end
31
31
32
- TArray {T} () where T = TArray (T, d)
33
32
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" )
36
35
TArray {T,N} (dim:: NTuple{N,Int} ) where {T,N} = TArray (T, dim)
37
36
38
37
function TArray (T:: Type , dim)
46
45
#
47
46
# Indexing Interface Implementation
48
47
#
49
- # function Base.getindex(S::TArray, i::Real)
50
- # t, d = task_local_storage(S.ref)
51
- # return getindex(d, i)
52
- # end
53
48
54
49
function Base. getindex (S:: TArray{T, N} , I:: Vararg{Int,N} ) where {T, N}
55
50
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}
68
63
newd[I... ] = x
69
64
end
70
65
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
-
89
66
function Base. push! (S:: TArray , x)
90
67
n, d = task_local_storage (S. ref)
91
68
cn = n_copies ()
@@ -134,13 +111,15 @@ Base.ndims(S::TArray) = Base.ndims(task_local_storage(S.ref)[2])
134
111
# Base.get(t::Task, S::TArray) = (t.storage[S.ref][2])
135
112
Base. get (S:: TArray ) = (current_task (). storage[S. ref][2 ])
136
113
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
+
137
120
#
138
121
# Similarity implementation
139
122
#
140
- function Base. eltype (S:: TArray )
141
- _, d = task_local_storage (S. ref)
142
- return eltype (d)
143
- end
144
123
145
124
Base. similar (S:: TArray ) = tzeros (eltype (S), size (S))
146
125
Base. similar (S:: TArray , :: Type{T} ) where {T} = tzeros (T, size (S))
0 commit comments