-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from JuliaArrays/teh/dict
This is primarily intended for ImageSegmentation, for which the index label is not guaranteed to be contiguous. * Add Manifest to .gitignore * Use testsets
- Loading branch information
Showing
5 changed files
with
106 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ jobs: | |
fail-fast: false | ||
matrix: | ||
version: | ||
- '0.7' | ||
- '1.0' | ||
- '1' | ||
- 'nightly' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*.jl.cov | ||
*.jl.*.cov | ||
*.jl.mem | ||
Manifest.toml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
name = "IndirectArrays" | ||
uuid = "9b13fd28-a010-5f03-acff-a1bbcff69959" | ||
version = "0.5.1" | ||
version = "1.0.0" | ||
|
||
[deps] | ||
|
||
[compat] | ||
FixedPointNumbers = "0.5, 0.6, 0.7" | ||
julia = "0.7, 1" | ||
julia = "1" | ||
|
||
[extras] | ||
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581" | ||
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93" | ||
MappedArrays = "dbb5928d-eab1-5f90-85c2-b9b0edb7c900" | ||
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" | ||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | ||
|
||
[targets] | ||
test = ["Test", "MappedArrays", "Colors", "FixedPointNumbers"] | ||
test = ["Test", "MappedArrays", "Colors", "FixedPointNumbers", "OrderedCollections"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,68 @@ | ||
using IndirectArrays, MappedArrays | ||
using IndirectArrays, MappedArrays, OrderedCollections | ||
using Test, FixedPointNumbers, Colors | ||
|
||
colors = [RGB(1,0,0) RGB(0,1,0); | ||
RGB(0,0,1) RGB(1,0,0)] | ||
index0 = [1 3; | ||
2 1] | ||
for indexT in (Int8, Int16, UInt8, UInt16) | ||
A = IndirectArray{indexT}(colors) | ||
@test eltype(A) == RGB{N0f8} | ||
@test size(A) == (2,2) | ||
@test ndims(A) == 2 | ||
@test A[1,1] === A[1] === RGB(1,0,0) | ||
@test A[2,1] === A[2] === RGB(0,0,1) | ||
@test A[1,2] === A[3] === RGB(0,1,0) | ||
@test A[2,2] === A[4] === RGB(1,0,0) | ||
@test isa(eachindex(A), AbstractUnitRange) | ||
@test A.index == index0 | ||
end | ||
x = IndirectArray(colors[:]) | ||
@test x == IndirectArray{UInt8}(colors[:]) | ||
xc = copy(x) | ||
@test x == xc | ||
xc[2], xc[3] = RGB(0,1,0), RGB(0,1,1) | ||
@test xc == IndirectArray([RGB(1,0,0), RGB(0,1,0), RGB(0,1,1), RGB(1,0,0)]) | ||
@test append!(x, x) == IndirectArray([colors[:]; colors[:]]) | ||
@test append!(x, IndirectArray([RGB(1,0,0), RGB(1,1,0)])) == | ||
IndirectArray([colors[:]; colors[:]; [RGB(1,0,0), RGB(1,1,0)]]) | ||
# Append with non-IndirectArray | ||
@test append!(IndirectArray(colors[:]), IndirectArray(colors[:])) == | ||
append!(IndirectArray(colors[:]), colors[:]) | ||
@testset "values::AbstractVector" begin | ||
colors = [RGB(1,0,0) RGB(0,1,0); | ||
RGB(0,0,1) RGB(1,0,0)] | ||
index0 = [1 3; | ||
2 1] | ||
for indexT in (Int8, Int16, UInt8, UInt16) | ||
A = IndirectArray{indexT}(colors) | ||
@test eltype(A) == RGB{N0f8} | ||
@test size(A) == (2,2) | ||
@test ndims(A) == 2 | ||
@test A[1,1] === A[1] === RGB(1,0,0) | ||
@test A[2,1] === A[2] === RGB(0,0,1) | ||
@test A[1,2] === A[3] === RGB(0,1,0) | ||
@test A[2,2] === A[4] === RGB(1,0,0) | ||
@test isa(eachindex(A), AbstractUnitRange) | ||
@test A.index == index0 | ||
end | ||
x = IndirectArray(colors[:]) | ||
@test x == IndirectArray{UInt8}(colors[:]) | ||
xc = copy(x) | ||
@test x == xc | ||
xc[2], xc[3] = RGB(0,1,0), RGB(0,1,1) | ||
@test xc == IndirectArray([RGB(1,0,0), RGB(0,1,0), RGB(0,1,1), RGB(1,0,0)]) | ||
@test append!(x, x) == IndirectArray([colors[:]; colors[:]]) | ||
@test append!(x, IndirectArray([RGB(1,0,0), RGB(1,1,0)])) == | ||
IndirectArray([colors[:]; colors[:]; [RGB(1,0,0), RGB(1,1,0)]]) | ||
# Append with non-IndirectArray | ||
@test append!(IndirectArray(colors[:]), IndirectArray(colors[:])) == | ||
append!(IndirectArray(colors[:]), colors[:]) | ||
|
||
# Bounds checking upon construction | ||
index_ob = copy(index0) | ||
index_ob[1] = 5 # out-of-bounds | ||
unsafe_ia(idx, vals) = (@inbounds ret = IndirectArray(idx, vals); ret) | ||
safe_ia(idx, vals) = (ret = IndirectArray(idx, vals); ret) | ||
@test_throws BoundsError safe_ia(index_ob, colors[1:3]) | ||
# This requires inlining, which means it fails on Travis since we turn | ||
# off inlining for better coverage stats | ||
# B = unsafe_ia(index_ob, colors) | ||
# @test_throws BoundsError B[1] | ||
# @test B[2] == RGB(0,0,1) | ||
|
||
# Bounds checking upon construction | ||
index_ob = copy(index0) | ||
index_ob[1] = 5 # out-of-bounds | ||
unsafe_ia(idx, vals) = (@inbounds ret = IndirectArray(idx, vals); ret) | ||
safe_ia(idx, vals) = (ret = IndirectArray(idx, vals); ret) | ||
@test_throws BoundsError safe_ia(index_ob, colors[1:3]) | ||
# This requires inlining, which means it fails on Travis since we turn | ||
# off inlining for better coverage stats | ||
# B = unsafe_ia(index_ob, colors) | ||
# @test_throws BoundsError B[1] | ||
# @test B[2] == RGB(0,0,1) | ||
# Non-Arrays | ||
a = [0.1 0.4; | ||
0.33 1.0] | ||
f(x) = round(Int, 99*x) + 1 # maps 0-1 to 1-100 | ||
m = mappedarray(f, a) | ||
cmap = colormap("RdBu", 100) | ||
img = IndirectArray(m, cmap) | ||
@test img == [cmap[11] cmap[41]; | ||
cmap[34] cmap[100]] | ||
end | ||
|
||
# Non-Arrays | ||
a = [0.1 0.4; | ||
0.33 1.0] | ||
f(x) = round(Int, 99*x) + 1 # maps 0-1 to 1-100 | ||
m = mappedarray(f, a) | ||
cmap = colormap("RdBu", 100) | ||
img = IndirectArray(m, cmap) | ||
@test img == [cmap[11] cmap[41]; | ||
cmap[34] cmap[100]] | ||
@testset "values::AbstractDict" begin | ||
# With Dicts | ||
a = ['a' 'b'; | ||
'q' 'j'] | ||
v = freeze(Dict('a' => "apple", 'b' => "book", 'q' => "quit", 'j' => "jolly")) | ||
A = IndirectArray(a, v) | ||
@test A[1,1] == "apple" | ||
@test A[2,1] == "quit" | ||
@test A[1,2] == "book" | ||
@test A[2,2] == "jolly" | ||
@test_throws BoundsError IndirectArray(a, Dict('a' => "apple", 'b' => "book")) | ||
end |
e5541f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
e5541f5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/43949
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: