MCPcopy Create free account
hub / github.com/numpy/numpy / convert

Function convert

numpy/core/tests/test_umath_accuracy.py:27–36  ·  view source on GitHub ↗
(s, datatype="np.float32")

Source from the content-addressed store, hash-verified

25# convert string to hex function taken from:
26# https://stackoverflow.com/questions/1592158/convert-hex-to-float #
27def convert(s, datatype="np.float32"):
28 i = int(s, 16) # convert from hex to a Python int
29 if (datatype == "np.float64"):
30 cp = pointer(c_longlong(i)) # make this into a c long long integer
31 fp = cast(cp, POINTER(c_double)) # cast the int pointer to a double pointer
32 else:
33 cp = pointer(c_int(i)) # make this into a c integer
34 fp = cast(cp, POINTER(c_float)) # cast the int pointer to a float pointer
35
36 return fp.contents.value # dereference the pointer, get the float
37
38str_to_float = np.vectorize(convert)
39

Callers 1

RATIONAL_BINOPFunction · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected