Skip to content

Commit

Permalink
Merge pull request xsuite#134 from xsuite/release/v0.4.1
Browse files Browse the repository at this point in the history
Release/v0.4.1
  • Loading branch information
szymonlopaciuk authored Apr 22, 2024
2 parents 0af4bf1 + 48aacf9 commit 1edc1b4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion xobjects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@

from .general import _print

from .test_helpers import assert_allclose
from .general import assert_allclose

from ._version import __version__
2 changes: 1 addition & 1 deletion xobjects/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.0"
__version__ = "0.4.1"
15 changes: 15 additions & 0 deletions xobjects/general.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# copyright ################################# #
# This file is part of the Xobjects Package. #
# Copyright (c) CERN, 2024. #
# ########################################### #
from numpy.testing import assert_allclose as np_assert_allclose


class Print:
suppress = False

Expand All @@ -7,3 +14,11 @@ def __call__(self, *args, **kwargs):


_print = Print()


def assert_allclose(a, b, rtol=1e-7, atol=1e-7):
if hasattr(a, "get"):
a = a.get()
if hasattr(b, "get"):
b = b.get()
np_assert_allclose(a, b, rtol=rtol, atol=atol)
10 changes: 7 additions & 3 deletions xobjects/hybrid_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ def __set__(self, container, value):
# in the latter case reference mechanism is used)
if not (
container._xobject._buffer is value._xobject._buffer
and (getattr(container._xobject, self.name) is not None and
getattr(container._xobject, self.name)._offset == value._xobject._offset)
and (
getattr(container._xobject, self.name) is not None
and getattr(container._xobject, self.name)._offset
== value._xobject._offset
)
):
setattr(container._xobject, self.name, value._xobject)

Expand Down Expand Up @@ -324,7 +327,8 @@ def _static_from_dict(cls, dct, _context=None, _buffer=None, _offset=None):

@classmethod
def from_dict(cls, dct, _context=None, _buffer=None, _offset=None):
return HybridClass._static_from_dict(cls,
return HybridClass._static_from_dict(
cls,
dct,
_context=_context,
_buffer=_buffer,
Expand Down
8 changes: 0 additions & 8 deletions xobjects/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from functools import wraps
from typing import Callable, Iterable, Union
from numpy.testing import assert_allclose as np_assert_allclose

import pytest

Expand Down Expand Up @@ -84,10 +83,3 @@ def requires_context(context_name: str):
return lambda test_function: test_function

return pytest.mark.skip(f"{context_name} is unavailable on this platform.")

def assert_allclose(a, b, rtol=1e-7, atol=1e-7):
if hasattr(a, 'get'):
a = a.get()
if hasattr(b, 'get'):
b = b.get()
np_assert_allclose(a, b, rtol=rtol, atol=atol)

0 comments on commit 1edc1b4

Please sign in to comment.