Python numpy.half() Examples
The following are 30
code examples of numpy.half().
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 also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: test_scalar_ctors.py From recruit with Apache License 2.0 | 6 votes |
def test_floating_overflow(self): """ Strings containing an unrepresentable float overflow """ fhalf = np.half('1e10000') assert_equal(fhalf, np.inf) fsingle = np.single('1e10000') assert_equal(fsingle, np.inf) fdouble = np.double('1e10000') assert_equal(fdouble, np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000') assert_equal(flongdouble, np.inf) fhalf = np.half('-1e10000') assert_equal(fhalf, -np.inf) fsingle = np.single('-1e10000') assert_equal(fsingle, -np.inf) fdouble = np.double('-1e10000') assert_equal(fdouble, -np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000') assert_equal(flongdouble, -np.inf)
Example #2
Source File: test_scalar_ctors.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_floating_overflow(self): """ Strings containing an unrepresentable float overflow """ fhalf = np.half('1e10000') assert_equal(fhalf, np.inf) fsingle = np.single('1e10000') assert_equal(fsingle, np.inf) fdouble = np.double('1e10000') assert_equal(fdouble, np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000') assert_equal(flongdouble, np.inf) fhalf = np.half('-1e10000') assert_equal(fhalf, -np.inf) fsingle = np.single('-1e10000') assert_equal(fsingle, -np.inf) fdouble = np.double('-1e10000') assert_equal(fdouble, -np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000') assert_equal(flongdouble, -np.inf)
Example #3
Source File: test_scalar_ctors.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def test_floating_overflow(self): """ Strings containing an unrepresentable float overflow """ fhalf = np.half('1e10000') assert_equal(fhalf, np.inf) fsingle = np.single('1e10000') assert_equal(fsingle, np.inf) fdouble = np.double('1e10000') assert_equal(fdouble, np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000') assert_equal(flongdouble, np.inf) fhalf = np.half('-1e10000') assert_equal(fhalf, -np.inf) fsingle = np.single('-1e10000') assert_equal(fsingle, -np.inf) fdouble = np.double('-1e10000') assert_equal(fdouble, -np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000') assert_equal(flongdouble, -np.inf)
Example #4
Source File: test_scalar_ctors.py From coffeegrindsize with MIT License | 6 votes |
def test_floating_overflow(self): """ Strings containing an unrepresentable float overflow """ fhalf = np.half('1e10000') assert_equal(fhalf, np.inf) fsingle = np.single('1e10000') assert_equal(fsingle, np.inf) fdouble = np.double('1e10000') assert_equal(fdouble, np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000') assert_equal(flongdouble, np.inf) fhalf = np.half('-1e10000') assert_equal(fhalf, -np.inf) fsingle = np.single('-1e10000') assert_equal(fsingle, -np.inf) fdouble = np.double('-1e10000') assert_equal(fdouble, -np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000') assert_equal(flongdouble, -np.inf)
Example #5
Source File: basic.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
def _asfarray(x): """Like numpy asfarray, except that it does not modify x dtype if x is already an array with a float dtype, and do not cast complex types to real.""" if hasattr(x, "dtype") and x.dtype.char in numpy.typecodes["AllFloat"]: # 'dtype' attribute does not ensure that the # object is an ndarray (e.g. Series class # from the pandas library) if x.dtype == numpy.half: # no half-precision routines, so convert to single precision return numpy.asarray(x, dtype=numpy.float32) return numpy.asarray(x, dtype=x.dtype) else: # We cannot use asfarray directly because it converts sequences of # complex to sequence of real ret = numpy.asarray(x) if ret.dtype == numpy.half: return numpy.asarray(ret, dtype=numpy.float32) elif ret.dtype.char not in numpy.typecodes["AllFloat"]: return numpy.asfarray(x) return ret
Example #6
Source File: test_multiarray.py From ImageFusion with MIT License | 6 votes |
def test_roundtrip_half(self): half_list = [ 1.0, -2.0, 6.5504 * 10**4, # (max half precision) 2**-14, # ~= 6.10352 * 10**-5 (minimum positive normal) 2**-24, # ~= 5.96046 * 10**-8 (minimum strictly positive subnormal) 0.0, -0.0, float('+inf'), float('-inf'), 0.333251953125, # ~= 1/3 ] x = np.array(half_list, dtype='>e') self._check_roundtrip(x) x = np.array(half_list, dtype='<e') self._check_roundtrip(x)
Example #7
Source File: test_scalar_ctors.py From pySINDy with MIT License | 6 votes |
def test_floating_overflow(self): """ Strings containing an unrepresentable float overflow """ fhalf = np.half('1e10000') assert_equal(fhalf, np.inf) fsingle = np.single('1e10000') assert_equal(fsingle, np.inf) fdouble = np.double('1e10000') assert_equal(fdouble, np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000') assert_equal(flongdouble, np.inf) fhalf = np.half('-1e10000') assert_equal(fhalf, -np.inf) fsingle = np.single('-1e10000') assert_equal(fsingle, -np.inf) fdouble = np.double('-1e10000') assert_equal(fdouble, -np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000') assert_equal(flongdouble, -np.inf)
Example #8
Source File: test_scalar_ctors.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 6 votes |
def test_floating_overflow(self): """ Strings containing an unrepresentable float overflow """ fhalf = np.half('1e10000') assert_equal(fhalf, np.inf) fsingle = np.single('1e10000') assert_equal(fsingle, np.inf) fdouble = np.double('1e10000') assert_equal(fdouble, np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000') assert_equal(flongdouble, np.inf) fhalf = np.half('-1e10000') assert_equal(fhalf, -np.inf) fsingle = np.single('-1e10000') assert_equal(fsingle, -np.inf) fdouble = np.double('-1e10000') assert_equal(fdouble, -np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000') assert_equal(flongdouble, -np.inf)
Example #9
Source File: basic.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def _asfarray(x): """Like numpy asfarray, except that it does not modify x dtype if x is already an array with a float dtype, and do not cast complex types to real.""" if hasattr(x, "dtype") and x.dtype.char in numpy.typecodes["AllFloat"]: # 'dtype' attribute does not ensure that the # object is an ndarray (e.g. Series class # from the pandas library) if x.dtype == numpy.half: # no half-precision routines, so convert to single precision return numpy.asarray(x, dtype=numpy.float32) return numpy.asarray(x, dtype=x.dtype) else: # We cannot use asfarray directly because it converts sequences of # complex to sequence of real ret = numpy.asarray(x) if ret.dtype == numpy.half: return numpy.asarray(ret, dtype=numpy.float32) elif ret.dtype.char not in numpy.typecodes["AllFloat"]: return numpy.asfarray(x) return ret
Example #10
Source File: test_scalar_ctors.py From GraphicDesignPatternByPython with MIT License | 6 votes |
def test_floating_overflow(self): """ Strings containing an unrepresentable float overflow """ fhalf = np.half('1e10000') assert_equal(fhalf, np.inf) fsingle = np.single('1e10000') assert_equal(fsingle, np.inf) fdouble = np.double('1e10000') assert_equal(fdouble, np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000') assert_equal(flongdouble, np.inf) fhalf = np.half('-1e10000') assert_equal(fhalf, -np.inf) fsingle = np.single('-1e10000') assert_equal(fsingle, -np.inf) fdouble = np.double('-1e10000') assert_equal(fdouble, -np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000') assert_equal(flongdouble, -np.inf)
Example #11
Source File: test_scalar_ctors.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_floating_overflow(self): """ Strings containing an unrepresentable float overflow """ fhalf = np.half('1e10000') assert_equal(fhalf, np.inf) fsingle = np.single('1e10000') assert_equal(fsingle, np.inf) fdouble = np.double('1e10000') assert_equal(fdouble, np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000') assert_equal(flongdouble, np.inf) fhalf = np.half('-1e10000') assert_equal(fhalf, -np.inf) fsingle = np.single('-1e10000') assert_equal(fsingle, -np.inf) fdouble = np.double('-1e10000') assert_equal(fdouble, -np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000') assert_equal(flongdouble, -np.inf)
Example #12
Source File: test_multiarray.py From Computable with MIT License | 6 votes |
def test_roundtrip_half(self): half_list = [ 1.0, -2.0, 6.5504 * 10**4, # (max half precision) 2**-14, # ~= 6.10352 * 10**-5 (minimum positive normal) 2**-24, # ~= 5.96046 * 10**-8 (minimum strictly positive subnormal) 0.0, -0.0, float('+inf'), float('-inf'), 0.333251953125, # ~= 1/3 ] x = np.array(half_list, dtype='>e') self._check_roundtrip(x) x = np.array(half_list, dtype='<e') self._check_roundtrip(x)
Example #13
Source File: test_scalar_ctors.py From vnpy_crypto with MIT License | 6 votes |
def test_floating_overflow(self): """ Strings containing an unrepresentable float overflow """ fhalf = np.half('1e10000') assert_equal(fhalf, np.inf) fsingle = np.single('1e10000') assert_equal(fsingle, np.inf) fdouble = np.double('1e10000') assert_equal(fdouble, np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '1e10000') assert_equal(flongdouble, np.inf) fhalf = np.half('-1e10000') assert_equal(fhalf, -np.inf) fsingle = np.single('-1e10000') assert_equal(fsingle, -np.inf) fdouble = np.double('-1e10000') assert_equal(fdouble, -np.inf) flongdouble = assert_warns(RuntimeWarning, np.longdouble, '-1e10000') assert_equal(flongdouble, -np.inf)
Example #14
Source File: basic.py From lambda-packs with MIT License | 6 votes |
def _asfarray(x): """Like numpy asfarray, except that it does not modify x dtype if x is already an array with a float dtype, and do not cast complex types to real.""" if hasattr(x, "dtype") and x.dtype.char in numpy.typecodes["AllFloat"]: # 'dtype' attribute does not ensure that the # object is an ndarray (e.g. Series class # from the pandas library) if x.dtype == numpy.half: # no half-precision routines, so convert to single precision return numpy.asarray(x, dtype=numpy.float32) return numpy.asarray(x, dtype=x.dtype) else: # We cannot use asfarray directly because it converts sequences of # complex to sequence of real ret = numpy.asarray(x) if ret.dtype == numpy.half: return numpy.asarray(ret, dtype=numpy.float32) elif ret.dtype.char not in numpy.typecodes["AllFloat"]: return numpy.asfarray(x) return ret
Example #15
Source File: terrain_correction.py From pyeo with GNU General Public License v3.0 | 5 votes |
def _generate_latlon_arrays(array, transformer, geotransform): def generate_latlon_for_here(x, y): return generate_latlon(x, y, geotransform, transformer) # The crude way. Ask someone if it is doable. top_lat, left_lon = generate_latlon_for_here(0,0) bottom_lat, right_lon = generate_latlon_for_here(array.shape[0]-1, array.shape[1]-1) lat_list = np.linspace(top_lat, bottom_lat, array.shape[1], dtype=np.half) lon_list = np.linspace(left_lon, right_lon, array.shape[0], dtype=np.half) lat_array = np.stack([lat_list]*array.shape[0]) lon_array = np.stack([lon_list]*array.shape[1]).T return lat_array, lon_array
Example #16
Source File: test_getlimits.py From keras-lambda with MIT License | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))
Example #17
Source File: test_getlimits.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))
Example #18
Source File: test_histograms.py From recruit with Apache License 2.0 | 5 votes |
def test_precision(self): # not looping results in a useful stack trace upon failure self.do_precision(np.half, np.single) self.do_precision(np.half, np.double) self.do_precision(np.half, np.longdouble) self.do_precision(np.single, np.double) self.do_precision(np.single, np.longdouble) self.do_precision(np.double, np.longdouble)
Example #19
Source File: test_histograms.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_precision(self): # not looping results in a useful stack trace upon failure self.do_precision(np.half, np.single) self.do_precision(np.half, np.double) self.do_precision(np.half, np.longdouble) self.do_precision(np.single, np.double) self.do_precision(np.single, np.longdouble) self.do_precision(np.double, np.longdouble)
Example #20
Source File: test_getlimits.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))
Example #21
Source File: test_getlimits.py From recruit with Apache License 2.0 | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))
Example #22
Source File: test_histograms.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def test_precision(self): # not looping results in a useful stack trace upon failure self.do_precision(np.half, np.single) self.do_precision(np.half, np.double) self.do_precision(np.half, np.longdouble) self.do_precision(np.single, np.double) self.do_precision(np.single, np.longdouble) self.do_precision(np.double, np.longdouble)
Example #23
Source File: test_getlimits.py From coffeegrindsize with MIT License | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))
Example #24
Source File: test_histograms.py From coffeegrindsize with MIT License | 5 votes |
def test_precision(self): # not looping results in a useful stack trace upon failure self.do_precision(np.half, np.single) self.do_precision(np.half, np.double) self.do_precision(np.half, np.longdouble) self.do_precision(np.single, np.double) self.do_precision(np.single, np.longdouble) self.do_precision(np.double, np.longdouble)
Example #25
Source File: test_getlimits.py From elasticintel with GNU General Public License v3.0 | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))
Example #26
Source File: test_getlimits.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))
Example #27
Source File: test_getlimits.py From ImageFusion with MIT License | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))
Example #28
Source File: test_multiarray.py From ImageFusion with MIT License | 5 votes |
def test_export_record(self): dt = [('a', 'b'), ('b', 'h'), ('c', 'i'), ('d', 'l'), ('dx', 'q'), ('e', 'B'), ('f', 'H'), ('g', 'I'), ('h', 'L'), ('hx', 'Q'), ('i', np.single), ('j', np.double), ('k', np.longdouble), ('ix', np.csingle), ('jx', np.cdouble), ('kx', np.clongdouble), ('l', 'S4'), ('m', 'U4'), ('n', 'V3'), ('o', '?'), ('p', np.half), ] x = np.array( [(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, asbytes('aaaa'), 'bbbb', asbytes(' '), True, 1.0)], dtype=dt) y = memoryview(x) assert_equal(y.shape, (1,)) assert_equal(y.ndim, 1) assert_equal(y.suboffsets, EMPTY) sz = sum([dtype(b).itemsize for a, b in dt]) if dtype('l').itemsize == 4: assert_equal(y.format, 'T{b:a:=h:b:i:c:l:d:q:dx:B:e:@H:f:=I:g:L:h:Q:hx:f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}') else: assert_equal(y.format, 'T{b:a:=h:b:i:c:q:d:q:dx:B:e:@H:f:=I:g:Q:h:Q:hx:f:i:d:j:^g:k:=Zf:ix:Zd:jx:^Zg:kx:4s:l:=4w:m:3x:n:?:o:@e:p:}') # Cannot test if NPY_RELAXED_STRIDES_CHECKING changes the strides if not (np.ones(1).strides[0] == np.iinfo(np.intp).max): assert_equal(y.strides, (sz,)) assert_equal(y.itemsize, sz)
Example #29
Source File: test_getlimits.py From Computable with MIT License | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))
Example #30
Source File: test_getlimits.py From mxnet-lambda with Apache License 2.0 | 5 votes |
def test_singleton(self): ftype = finfo(half) ftype2 = finfo(half) assert_equal(id(ftype), id(ftype2))