Python numpy.maximum_sctype() Examples

The following are 22 code examples for showing how to use numpy.maximum_sctype(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module numpy , or try the search function .

Example 1
Project: me-ica   Author: ME-ICA   File: test_scaling.py    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
def check_int_a2f(in_type, out_type):
    # Check that array to / from file returns roughly the same as input
    big_floater = np.maximum_sctype(np.float)
    info = type_info(in_type)
    this_min, this_max = info['min'], info['max']
    if not in_type in np.sctypes['complex']:
        data = np.array([this_min, this_max], in_type)
        # Bug in numpy 1.6.2 on PPC leading to infs - abort
        if not np.all(np.isfinite(data)):
            if DEBUG:
                print 'Hit PPC max -> inf bug; skip in_type %s' % in_type
            return
    else: # Funny behavior with complex256
        data = np.zeros((2,), in_type)
        data[0] = this_min + 0j
        data[1] = this_max + 0j
    str_io = BytesIO()
    try:
        scale, inter, mn, mx = calculate_scale(data, out_type, True)
    except ValueError:
        if DEBUG:
            print in_type, out_type, sys.exc_info()[1]
        return
    array_to_file(data, str_io, out_type, 0, inter, scale, mn, mx)
    data_back = array_from_file(data.shape, out_type, str_io)
    data_back = apply_read_scaling(data_back, scale, inter)
    assert_true(np.allclose(big_floater(data), big_floater(data_back)))
    # Try with analyze-size scale and inter
    scale32 = np.float32(scale)
    inter32 = np.float32(inter)
    if scale32 == np.inf or inter32 == np.inf:
        return
    data_back = array_from_file(data.shape, out_type, str_io)
    data_back = apply_read_scaling(data_back, scale32, inter32)
    # Clip at extremes to remove inf
    info = type_info(in_type)
    out_min, out_max = info['min'], info['max']
    assert_true(np.allclose(big_floater(data),
                            big_floater(np.clip(data_back, out_min, out_max)))) 
Example 2
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
def test_int(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['int'][-1]) 
Example 3
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
def test_uint(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['uint'][-1]) 
Example 4
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
def test_float(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['float'][-1]) 
Example 5
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
def test_complex(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['complex'][-1]) 
Example 6
Project: recruit   Author: Frank-qlu   File: test_numerictypes.py    License: Apache License 2.0 5 votes vote down vote up
def test_other(self, t):
        assert_equal(np.maximum_sctype(t), t) 
Example 7
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_int(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['int'][-1]) 
Example 8
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_uint(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['uint'][-1]) 
Example 9
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_float(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['float'][-1]) 
Example 10
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_complex(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['complex'][-1]) 
Example 11
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_other(self, t):
        assert_equal(np.maximum_sctype(t), t) 
Example 12
def test_int(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['int'][-1]) 
Example 13
def test_uint(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['uint'][-1]) 
Example 14
def test_float(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['float'][-1]) 
Example 15
def test_complex(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['complex'][-1]) 
Example 16
def test_other(self, t):
        assert_equal(np.maximum_sctype(t), t) 
Example 17
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_int(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['int'][-1]) 
Example 18
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_uint(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['uint'][-1]) 
Example 19
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_float(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['float'][-1]) 
Example 20
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_complex(self, t):
        assert_equal(np.maximum_sctype(t), np.sctypes['complex'][-1]) 
Example 21
Project: coffeegrindsize   Author: jgagneastro   File: test_numerictypes.py    License: MIT License 5 votes vote down vote up
def test_other(self, t):
        assert_equal(np.maximum_sctype(t), t) 
Example 22
Project: me-ica   Author: ME-ICA   File: test_scaling.py    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
def test_scale_min_max():
    mx_dt = np.maximum_sctype(np.float)
    for tp in np.sctypes['uint'] + np.sctypes['int']:
        info = np.iinfo(tp)
        # Need to pump up to max fp type to contain python longs
        imin = np.array(info.min, dtype=mx_dt)
        imax = np.array(info.max, dtype=mx_dt)
        value_pairs = (
            (0, imax),
            (imin, 0),
            (imin, imax),
            (1, 10),
            (-1, -1),
            (1, 1),
            (-10, -1),
            (-100, 10))
        for mn, mx in value_pairs:
            # with intercept
            scale, inter = scale_min_max(mn, mx, tp, True)
            if mx-mn:
                assert_array_almost_equal, (mx-inter) / scale, imax
                assert_array_almost_equal, (mn-inter) / scale, imin
            else:
                assert_equal, (scale, inter), (1.0, mn)
            # without intercept
            if imin == 0 and mn < 0 and mx > 0:
                (assert_raises, ValueError,
                       scale_min_max, mn, mx, tp, False)
                continue
            scale, inter = scale_min_max(mn, mx, tp, False)
            assert_equal, inter, 0.0
            if mn == 0 and mx == 0:
                assert_equal, scale, 1.0
                continue
            sc_mn = mn / scale
            sc_mx = mx / scale
            assert_true, sc_mn >= imin
            assert_true, sc_mx <= imax
            if imin == 0:
                if mx > 0: # numbers all +ve
                    assert_array_almost_equal, mx / scale, imax
                else: # numbers all -ve
                    assert_array_almost_equal, mn / scale, imax
                continue
            if abs(mx) >= abs(mn):
                assert_array_almost_equal, mx / scale, imax
            else:
                assert_array_almost_equal, mn / scale, imin