MCPcopy Create free account
hub / github.com/Oneflow-Inc/oneflow / UnpackIndexItem

Function UnpackIndexItem

oneflow/api/python/functional/indexing.cpp:196–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194}
195
196IndexItem UnpackIndexItem(PyObject* object) {
197 if (object == Py_Ellipsis) {
198 return IndexItem(EllipsisIndex{});
199 } else if (PySlice_Check(object)) {
200 Py_ssize_t start, end, step;
201 PySliceUnpack(object, &start, &end, &step);
202 return IndexItem(start, end, step);
203 } else if (PyLong_Check(object) && object != Py_False && object != Py_True) {
204 return IndexItem(static_cast<int64_t>(PyLong_AsLongLong(object)));
205 } else if (numpy::PyArrayCheckLongScalar(object)) {
206 return IndexItem(static_cast<int64_t>(PyLong_AsLongLong(object)));
207 } else if (object == Py_False || object == Py_True) {
208 return IndexItem(object == Py_True);
209 } else if (object == Py_None) {
210 return IndexItem(NoneIndex{});
211 } else if (PyTensor_Check(object)) {
212 return IndexItem(PyTensor_Unpack(object));
213 } else if (PySequence_Check(object)) {
214 return IndexItem(ConvertToIndexingTensor(object).GetPtrOrThrow());
215 }
216 THROW(IndexError) << "Invalid index " << Py_TYPE(object)->tp_name;
217 return IndexItem();
218}
219
220} // namespace detail
221

Callers 1

PyUnpackTensorIndexFunction · 0.85

Calls 6

IndexItemClass · 0.85
PySliceUnpackFunction · 0.85
PyArrayCheckLongScalarFunction · 0.85
PyTensor_CheckFunction · 0.85
ConvertToIndexingTensorFunction · 0.85
GetPtrOrThrowMethod · 0.80

Tested by

no test coverage detected