Skip to content

Commit

Permalink
Fixed #450, ufunc now converts python objects to bharrays
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Feb 21, 2018
1 parent c065854 commit 9c1cd39
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bridge/npbackend/bohrium/ufuncs.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class Ufunc(object):
if val is not None:
raise ValueError("Bohrium ufuncs doesn't support the '%s' argument" % str(k))

# Makes sure that `args` are either bohrium arrays or scalars
for i in range(len(args)):
if not np.isscalar(args[i]) and not bhary.check(args[i]):
args[i] = array_create.array(args[i])

# Broadcast the args
(bargs, out_shape) = broadcast_arrays(*args)

Expand Down
15 changes: 14 additions & 1 deletion test/python/tests/test_conversion.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import util
import sys


class test_conversion:
def init(self):
yield "a = M.arange(1);"
Expand All @@ -25,3 +25,16 @@ def test_hex(self, cmd):
def test_long(self, cmd):
cmd += "res = long(a);"
return cmd


class test_python_lists:
def init(self):
yield "a = [1,2,3,4]; b = M.arange(4); "

def test_add(self, cmd):
cmd += "res = a + b"
return cmd

def test_sum(self, cmd):
cmd += "res = M.sum(a)"
return cmd

0 comments on commit 9c1cd39

Please sign in to comment.