Skip to content

Commit

Permalink
add BitArray conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Apr 23, 2016
1 parent 6e42b1d commit eb8d70a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/conversions.jl
Expand Up @@ -200,7 +200,7 @@ end
"""
PyVector(o::PyObject)
This returns a PyVector object, which is a wrapper around an arbitrary Python list or sequence object.
This returns a PyVector object, which is a wrapper around an arbitrary Python list or sequence object.
Alternatively, `PyVector` can be used as the return type for a `pycall` that returns a sequence object (including tuples).
"""
Expand Down Expand Up @@ -381,6 +381,8 @@ end
convert(::Type{Array}, o::PyObject) = py2array(PyAny, o)
convert{T}(::Type{Array{T}}, o::PyObject) = py2array(T, o)

PyObject(a::BitArray) = PyObject(Array(a))

# NumPy conversions (multidimensional arrays)
include("numpy.jl")

Expand All @@ -393,7 +395,7 @@ include("numpy.jl")
This returns a PyDict, which is a no-copy wrapper around a Python dictionary.
Alternatively, you can specify the return type of a `pycall` as PyDict.
Alternatively, you can specify the return type of a `pycall` as PyDict.
"""
type PyDict{K,V} <: Associative{K,V}
o::PyObject
Expand Down
5 changes: 2 additions & 3 deletions src/numpy.jl
Expand Up @@ -202,9 +202,8 @@ function PyObject{T<:NPY_TYPES}(a::StridedArray{T})
end
end

function PyReverseDims{T<:NPY_TYPES}(a::StridedArray{T})
return NpyArray(a, true)
end
PyReverseDims{T<:NPY_TYPES}(a::StridedArray{T}) = NpyArray(a, true)
PyReverseDims(a::BitArray) = PyReverseDims(Array(a))

"""
PyReverseDims(array)
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Expand Up @@ -54,12 +54,14 @@ testkw(x; y=0) = x + 2*y

if PyCall.npy_initialized
@test PyArray(PyObject([1. 2 3;4 5 6])) == [1. 2 3;4 5 6]
let A = rand(Int, 2,3,4)
let A = rand(Int, 2,3,4), B = rand(Bool, 2,3,4)
@test convert(PyAny, PyReverseDims(A)) == permutedims(A, [3,2,1])
@test convert(PyAny, PyReverseDims(BitArray(B))) == permutedims(B, [3,2,1])
end
end
@test PyVector(PyObject([1,3.2,"hello",true])) == [1,3.2,"hello",true]
@test PyDict(PyObject(Dict(1 => "hello", 2 => "goodbye"))) == Dict(1 => "hello", 2 => "goodbye")
@test roundtripeq(BitArray([true, false, true, true]))

let d = PyDict(Dict(1 => "hello", 34 => "yes" ))
@test get(d.o, 1) == "hello"
Expand Down

0 comments on commit eb8d70a

Please sign in to comment.