Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/tarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function Base.getindex(S::TArray{T, N}, I::Vararg{Int,N}) where {T, N}
return d[I...]
end

function Base.setindex!(S::TArray{T, N}, x, I::Vararg{Int,N}) where {T, N}
function Base.setindex!(S::TArray{T, N}, x::T, I::Vararg{Int,N}) where {T, N}
n, d = task_local_storage(S.ref)
cn = n_copies()
newd = d
Expand All @@ -65,7 +65,7 @@ function Base.setindex!(S::TArray{T, N}, x, I::Vararg{Int,N}) where {T, N}
newd[I...] = x
end

function Base.push!(S::TArray, x)
function Base.push!(S::TArray{T}, x::T) where T
n, d = task_local_storage(S.ref)
cn = n_copies()
newd = d
Expand Down Expand Up @@ -102,21 +102,27 @@ end

function Base.display(S::TArray)
arr = S.orig_task.storage[S.ref][2]
@warn "display(::TArray) prints the originating task's storage, not the current task's storage. Please use show(::TArray) to display the current task's version of a TArray."
@warn "display(::TArray) prints the originating task's storage, " *
"not the current task's storage. " *
"Please use show(::TArray) to display the current task's version of a TArray."
display(arr)
end

Base.show(io::IO, S::TArray) = Base.show(io::IO, task_local_storage(S.ref)[2])
Base.size(S::TArray) = Base.size(task_local_storage(S.ref)[2])
Base.ndims(S::TArray) = Base.ndims(task_local_storage(S.ref)[2])

# Base.get(t::Task, S) = S
# Base.get(t::Task, S::TArray) = (t.storage[S.ref][2])
Base.get(S::TArray) = (current_task().storage[S.ref][2])

# Implements eltype, firstindex, lastindex, and iterate
# functions.
for F in (:eltype, :firstindex, :lastindex, :iterate)
##
# Iterator Interface
IteratorSize(::Type{TArray{T, N}}) where {T, N} = HasShape{N}()
IteratorEltype(::Type{TArray}) = HasEltype()

# Implements iterate, eltype, length, and size functions,
# as well as firstindex, lastindex, ndims, and axes
for F in (:iterate, :eltype, :length, :size,
:firstindex, :lastindex, :ndims, :axes)
@eval Base.$F(a::TArray, args...) = $F(get(a), args...)
end

Expand Down
2 changes: 1 addition & 1 deletion src/tref.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##########
# TRef #
# TRef #
##########

"""
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ include("clonetask.jl")
include("brokentask.jl")
include("tarray.jl")
include("tarray2.jl")
include("tarray3.jl")
32 changes: 32 additions & 0 deletions test/tarray3.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Libtask
using Test

@testset "TArray Copying Test" begin
DATA = Dict{Task, Array}()

function f_ct()
ta = tzeros(UInt64, 4);
for i in 1:4
ta[i] = hash(current_task())
DATA[current_task()] = convert(Array, ta)
produce(ta[i])
end
end

t = CTask(f_ct)

@test consume(t) == hash(t) # index = 1
@test consume(t) == hash(t) # index = 2

a = copy(t);

@test consume(a) == hash(a) # index = 3
@test consume(a) == hash(a) # index = 4

@test consume(t) == hash(t) # index = 3


@test DATA[t] == [hash(t), hash(t), hash(t), 0]
@test DATA[a] == [hash(t), hash(t), hash(a), hash(a)]

end