Skip to content

Commit 217f706

Browse files
authored
Optimize for numpy builtin types (#209)
1 parent d95c29d commit 217f706

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

charm4py/charm.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ def packMsg(self, destObj, msgArgs, header):
381381
# memoryview, Python throws error: "memoryview: underlying buffer is not
382382
# C-contiguous", which seems to be a CPython error (not cffi related)
383383
nbytes = arg.nbytes
384-
direct_copy_hdr.append((i, 2, (arg.shape, arg.dtype.name), nbytes))
384+
if arg.dtype.isbuiltin:
385+
direct_copy_hdr.append((i, 2, (arg.shape, arg.dtype.char), nbytes))
386+
else:
387+
direct_copy_hdr.append((i, 2, (arg.shape, arg.dtype.name), nbytes))
385388
else:
386389
continue
387390
args[i] = None # will direct-copy this arg so remove from args list

charm4py/charmlib/charmlib_cython.pyx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,10 @@ class CharmLib(object):
791791
if isinstance(arg, np.ndarray) and not arg.dtype.hasobject:
792792
np_array = arg
793793
nbytes = np_array.nbytes
794-
direct_copy_hdr.append((i, 2, (arg.shape, np_array.dtype.name), nbytes))
794+
if arg.dtype.isbuiltin:
795+
direct_copy_hdr.append((i, 2, (arg.shape, arg.dtype.char), nbytes))
796+
else:
797+
direct_copy_hdr.append((i, 2, (arg.shape, arg.dtype.name), nbytes))
795798
send_bufs[cur_buf] = <char*>np_array.data
796799
elif isinstance(arg, bytes):
797800
nbytes = len(arg)

0 commit comments

Comments
 (0)