Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Support for Numpy >= 2.0 #652

Open
morales-gregorio opened this issue Dec 10, 2024 · 3 comments
Open

[Feature] Support for Numpy >= 2.0 #652

morales-gregorio opened this issue Dec 10, 2024 · 3 comments
Labels

Comments

@morales-gregorio
Copy link
Collaborator

Hi,

are there any plans to test and deploy support for NumPy >= 2.0 ? I have been using elephant with numpy 2.2 for some time now and there is a massive performance improvement. From the migration guide it seems not many errors will be raised by the change, in fact I did not encounter any errors so far.

Best,
Aitor

@Moritz-Alexander-Kern
Copy link
Member

Moritz-Alexander-Kern commented Dec 10, 2024

Hey @morales-gregorio ,

Thank you for your inquiry. Indeed, we are actively working on compatibility with Numpy 2.0.
For example PR #646 is a step towards compatibility, here we addressed the new behavior of the copy keyword with numpy 2.0, see also : https://numpy.org/doc/stable/release/2.0.0-notes.html#new-copy-keyword-meaning-for-array-and-asarray-constructors

However, there are dependencies that currently prevent us from fully supporting it.

Specifically, we had to wait for key fixes in python-quantities (support of numpy 2.0 with release 0.16.0 since Aug 27, 2024):

At present, we are still waiting for Neo to gain full compatibility with Numpy 2.0, which is being tracked in:

If you are currently using Numpy 2.0, please note that this is not officially supported yet. You may encounter unexpected behavior, as Elephant has not been tested with Numpy 2.0 so far.

Thank you for your understanding and patience.

@zm711
Copy link

zm711 commented Dec 13, 2024

Hey both we just merged Neo 1490 so we would love to know if anything is coming up on the downstream side. Just let us know :)

@penguinpee
Copy link

With numpy 2.2.0 and quantities 0.16.1, the following tests still fail:

