| 305 | } |
| 306 | |
| 307 | py::object _Const(py::handle value, py::handle dtype, py::handle device) { |
| 308 | py::object val = py::reinterpret_borrow<py::object>(value); |
| 309 | if (PyArray_Check(value.ptr())) { |
| 310 | py::tuple strides = |
| 311 | py::reinterpret_borrow<py::tuple>(getattr(value, "strides")); |
| 312 | bool need_squeeze = false; |
| 313 | for (size_t i = 0; i < strides.size(); ++i) { |
| 314 | if (strides[i].cast<ptrdiff_t>() == 0) { |
| 315 | need_squeeze = true; |
| 316 | } |
| 317 | } |
| 318 | if (need_squeeze) { |
| 319 | val = py::reinterpret_borrow<py::array>(value); |
| 320 | py::object orig_shp = val.attr("shape"); |
| 321 | val = val.attr("squeeze")(); |
| 322 | val = val.attr("reshape")(orig_shp); |
| 323 | } |
| 324 | } |
| 325 | py::object device_obj = device2obj(device, true); |
| 326 | py::tuple tup = |
| 327 | py::make_tuple(val, dtype, device_obj, true, false, py::none(), py::none()); |
| 328 | return TensorWrapper::make(py_tensor_type, tup.ptr(), nullptr); |
| 329 | } |
| 330 | |
| 331 | py::tuple _make_shape_tuple(py::handle shape) { |
| 332 | py::list orig; |
no test coverage detected