Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement DataAPI #24

Merged
merged 5 commits into from
Dec 20, 2019
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ os:
- osx

julia:
- "0.7"
- "1.0"
- "1.1"
- "nightly"
Expand Down
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ name = "PooledArrays"
uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720"
version = "0.5.2"

[deps]
DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"

[compat]
julia = "0.7, 1"
DataAPI = "1"
julia = "1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add to bump here as DataAPI requires julia 1.0 at least.


[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
6 changes: 6 additions & 0 deletions src/PooledArrays.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module PooledArrays

import DataAPI

export PooledArray, PooledVector, PooledMatrix

##############################################################################
Expand Down Expand Up @@ -137,6 +139,10 @@ PooledArray(t::Type, r::Type) = PooledArray(Array(t,0), r)
##
##############################################################################

DataAPI.refarray(pa::PooledArray) = pa.refs
DataAPI.refvalue(pa::PooledArray, i) = pa.pool[i]
nalimilan marked this conversation as resolved.
Show resolved Hide resolved
DataAPI.refpool(pa::PooledArray) = pa.pool

Base.size(pa::PooledArray) = size(pa.refs)
Base.length(pa::PooledArray) = length(pa.refs)
Base.lastindex(pa::PooledArray) = lastindex(pa.refs)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Test
using PooledArrays
using DataAPI: refarray, refvalue, refpool

let a = rand(10), b = rand(10,10), c = rand(1:10, 1000)
@test PooledArray(a) == a
Expand Down Expand Up @@ -68,4 +69,11 @@ let a = rand(10), b = rand(10,10), c = rand(1:10, 1000)
@test eltype(PooledArray(rand(300)).refs) == UInt16
@test PooledVector == PooledArray{T, R, 1} where {T, R}
@test PooledMatrix == PooledArray{T, R, 2} where {T, R}

s = PooledArray(["a", "a", "b"])
@test all(refarray(s) .== [1, 1, 2])
for i in 1:3
@test refvalue(s, refarray(s)[i]) == s[i]
end
@test refpool(s) == ["a", "b"]
end