| 466 | } |
| 467 | |
| 468 | Status UnboxIntegerAsInt64(PyObject* obj, int64_t* out) { |
| 469 | if (PyLong_Check(obj)) { |
| 470 | int overflow = 0; |
| 471 | *out = PyLong_AsLongLongAndOverflow(obj, &overflow); |
| 472 | if (overflow) { |
| 473 | return Status::Invalid("PyLong is too large to fit int64"); |
| 474 | } |
| 475 | } else if (PyArray_IsScalar(obj, Byte)) { |
| 476 | *out = reinterpret_cast<PyByteScalarObject*>(obj)->obval; |
| 477 | } else if (PyArray_IsScalar(obj, UByte)) { |
| 478 | *out = reinterpret_cast<PyUByteScalarObject*>(obj)->obval; |
| 479 | } else if (PyArray_IsScalar(obj, Short)) { |
| 480 | *out = reinterpret_cast<PyShortScalarObject*>(obj)->obval; |
| 481 | } else if (PyArray_IsScalar(obj, UShort)) { |
| 482 | *out = reinterpret_cast<PyUShortScalarObject*>(obj)->obval; |
| 483 | } else if (PyArray_IsScalar(obj, Int)) { |
| 484 | *out = reinterpret_cast<PyIntScalarObject*>(obj)->obval; |
| 485 | } else if (PyArray_IsScalar(obj, UInt)) { |
| 486 | *out = reinterpret_cast<PyUIntScalarObject*>(obj)->obval; |
| 487 | } else if (PyArray_IsScalar(obj, Long)) { |
| 488 | *out = reinterpret_cast<PyLongScalarObject*>(obj)->obval; |
| 489 | } else if (PyArray_IsScalar(obj, ULong)) { |
| 490 | *out = reinterpret_cast<PyULongScalarObject*>(obj)->obval; |
| 491 | } else if (PyArray_IsScalar(obj, LongLong)) { |
| 492 | *out = reinterpret_cast<PyLongLongScalarObject*>(obj)->obval; |
| 493 | } else if (PyArray_IsScalar(obj, Int64)) { |
| 494 | *out = reinterpret_cast<PyInt64ScalarObject*>(obj)->obval; |
| 495 | } else if (PyArray_IsScalar(obj, ULongLong)) { |
| 496 | *out = reinterpret_cast<PyULongLongScalarObject*>(obj)->obval; |
| 497 | } else if (PyArray_IsScalar(obj, UInt64)) { |
| 498 | *out = reinterpret_cast<PyUInt64ScalarObject*>(obj)->obval; |
| 499 | } else { |
| 500 | return Status::Invalid("Integer scalar type not recognized"); |
| 501 | } |
| 502 | return Status::OK(); |
| 503 | } |
| 504 | |
| 505 | Status IntegerScalarToDoubleSafe(PyObject* obj, double* out) { |
| 506 | int64_t value = 0; |
no test coverage detected