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

Function InferArraySizes

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

Source from the content-addressed store, hash-verified

140}
141
142Shape InferArraySizes(PyObject* object) {
143 DimVector sizes;
144 PyObject* seq = object;
145 PyObjectPtr handle;
146 while (PySequence_Check(seq)) {
147 int64_t length = PySequence_Length(seq);
148 sizes.emplace_back(length);
149 CHECK_LE_OR_THROW(sizes.size(), /*MAX_DIMS=*/128)
150 << "Too many dimensions " << Py_TYPE(seq)->tp_name;
151 if (length == 0) break;
152 handle = PyObjectPtr(PySequence_GetItem(seq, 0));
153 seq = handle.get();
154 }
155 return Shape(sizes);
156}
157
158Maybe<Tensor> ConvertToIndexingTensor(PyObject* object) {
159 // NOTE: convert data to indexing will ensure in eager mode

Callers 1

ConvertToIndexingTensorFunction · 0.85

Calls 4

ShapeClass · 0.70
emplace_backMethod · 0.45
sizeMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected