Example #1
0
def test_unit_discarding_functions():
    '''
    Test functions that discard units.
    '''
    from brian2.units.unitsafefunctions import zeros_like, ones_like

    values = [3 * mV, np.array([1, 2]) * mV, np.arange(12).reshape(3, 4) * mV]
    for value in values:
        assert_equal(np.sign(value), np.sign(np.asarray(value)))
        assert_equal(zeros_like(value), np.zeros_like(np.asarray(value)))
        assert_equal(ones_like(value), np.ones_like(np.asarray(value)))
        assert_equal(np.nonzero(value), np.nonzero(np.asarray(value)))
Example #2
0
def test_unit_discarding_functions():
    '''
    Test functions that discard units.
    '''
    from brian2.units.unitsafefunctions import zeros_like, ones_like
    
    values = [3 * mV, np.array([1, 2]) * mV, np.arange(12).reshape(3, 4) * mV]
    for value in values:
        assert_equal(np.sign(value), np.sign(np.asarray(value)))
        assert_equal(zeros_like(value), np.zeros_like(np.asarray(value)))
        assert_equal(ones_like(value), np.ones_like(np.asarray(value)))
        assert_equal(np.nonzero(value), np.nonzero(np.asarray(value)))
Example #3
0
def test_unit_discarding_functions():
    '''
    Test functions that discard units.
    '''
    from brian2.units.unitsafefunctions import zeros_like, ones_like

    values = [3 * mV, np.array([1, 2]) * mV, np.arange(12).reshape(3, 4) * mV]
    for value in values:
        assert_equal(np.sign(value), np.sign(np.asarray(value)))
        assert_equal(zeros_like(value), np.zeros_like(np.asarray(value)))
        assert_equal(ones_like(value), np.ones_like(np.asarray(value)))
        # Calling non-zero on a 0d array is deprecated, don't test it:
        if value.ndim > 0:
            assert_equal(np.nonzero(value), np.nonzero(np.asarray(value)))