MCPcopy Create free account
hub / github.com/NVIDIA/cuda-quantum / Float

Class Float

python/utils/PyTypes.h:67–102  ·  view source on GitHub ↗

Extended python float object. Includes `float`, `numpy.float64`, `numpy.float32`.

Source from the content-addressed store, hash-verified

65///
66/// Includes `float`, `numpy.float64`, `numpy.float32`.
67class Float : public nanobind::object {
68public:
69 NB_OBJECT_DEFAULT(Float, nanobind::object, "float", isFloat_)
70
71 // Allow implicit conversion from float/double:
72 // NOLINTNEXTLINE(google-explicit-constructor)
73 Float(float value)
74 : nanobind::object(nanobind::steal(PyFloat_FromDouble((double)value))) {
75 if (!ptr()) {
76 throw std::runtime_error("Could not allocate float object!");
77 }
78 }
79 // NOLINTNEXTLINE(google-explicit-constructor)
80 Float(double value = .0)
81 : nanobind::object(nanobind::steal(PyFloat_FromDouble((double)value))) {
82 if (!ptr()) {
83 throw std::runtime_error("Could not allocate float object!");
84 }
85 }
86 // NOLINTNEXTLINE(google-explicit-constructor)
87 operator float() const { return (float)PyFloat_AsDouble(ptr()); }
88 // NOLINTNEXTLINE(google-explicit-constructor)
89 operator double() const { return (double)PyFloat_AsDouble(ptr()); }
90
91 static bool isFloat_(PyObject *o) {
92 if (PyFloat_Check(o)) {
93 return true;
94 }
95 PyTypeObject *type = Py_TYPE(o);
96 std::string name = std::string(type->tp_name);
97 if (name == "numpy.float32" || name == "numpy.float64") {
98 return true;
99 }
100 return false;
101 }
102};
103
104/// Extended python int object.
105///

Callers 1

convertFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected