Skip to content

Commit

Permalink
Circumvent type-instability of deepcopy. Fixes #356
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Sep 26, 2015
1 parent f2b6493 commit 3761d9a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ ndims(img::AbstractImage) = ndims(img.data)

strides(img::AbstractImage) = strides(img.data)

copy(img::Image) = Image(copy(img.data), deepcopy(img.properties))
copy(img::ImageCmap) = ImageCmap(copy(img.data), copy(img.cmap), deepcopy(img.properties))
copy(img::Image) = Image(copy(img.data), deepcopy(img.properties)::typeof(img.properties)) # see issue #356
copy(img::ImageCmap) = ImageCmap(copy(img.data), copy(img.cmap), deepcopy(img.properties)::typeof(img.properties))

# Create a new "Image" (could be just an Array) copying the properties but replacing the data
copyproperties(img::AbstractArray, data::AbstractArray) = data
Expand Down
5 changes: 4 additions & 1 deletion test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ if testing_units
end

facts("Core") do
a = rand(3,3)
@inferred(Image(a))

# support integer-valued types, but these are NOT recommended (use Ufixed)
B = rand(convert(UInt16, 1):convert(UInt16, 20), 3, 5)
# img, imgd, and imgds will be used in many more tests
Expand Down Expand Up @@ -127,7 +130,7 @@ facts("Core") do

context("Copy / similar") do
A = randn(3,5,3)
imgc = copy(img)
imgc = @inferred(copy(img))
@fact imgc.data --> img.data
imgc = copyproperties(imgd, A)
@fact imgc.data --> A
Expand Down

0 comments on commit 3761d9a

Please sign in to comment.