| 328 | } |
| 329 | |
| 330 | Status TestNumPyBufferNumpyArray() { |
| 331 | npy_intp dims[1] = {10}; |
| 332 | |
| 333 | OwnedRef arr_ref(PyArray_SimpleNew(1, dims, NPY_FLOAT)); |
| 334 | PyObject* arr = arr_ref.obj(); |
| 335 | ASSERT_NE(arr, nullptr); |
| 336 | auto old_refcnt = Py_REFCNT(arr); |
| 337 | |
| 338 | auto buf = std::make_shared<NumPyBuffer>(arr); |
| 339 | ASSERT_TRUE(buf->is_cpu()); |
| 340 | ASSERT_EQ(buf->data(), PyArray_DATA(reinterpret_cast<PyArrayObject*>(arr))); |
| 341 | ASSERT_TRUE(buf->is_mutable()); |
| 342 | ASSERT_EQ(buf->mutable_data(), buf->data()); |
| 343 | ASSERT_EQ(old_refcnt + 1, Py_REFCNT(arr)); |
| 344 | buf.reset(); |
| 345 | ASSERT_EQ(old_refcnt, Py_REFCNT(arr)); |
| 346 | |
| 347 | // Read-only |
| 348 | PyArray_CLEARFLAGS(reinterpret_cast<PyArrayObject*>(arr), NPY_ARRAY_WRITEABLE); |
| 349 | buf = std::make_shared<NumPyBuffer>(arr); |
| 350 | ASSERT_TRUE(buf->is_cpu()); |
| 351 | ASSERT_EQ(buf->data(), PyArray_DATA(reinterpret_cast<PyArrayObject*>(arr))); |
| 352 | ASSERT_FALSE(buf->is_mutable()); |
| 353 | ASSERT_EQ(old_refcnt + 1, Py_REFCNT(arr)); |
| 354 | buf.reset(); |
| 355 | ASSERT_EQ(old_refcnt, Py_REFCNT(arr)); |
| 356 | |
| 357 | return Status::OK(); |
| 358 | } |
| 359 | #endif |
| 360 | |
| 361 | Status TestPythonDecimalToString() { |
nothing calls this directly
no test coverage detected