Repository: Suzhou-Tongyuan/jnumpy (language: python)

Issue:
Boolean array support



Discussion / hints:
@songjhaha 

Fix patch:
diff --git a/TyPython/src/CPython.Julia.jl b/TyPython/src/CPython.Julia.jl
index 06f04d7..47dd807 100644
--- a/TyPython/src/CPython.Julia.jl
+++ b/TyPython/src/CPython.Julia.jl
@@ -51,6 +51,10 @@ function get_perm(x::PermutedDimsArray{T, N, perm}) where {T, N, perm}
     return perm .- 1
 end
 
+function get_typekind(_::Bool)
+    return Cchar('b')
+end
+
 function get_typekind(_::Union{Int8, Int16, Int32, Int64})
     return Cchar('i')
 end
diff --git a/TyPython/src/CPython.NumPy.jl b/TyPython/src/CPython.NumPy.jl
index 6245f5d..5fe8e43 100644
--- a/TyPython/src/CPython.NumPy.jl
+++ b/TyPython/src/CPython.NumPy.jl
@@ -42,7 +42,7 @@ function get_numpy()
     return G_numpy
 end
 
-const supported_kinds = Cchar['i', 'u', 'f', 'c']
+const supported_kinds = Cchar['b', 'i', 'u', 'f', 'c']
 
 const SupportedNDim = 32  # hard coded in numpy
 const ShapeType = Union{(Tuple{repeat([Py_intptr_t], i)...} for i = 0:SupportedNDim)...}
@@ -108,6 +108,9 @@ function from_ndarray(x::Py)
     end
 
     arr = @switch (Char(info.typekind), Int(info.itemsize)) begin
+        @case ('b', 1)
+            register_root(x,
+                unsafe_wrap(Array, convert(Ptr{Bool}, info.data), shape; own=false))
         @case ('i', 1)
             register_root(x,
                 unsafe_wrap(Array, convert(Ptr{Int8}, info.data), shape; own=false))


Test patch:
diff --git a/TyPython/test/convert.jl b/TyPython/test/convert.jl
index 7b34c55..a421704 100644
--- a/TyPython/test/convert.jl
+++ b/TyPython/test/convert.jl
@@ -167,6 +167,11 @@ end
         e = np.random.random(py_cast(Py, (1, 10, 1, 1)))
         @test py_cast(AbstractArray, e) isa Array
     end
+    @testset "bool array" begin
+        f = rand(Bool, 2, 2)
+        py_f = py_cast(Py, f)
+        @test py_f.dtype == np.dtype(py_cast(Py, "bool"))
+    end
     @test_throws CPython.PyException py_cast(Array, py_cast(Py, "abc"))
 end
 
diff --git a/jnumpy/tests/test_core.py b/jnumpy/tests/test_core.py
index e4c8ac6..d2901ef 100644
--- a/jnumpy/tests/test_core.py
+++ b/jnumpy/tests/test_core.py
@@ -57,8 +57,15 @@ def test_mat_mul(dtype):
     y = np.asarray([[7.8, 5e-3], [6.75, 8.234]], dtype=dtype)
     actual = mat_mul(x, y)
     desired = x @ y
+    assert actual.dtype == desired.dtype
     np.testing.assert_array_almost_equal(actual, desired, decimal=5)
 
+def test_bool_array():
+    x = np.asarray([[True, False], [True, False]])
+    x_int = x.astype('i')
+    actual = mat_mul(x, x)
+    desired = x_int @ x_int
+    assert np.all(actual == desired)
 
 def test_set_zero():
     x = np.random.rand(2)