=========================== short test summary info ============================
FAILED elephant/test/test_icsd.py::TestICSD::test_DeltaiCSD_00 - AssertionErr...
FAILED elephant/test/test_icsd.py::TestICSD::test_DeltaiCSD_01 - AssertionErr...
FAILED elephant/test/test_icsd.py::TestICSD::test_DeltaiCSD_02 - AssertionErr...
FAILED elephant/test/test_icsd.py::TestICSD::test_DeltaiCSD_03 - AssertionErr...
FAILED elephant/test/test_icsd.py::TestICSD::test_DeltaiCSD_04 - AssertionErr...
FAILED elephant/test/test_phase_analysis.py::SpikeTriggeredPhaseTestCase::test_perfect_locking_many_spiketrains_many_signals
FAILED elephant/test/test_phase_analysis.py::SpikeTriggeredPhaseTestCase::test_perfect_locking_many_spiketrains_one_signal
FAILED elephant/test/test_phase_analysis.py::SpikeTriggeredPhaseTestCase::test_perfect_locking_one_spiketrain_one_signal
FAILED elephant/test/test_phase_analysis.py::SpikeTriggeredPhaseTestCase::test_perfect_locking_one_spiketrains_many_signals
FAILED elephant/test/test_spectral.py::MultitaperCrossSpectrumTestCase::test_multitaper_cross_spectrum_behavior
FAILED elephant/test/test_spectral.py::MultitaperCoherenceTestCase::test_multitaper_coherence_input_types
= 11 failed, 691 passed, 3 skipped, 21 deselected, 3648 warnings in 951.42s (0:15:51) =
Full log ```python =================================== FAILURES =================================== __________________________ TestICSD.test_DeltaiCSD_00 __________________________

self = <elephant.test.test_icsd.TestICSD testMethod=test_DeltaiCSD_00>

def test_DeltaiCSD_00(self):
    """test using standard SI units"""
    # set some parameters for ground truth csd and csd estimates., e.g.,
    # we will use same source diameter as in ground truth

    # contact point coordinates
    z_j = np.arange(21) * 1E-4 * pq.m

    # source coordinates
    z_i = z_j

    # current source density magnitude
    C_i = np.zeros(z_i.size) * pq.A / pq.m**2
    C_i[7:12:2] += np.array([-.5, 1., -.5]) * pq.A / pq.m**2

    # source radius (delta, step)
    R_i = np.ones(z_i.size) * 1E-3 * pq.m

    # conductivity, use same conductivity for top layer (z_j < 0)
    sigma = 0.3 * pq.S / pq.m
    sigma_top = sigma

    # flag for debug plots
    plot = False

    # get LFP and CSD at contacts
    phi_j, C_i = get_lfp_of_disks(z_j, z_i, C_i, R_i, sigma,
                                  plot)
    delta_input = {
        'lfp': phi_j,
        'coord_electrode': z_j,
        'diam': R_i.mean() * 2,        # source diameter
        'sigma': sigma,           # extracellular conductivity
        'sigma_top': sigma_top,       # conductivity on top of cortex
        'f_type': 'gaussian',  # gaussian filter
        'f_order': (3, 1),     # 3-point filter, sigma = 1.
    }

    delta_icsd = icsd.DeltaiCSD(**delta_input)
    csd = delta_icsd.get_csd()
  self.assertEqual(C_i.units, csd.units)

E AssertionError: array(1.) * A/m2 != array(1.) * kg*m/(s3*A)

elephant/test/test_icsd.py:453: AssertionError
__________________________ TestICSD.test_DeltaiCSD_01 __________________________

self = <elephant.test.test_icsd.TestICSD testMethod=test_DeltaiCSD_01>

def test_DeltaiCSD_01(self):
    """test using non-standard SI units 1"""
    # set some parameters for ground truth csd and csd estimates., e.g.,
    # we will use same source diameter as in ground truth

    # contact point coordinates
    z_j = np.arange(21) * 1E-4 * pq.m

    # source coordinates
    z_i = z_j

    # current source density magnitude
    C_i = np.zeros(z_i.size) * pq.A / pq.m**2
    C_i[7:12:2] += np.array([-.5, 1., -.5]) * pq.A / pq.m**2

    # source radius (delta, step)
    R_i = np.ones(z_i.size) * 1E-3 * pq.m

    # conductivity, use same conductivity for top layer (z_j < 0)
    sigma = 0.3 * pq.S / pq.m
    sigma_top = sigma

    # flag for debug plots
    plot = False

    # get LFP and CSD at contacts
    phi_j, C_i = get_lfp_of_disks(z_j, z_i, C_i, R_i, sigma,
                                  plot)
    delta_input = {
        'lfp': phi_j * 1E3 * pq.mV / pq.V,
        'coord_electrode': z_j,
        'diam': R_i.mean() * 2,        # source diameter
        'sigma': sigma,           # extracellular conductivity
        'sigma_top': sigma_top,       # conductivity on top of cortex
        'f_type': 'gaussian',  # gaussian filter
        'f_order': (3, 1),     # 3-point filter, sigma = 1.
    }

    delta_icsd = icsd.DeltaiCSD(**delta_input)
    csd = delta_icsd.get_csd()
  self.assertEqual(C_i.units, csd.units)

E AssertionError: array(1.) * A/m2 != array(1.) * kg*m/(s3*A)

elephant/test/test_icsd.py:497: AssertionError
__________________________ TestICSD.test_DeltaiCSD_02 __________________________

self = <elephant.test.test_icsd.TestICSD testMethod=test_DeltaiCSD_02>

def test_DeltaiCSD_02(self):
    """test using non-standard SI units 2"""
    # set some parameters for ground truth csd and csd estimates., e.g.,
    # we will use same source diameter as in ground truth

    # contact point coordinates
    z_j = np.arange(21) * 1E-4 * pq.m

    # source coordinates
    z_i = z_j

    # current source density magnitude
    C_i = np.zeros(z_i.size) * pq.A / pq.m**2
    C_i[7:12:2] += np.array([-.5, 1., -.5]) * pq.A / pq.m**2

    # source radius (delta, step)
    R_i = np.ones(z_i.size) * 1E-3 * pq.m

    # conductivity, use same conductivity for top layer (z_j < 0)
    sigma = 0.3 * pq.S / pq.m
    sigma_top = sigma

    # flag for debug plots
    plot = False

    # get LFP and CSD at contacts
    phi_j, C_i = get_lfp_of_disks(z_j, z_i, C_i, R_i, sigma,
                                  plot)
    delta_input = {
        'lfp': phi_j,
        'coord_electrode': z_j * 1E3 * pq.mm / pq.m,
        'diam': R_i.mean() * 2 * 1E3 * pq.mm / pq.m,    # source diameter
        'sigma': sigma,           # extracellular conductivity
        'sigma_top': sigma_top,       # conductivity on top of cortex
        'f_type': 'gaussian',  # gaussian filter
        'f_order': (3, 1),     # 3-point filter, sigma = 1.
    }

    delta_icsd = icsd.DeltaiCSD(**delta_input)
    csd = delta_icsd.get_csd()
  self.assertEqual(C_i.units, csd.units)

E AssertionError: array(1.) * A/m2 != array(1.) * kg*m/(s3*A)

elephant/test/test_icsd.py:541: AssertionError
__________________________ TestICSD.test_DeltaiCSD_03 __________________________

self = <elephant.test.test_icsd.TestICSD testMethod=test_DeltaiCSD_03>

def test_DeltaiCSD_03(self):
    """test using non-standard SI units 3"""
    # set some parameters for ground truth csd and csd estimates., e.g.,
    # we will use same source diameter as in ground truth

    # contact point coordinates
    z_j = np.arange(21) * 1E-4 * pq.m

    # source coordinates
    z_i = z_j

    # current source density magnitude
    C_i = np.zeros(z_i.size) * pq.A / pq.m**2
    C_i[7:12:2] += np.array([-.5, 1., -.5]) * pq.A / pq.m**2

    # source radius (delta, step)
    R_i = np.ones(z_i.size) * 1E-3 * pq.m

    # conductivity, use same conductivity for top layer (z_j < 0)
    sigma = 0.3 * pq.S / pq.m
    sigma_top = sigma

    # flag for debug plots
    plot = False

    # get LFP and CSD at contacts
    phi_j, C_i = get_lfp_of_disks(z_j, z_i, C_i, R_i, sigma,
                                  plot)
    delta_input = {
        'lfp': phi_j,
        'coord_electrode': z_j,
        'diam': R_i.mean() * 2,        # source diameter
        'sigma': sigma * 1E3 * pq.mS / pq.S,  # extracellular conductivity
        'sigma_top': sigma_top * 1E3 * pq.mS / pq.S,  # conductivity on
                                                      # top of cortex
        'f_type': 'gaussian',  # gaussian filter
        'f_order': (3, 1),     # 3-point filter, sigma = 1.
    }

    delta_icsd = icsd.DeltaiCSD(**delta_input)
    csd = delta_icsd.get_csd()
  self.assertEqual(C_i.units, csd.units)

E AssertionError: array(1.) * A/m2 != array(1.) * kg*m/(s3*A)

elephant/test/test_icsd.py:586: AssertionError
__________________________ TestICSD.test_DeltaiCSD_04 __________________________

self = <elephant.test.test_icsd.TestICSD testMethod=test_DeltaiCSD_04>

def test_DeltaiCSD_04(self):
    """test non-continous z_j array"""
    # set some parameters for ground truth csd and csd estimates., e.g.,
    # we will use same source diameter as in ground truth

    # contact point coordinates
    z_j = np.arange(21) * 1E-4 * pq.m

    # source coordinates
    z_i = z_j

    # current source density magnitude
    C_i = np.zeros(z_i.size) * pq.A / pq.m**2
    C_i[7:12:2] += np.array([-.5, 1., -.5]) * pq.A / pq.m**2

    # source radius (delta, step)
    R_i = np.ones(z_j.size) * 1E-3 * pq.m

    # conductivity, use same conductivity for top layer (z_j < 0)
    sigma = 0.3 * pq.S / pq.m
    sigma_top = sigma

    # flag for debug plots
    plot = False

    # get LFP and CSD at contacts
    phi_j, C_i = get_lfp_of_disks(z_j, z_i, C_i, R_i, sigma,
                                  plot)
    inds = np.delete(np.arange(21), 5)
    delta_input = {
        'lfp': phi_j[inds],
        'coord_electrode': z_j[inds],
        'diam': R_i[inds] * 2,        # source diameter
        'sigma': sigma,           # extracellular conductivity
        'sigma_top': sigma_top,       # conductivity on top of cortex
        'f_type': 'gaussian',  # gaussian filter
        'f_order': (3, 1),     # 3-point filter, sigma = 1.
    }

    delta_icsd = icsd.DeltaiCSD(**delta_input)
    csd = delta_icsd.get_csd()
  self.assertEqual(C_i.units, csd.units)

E AssertionError: array(1.) * A/m2 != array(1.) * kg*m/(s3*A)

elephant/test/test_icsd.py:631: AssertionError
_ SpikeTriggeredPhaseTestCase.test_perfect_locking_many_spiketrains_many_signals _

self = array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(1998,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless, np.True_), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
      res._dimensionality = p_dict[uf](*objs)

E KeyError: <ufunc 'bitwise_and'>

/usr/lib/python3.13/site-packages/quantities/quantity.py:284: KeyError

During handling of the above exception, another exception occurred:

x = array([0.95134403, 0.97496865, 0.98322633, ..., 0.98740633, 0.98322633,
0.97496865], shape=(1998,)) * dimensionless
y = array(1)

def compare(x, y):
  return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
                                   equal_nan=equal_nan)

/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py:1673:


/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py:2447: in isclose
result = (less_equal(abs(x-y), atol + rtol * abs(y))
/usr/lib/python3.13/site-packages/quantities/quantity.py:304: in array_wrap
return self.array_prepare(obj, context)


self = array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(1998,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless, np.True_), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
        res._dimensionality = p_dict[uf](*objs)
    except KeyError:
      raise ValueError(
            """ufunc %r not supported by quantities
            please file a bug report at https://github.com/python-quantities
            """ % uf
            )

E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities

/usr/lib/python3.13/site-packages/quantities/quantity.py:286: ValueError

During handling of the above exception, another exception occurred:

self = <elephant.test.test_phase_analysis.SpikeTriggeredPhaseTestCase testMethod=test_perfect_locking_many_spiketrains_many_signals>

def test_perfect_locking_many_spiketrains_many_signals(self):
    phases, amps, times = elephant.phase_analysis.spike_triggered_phase(
        [
            elephant.signal_processing.hilbert(self.anasig0),
            elephant.signal_processing.hilbert(self.anasig0)],
        [self.st0, self.st0],
        interpolate=True)

    assert_allclose(phases[0], -np.pi / 2.)
  assert_allclose(amps[0], 1, atol=0.1)

E ValueError:
E error during assertion:
E
E Traceback (most recent call last):
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 284, in array_prepare
E res._dimensionality = p_dictuf
E ~~~~~~^^^^
E KeyError: <ufunc 'bitwise_and'>
E
E During handling of the above exception, another exception occurred:
E
E Traceback (most recent call last):
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 814, in assert_array_compare
E val = comparison(x, y)
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 1673, in compare
E return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
E ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E equal_nan=equal_nan)
E ^^^^^^^^^^^^^^^^^^^^
E File "/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py", line 2447, in isclose
E result = (less_equal(abs(x-y), atol + rtol * abs(y))
E ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E & isfinite(y)
E ^~~~~~~~~~~~~
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 304, in array_wrap
E return self.array_prepare(obj, context)
E ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 286, in array_prepare
E raise ValueError(
E ...<3 lines>...
E )
E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities
E
E
E
E Not equal to tolerance rtol=1e-07, atol=0.1
E ACTUAL: Quantity([0.951344, 0.974969, 0.983226, ..., 0.987406, 0.983226, 0.974969],
E shape=(1998,))
E DESIRED: array(1)

elephant/test/test_phase_analysis.py:63: ValueError
_ SpikeTriggeredPhaseTestCase.test_perfect_locking_many_spiketrains_one_signal _

self = array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(1998,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless, np.True_), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
      res._dimensionality = p_dict[uf](*objs)

E KeyError: <ufunc 'bitwise_and'>

/usr/lib/python3.13/site-packages/quantities/quantity.py:284: KeyError

During handling of the above exception, another exception occurred:

x = array([0.95134403, 0.97496865, 0.98322633, ..., 0.98740633, 0.98322633,
0.97496865], shape=(1998,)) * dimensionless
y = array(1)

def compare(x, y):
  return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
                                   equal_nan=equal_nan)

/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py:1673:


/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py:2447: in isclose
result = (less_equal(abs(x-y), atol + rtol * abs(y))
/usr/lib/python3.13/site-packages/quantities/quantity.py:304: in array_wrap
return self.array_prepare(obj, context)


self = array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(1998,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless, np.True_), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
        res._dimensionality = p_dict[uf](*objs)
    except KeyError:
      raise ValueError(
            """ufunc %r not supported by quantities
            please file a bug report at https://github.com/python-quantities
            """ % uf
            )

E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities

/usr/lib/python3.13/site-packages/quantities/quantity.py:286: ValueError

During handling of the above exception, another exception occurred:

self = <elephant.test.test_phase_analysis.SpikeTriggeredPhaseTestCase testMethod=test_perfect_locking_many_spiketrains_one_signal>

def test_perfect_locking_many_spiketrains_one_signal(self):
    phases, amps, times = elephant.phase_analysis.spike_triggered_phase(
        elephant.signal_processing.hilbert(self.anasig0),
        [self.st0, self.st0],
        interpolate=True)

    assert_allclose(phases[0], -np.pi / 2.)
  assert_allclose(amps[0], 1, atol=0.1)

E ValueError:
E error during assertion:
E
E Traceback (most recent call last):
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 284, in array_prepare
E res._dimensionality = p_dictuf
E ~~~~~~^^^^
E KeyError: <ufunc 'bitwise_and'>
E
E During handling of the above exception, another exception occurred:
E
E Traceback (most recent call last):
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 814, in assert_array_compare
E val = comparison(x, y)
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 1673, in compare
E return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
E ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E equal_nan=equal_nan)
E ^^^^^^^^^^^^^^^^^^^^
E File "/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py", line 2447, in isclose
E result = (less_equal(abs(x-y), atol + rtol * abs(y))
E ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E & isfinite(y)
E ^~~~~~~~~~~~~
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 304, in array_wrap
E return self.array_prepare(obj, context)
E ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 286, in array_prepare
E raise ValueError(
E ...<3 lines>...
E )
E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities
E
E
E
E Not equal to tolerance rtol=1e-07, atol=0.1
E ACTUAL: Quantity([0.951344, 0.974969, 0.983226, ..., 0.987406, 0.983226, 0.974969],
E shape=(1998,))
E DESIRED: array(1)

elephant/test/test_phase_analysis.py:91: ValueError
__ SpikeTriggeredPhaseTestCase.test_perfect_locking_one_spiketrain_one_signal __

self = array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(1998,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless, np.True_), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
      res._dimensionality = p_dict[uf](*objs)

E KeyError: <ufunc 'bitwise_and'>

/usr/lib/python3.13/site-packages/quantities/quantity.py:284: KeyError

During handling of the above exception, another exception occurred:

x = array([0.95134403, 0.97496865, 0.98322633, ..., 0.98740633, 0.98322633,
0.97496865], shape=(1998,)) * dimensionless
y = array(1)

def compare(x, y):
  return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
                                   equal_nan=equal_nan)

/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py:1673:


/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py:2447: in isclose
result = (less_equal(abs(x-y), atol + rtol * abs(y))
/usr/lib/python3.13/site-packages/quantities/quantity.py:304: in array_wrap
return self.array_prepare(obj, context)


self = array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(1998,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless, np.True_), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
        res._dimensionality = p_dict[uf](*objs)
    except KeyError:
      raise ValueError(
            """ufunc %r not supported by quantities
            please file a bug report at https://github.com/python-quantities
            """ % uf
            )

E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities

/usr/lib/python3.13/site-packages/quantities/quantity.py:286: ValueError

During handling of the above exception, another exception occurred:

self = <elephant.test.test_phase_analysis.SpikeTriggeredPhaseTestCase testMethod=test_perfect_locking_one_spiketrain_one_signal>

def test_perfect_locking_one_spiketrain_one_signal(self):
    phases, amps, times = elephant.phase_analysis.spike_triggered_phase(
        elephant.signal_processing.hilbert(self.anasig0),
        self.st0,
        interpolate=True)

    assert_allclose(phases[0], - np.pi / 2.)
  assert_allclose(amps[0], 1, atol=0.1)

E ValueError:
E error during assertion:
E
E Traceback (most recent call last):
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 284, in array_prepare
E res._dimensionality = p_dictuf
E ~~~~~~^^^^
E KeyError: <ufunc 'bitwise_and'>
E
E During handling of the above exception, another exception occurred:
E
E Traceback (most recent call last):
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 814, in assert_array_compare
E val = comparison(x, y)
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 1673, in compare
E return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
E ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E equal_nan=equal_nan)
E ^^^^^^^^^^^^^^^^^^^^
E File "/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py", line 2447, in isclose
E result = (less_equal(abs(x-y), atol + rtol * abs(y))
E ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E & isfinite(y)
E ^~~~~~~~~~~~~
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 304, in array_wrap
E return self.array_prepare(obj, context)
E ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 286, in array_prepare
E raise ValueError(
E ...<3 lines>...
E )
E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities
E
E
E
E Not equal to tolerance rtol=1e-07, atol=0.1
E ACTUAL: Quantity([0.951344, 0.974969, 0.983226, ..., 0.987406, 0.983226, 0.974969],
E shape=(1998,))
E DESIRED: array(1)

elephant/test/test_phase_analysis.py:48: ValueError
_ SpikeTriggeredPhaseTestCase.test_perfect_locking_one_spiketrains_many_signals _

self = array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(1998,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless, np.True_), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
      res._dimensionality = p_dict[uf](*objs)

E KeyError: <ufunc 'bitwise_and'>

/usr/lib/python3.13/site-packages/quantities/quantity.py:284: KeyError

During handling of the above exception, another exception occurred:

x = array([0.95134403, 0.97496865, 0.98322633, ..., 0.98740633, 0.98322633,
0.97496865], shape=(1998,)) * dimensionless
y = array(1)

def compare(x, y):
  return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
                                   equal_nan=equal_nan)

/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py:1673:


/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py:2447: in isclose
result = (less_equal(abs(x-y), atol + rtol * abs(y))
/usr/lib/python3.13/site-packages/quantities/quantity.py:304: in array_wrap
return self.array_prepare(obj, context)


self = array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(1998,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(1998,)) * dimensionless, np.True_), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
        res._dimensionality = p_dict[uf](*objs)
    except KeyError:
      raise ValueError(
            """ufunc %r not supported by quantities
            please file a bug report at https://github.com/python-quantities
            """ % uf
            )

E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities

/usr/lib/python3.13/site-packages/quantities/quantity.py:286: ValueError

During handling of the above exception, another exception occurred:

self = <elephant.test.test_phase_analysis.SpikeTriggeredPhaseTestCase testMethod=test_perfect_locking_one_spiketrains_many_signals>

def test_perfect_locking_one_spiketrains_many_signals(self):
    phases, amps, times = elephant.phase_analysis.spike_triggered_phase(
        [
            elephant.signal_processing.hilbert(self.anasig0),
            elephant.signal_processing.hilbert(self.anasig0)],
        [self.st0],
        interpolate=True)

    assert_allclose(phases[0], -np.pi / 2.)
  assert_allclose(amps[0], 1, atol=0.1)

E ValueError:
E error during assertion:
E
E Traceback (most recent call last):
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 284, in array_prepare
E res._dimensionality = p_dictuf
E ~~~~~~^^^^
E KeyError: <ufunc 'bitwise_and'>
E
E During handling of the above exception, another exception occurred:
E
E Traceback (most recent call last):
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 814, in assert_array_compare
E val = comparison(x, y)
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 1673, in compare
E return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
E ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E equal_nan=equal_nan)
E ^^^^^^^^^^^^^^^^^^^^
E File "/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py", line 2447, in isclose
E result = (less_equal(abs(x-y), atol + rtol * abs(y))
E ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E & isfinite(y)
E ^~~~~~~~~~~~~
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 304, in array_wrap
E return self.array_prepare(obj, context)
E ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 286, in array_prepare
E raise ValueError(
E ...<3 lines>...
E )
E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities
E
E
E
E Not equal to tolerance rtol=1e-07, atol=0.1
E ACTUAL: Quantity([0.951344, 0.974969, 0.983226, ..., 0.987406, 0.983226, 0.974969],
E shape=(1998,))
E DESIRED: array(1)

elephant/test/test_phase_analysis.py:78: ValueError
___ MultitaperCrossSpectrumTestCase.test_multitaper_cross_spectrum_behavior ____

self = <elephant.test.test_spectral.MultitaperCrossSpectrumTestCase testMethod=test_multitaper_cross_spectrum_behavior>

def test_multitaper_cross_spectrum_behavior(self):
    # generate data (frequency domain to time domain)
    r = np.ones(2501) * 0.2
    r[0], r[500] = 0, 10  # Zero DC, peak at 100 Hz
    phi_x = np.random.uniform(-np.pi, np.pi, len(r))
    phi_y = np.random.uniform(-np.pi, np.pi, len(r))
    fake_coeffs_x = r*np.exp(1j * phi_x)
    fake_coeffs_y = r*np.exp(1j * phi_y)
    signal_x = scipy.fft.irfft(fake_coeffs_x)
    signal_y = scipy.fft.irfft(fake_coeffs_y)
    sampling_period = 0.001
    freqs = scipy.fft.rfftfreq(len(signal_x), d=sampling_period)
    signal_freq = freqs[r.argmax()]
    data = AnalogSignal(np.vstack([signal_x, signal_y]).T,
                        sampling_period=sampling_period * pq.s,
                        units='mV')

    # consistency between different ways of specifying number of tapers
    freqs1, cross_spec1 = \
        elephant.spectral.multitaper_cross_spectrum(
                data,
                fs=data.sampling_rate,
                nw=3.5)
    freqs2, cross_spec2 = \
        elephant.spectral.multitaper_cross_spectrum(
                data,
                fs=data.sampling_rate,
                nw=3.5,
                num_tapers=6)
    self.assertTrue((cross_spec1 == cross_spec2).all()
                    and (freqs1 == freqs2).all())

    # peak resolution and consistency with data
    peak_res = 1.0 * pq.Hz
    freqs, cross_spec = \
        elephant.spectral.multitaper_cross_spectrum(
                data, peak_resolution=peak_res)

    self.assertEqual(freqs[cross_spec[0, 0].argmax()], signal_freq)
    freqs_np, cross_spec_np = \
        elephant.spectral.multitaper_cross_spectrum(
                data.magnitude.T, fs=1 / sampling_period,
                peak_resolution=peak_res)
  self.assertTrue((freqs == freqs_np).all()
                    and (cross_spec == cross_spec_np).all())

E AssertionError: np.False_ is not true

elephant/test/test_spectral.py:572: AssertionError
______ MultitaperCoherenceTestCase.test_multitaper_coherence_input_types _______

self = array([ True, True, True, ..., True, True, True], shape=(5001,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(5001,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(5001,)) * dimensionless, array([ True, True, True, ..., True, True, True], shape=(5001,))), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
      res._dimensionality = p_dict[uf](*objs)

E KeyError: <ufunc 'bitwise_and'>

/usr/lib/python3.13/site-packages/quantities/quantity.py:284: KeyError

During handling of the above exception, another exception occurred:

x = array([0.00078479, 0.12790765, 0.12810887, ..., 0.19397819, 0.189415 ,
0.27107906], shape=(5001,), dtype=float32)
y = array([0.00078479, 0.12790765, 0.12810889, ..., 0.19397822, 0.18941501,
0.27107905], shape=(5001,)) * dimensionless

def compare(x, y):
  return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
                                   equal_nan=equal_nan)

/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py:1673:


/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py:2447: in isclose
result = (less_equal(abs(x-y), atol + rtol * abs(y))
/usr/lib/python3.13/site-packages/quantities/quantity.py:304: in array_wrap
return self.array_prepare(obj, context)


self = array([ True, True, True, ..., True, True, True], shape=(5001,)) * dimensionless
obj = array([ True, True, True, ..., True, True, True], shape=(5001,))
context = (<ufunc 'bitwise_and'>, (array([ True, True, True, ..., True, True, True], shape=(5001,)) * dimensionless, array([ True, True, True, ..., True, True, True], shape=(5001,))), 0)

def __array_prepare__(self, obj, context=None):
    if self.__array_priority__ >= Quantity.__array_priority__:
        res = obj if isinstance(obj, type(self)) else obj.view(type(self))
    else:
        # don't want a UnitQuantity
        res = obj.view(Quantity)
    if context is None:
        return res

    uf, objs, huh = context
    if uf.__name__.startswith('is'):
        return obj

    try:
        res._dimensionality = p_dict[uf](*objs)
    except KeyError:
      raise ValueError(
            """ufunc %r not supported by quantities
            please file a bug report at https://github.com/python-quantities
            """ % uf
            )

E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities

/usr/lib/python3.13/site-packages/quantities/quantity.py:286: ValueError

During handling of the above exception, another exception occurred:

self = <elephant.test.test_spectral.MultitaperCoherenceTestCase testMethod=test_multitaper_coherence_input_types>

def test_multitaper_coherence_input_types(self):
    # Generate dummy data
    data_length = 10000
    sampling_period = 0.001
    signal_freq = 100.0
    np.random.seed(123)
    noise = np.random.normal(size=(2, data_length))
    time_points = np.arange(0, data_length * sampling_period,
                            sampling_period)
    # Signals are designed to have coherence peak at `signal_freq`
    arr_signal_i = np.sin(2 * np.pi * signal_freq * time_points) + noise[0]
    arr_signal_j = np.cos(2 * np.pi * signal_freq * time_points) + noise[1]

    fs = 1000 * pq.Hz
    anasig_signal_i = neo.core.AnalogSignal(arr_signal_i,
                                            sampling_rate=fs,
                                            units=pq.mV)
    anasig_signal_j = neo.core.AnalogSignal(arr_signal_j,
                                            sampling_rate=fs,
                                            units=pq.mV)

    arr_f, arr_coh, arr_phi = elephant.spectral.multitaper_coherence(
        arr_signal_i, arr_signal_j, fs=fs)
    anasig_f, anasig_coh, anasig_phi = \
        elephant.spectral.multitaper_coherence(anasig_signal_i,
                                               anasig_signal_j)

    np.testing.assert_array_equal(arr_f, anasig_f)
  np.testing.assert_allclose(arr_coh, anasig_coh, atol=1e-6)

E ValueError:
E error during assertion:
E
E Traceback (most recent call last):
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 284, in array_prepare
E res._dimensionality = p_dictuf
E ~~~~~~^^^^
E KeyError: <ufunc 'bitwise_and'>
E
E During handling of the above exception, another exception occurred:
E
E Traceback (most recent call last):
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 814, in assert_array_compare
E val = comparison(x, y)
E File "/usr/lib64/python3.13/site-packages/numpy/testing/_private/utils.py", line 1673, in compare
E return np._core.numeric.isclose(x, y, rtol=rtol, atol=atol,
E ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E equal_nan=equal_nan)
E ^^^^^^^^^^^^^^^^^^^^
E File "/usr/lib64/python3.13/site-packages/numpy/_core/numeric.py", line 2447, in isclose
E result = (less_equal(abs(x-y), atol + rtol * abs(y))
E ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
E & isfinite(y)
E ^~~~~~~~~~~~~
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 304, in array_wrap
E return self.array_prepare(obj, context)
E ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
E File "/usr/lib/python3.13/site-packages/quantities/quantity.py", line 286, in array_prepare
E raise ValueError(
E ...<3 lines>...
E )
E ValueError: ufunc <ufunc 'bitwise_and'> not supported by quantities
E please file a bug report at https://github.com/python-quantities
E
E
E
E Not equal to tolerance rtol=1e-07, atol=1e-06
E ACTUAL: array([0.000785, 0.127908, 0.128109, ..., 0.193978, 0.189415, 0.271079],
E shape=(5001,), dtype=float32)
E DESIRED: Quantity([0.000785, 0.127908, 0.128109, ..., 0.193978, 0.189415, 0.271079],
E shape=(5001,))

elephant/test/test_spectral.py:932: ValueError

</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants