Skip to content

Commit

Permalink
Updated rapidjson & python-rapidjson
Browse files Browse the repository at this point in the history
More pruning of empty paths
Remove uses of float_ and complex_ for numpy > 2.0
  • Loading branch information
langmm committed Jun 18, 2024
1 parent 808b566 commit 44671d7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
7 changes: 5 additions & 2 deletions tests/serialize/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

unsupported_nptype = ['bool_']
map_nptype2cformat = [
(['float_', 'float16', 'float32', 'float64'], '%g'),
(['complex_', 'complex64', 'complex128'], '%g%+gj'),
(['float16', 'float32', 'float64'], '%g'),
(['complex64', 'complex128'], '%g%+gj'),
# (['int8', 'short', 'intc', 'int_', 'longlong'], '%d'),
# (['uint8', 'ushort', 'uintc', 'uint64', 'ulonglong'], '%u'),
('int8', '%hhd'), ('short', '%hd'), ('intc', '%d'),
Expand All @@ -18,6 +18,9 @@
else:
map_nptype2cformat.append(('int64', '%ld'))
map_nptype2cformat.append(('uint64', '%lu'))
if not platform._numpy2:
map_nptype2cformat.append(('float_', '%g'))
map_nptype2cformat.append(('complex_', '%g%+gj'))
# Conditional on if default int 32bit or 64bit
# This is for when default int is 32bit
if np.dtype('int_') != np.dtype('intc'):
Expand Down
19 changes: 12 additions & 7 deletions utils/setup_test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,13 +1412,18 @@ def preinstall_deps(method, param=None, return_commands=False,
if param.conda_env:
conda_prefix = os.path.join(conda_root, 'envs',
param.conda_env)
# Do both to ensure that the path is set for the installation
# and in following steps
cmds += [
f"export LD_LIBRARY_PATH={conda_prefix}/lib:$LD_LIBRARY_PATH",
"echo -n \"LD_LIBRARY_PATH=\" >> $GITHUB_ENV",
f"echo {conda_prefix}/lib:$LD_LIBRARY_PATH >> $GITHUB_ENV"
]
conda_libdir = os.path.join(conda_prefix, 'lib')
existing_paths = os.environ.get('LD_LIBRARY_PATH', '').split(os.pathsep)
if conda_libdir not in existing_paths:
if existing_paths:
conda_libdir += os.pathsep + "$LD_LIBRARY_PATH"
# Do both to ensure that the path is set for the installation
# and in following steps
cmds += [
f"export LD_LIBRARY_PATH={conda_libdir}",
"echo -n \"LD_LIBRARY_PATH=\" >> $GITHUB_ENV",
f"echo {conda_libdir} >> $GITHUB_ENV"
]
if return_commands:
return cmds
if cmds:
Expand Down
2 changes: 1 addition & 1 deletion yggdrasil/drivers/CompiledModelDriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -3552,7 +3552,7 @@ def _shared_path_env(self, to_update=None, out=None,
prev_path_list += prev_path.split(os.pathsep)
path_list.append(prev_path)
for x in paths_to_add:
if x not in prev_path_list:
if x and x not in prev_path_list:
if add_to_front:
path_list.insert(0, x)
else:
Expand Down
2 changes: 2 additions & 0 deletions yggdrasil/platform.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
r"""This module handle platform compatibility issues."""
import sys
import numpy as np


_is_64bit = (sys.maxsize > 2**32)
_is_mac = (sys.platform == 'darwin')
_is_linux = ('linux' in sys.platform)
_is_win = (sys.platform in ['win32', 'cygwin'])
_supported_platforms = ['Windows', 'MacOS', 'Linux']
_numpy2 = (np.lib.NumpyVersion(np.__version__) >= '2.0.0b1')

if _is_win: # pragma: windows
_newline = b'\r\n'
Expand Down
2 changes: 1 addition & 1 deletion yggdrasil/python-rapidjson
2 changes: 1 addition & 1 deletion yggdrasil/rapidjson
6 changes: 4 additions & 2 deletions yggdrasil/serialize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ def nptype2cformat(nptype, asbytes=False):
if len(t) > 0:
out = [nptype2cformat(t[n], asbytes=asbytes) for n in t.names]
return out
if t in [np.dtype(x) for x in ["float_", "float16", "float32", "float64"]]:
if t in ([np.dtype(x) for x in ["float16", "float32", "float64"]]
or ((not platform._numpy2) and (t == np.dtype("float_")))):
cfmt = "%g" # Ensures readability
elif t in [np.dtype(x) for x in ["complex_", "complex64", "complex128"]]:
elif t in ([np.dtype(x) for x in ["complex64", "complex128"]]
or ((not platform._numpy2) and (t == np.dtype("complex_")))):
cfmt = "%g%+gj"
elif t == np.dtype("int8"):
cfmt = "%hhd"
Expand Down

0 comments on commit 44671d7

Please sign in to comment.