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

Function RecursiveParseAndAssign

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

Source from the content-addressed store, hash-verified

111}
112
113void RecursiveParseAndAssign(PyObject* object, char* data, const int& ndims, const int& dim,
114 const ShapeView& shape, const DimVector& strides,
115 const DataType& dtype) {
116 if (dim == ndims) { return ParseScalar(object, data, dtype); }
117 auto seq = PyObjectPtr(PySequence_Fast(object, "Expected a sequence."));
118 int64_t size = PySequence_Fast_GET_SIZE(seq.get());
119 CHECK_EQ_OR_THROW(size, shape.At(dim)) << "Sequence size is " << size << " at dimemsion " << dim
120 << ", but expected " << shape.At(dim);
121 for (int64_t i = 0; i < size; ++i) {
122 PyObject* item = PySequence_Fast_GET_ITEM(seq.get(), i);
123 RecursiveParseAndAssign(item, data, ndims, dim + 1, shape, strides, dtype);
124 data += strides.at(dim) * GetSizeOfDataType(dtype);
125 }
126}
127
128void ParseArrayToTensor(PyObject* object,
129 const std::shared_ptr<vm::EagerBlobObject>& eager_blob_object) {

Callers 1

ParseArrayToTensorFunction · 0.85

Calls 5

ParseScalarFunction · 0.85
GetSizeOfDataTypeFunction · 0.85
getMethod · 0.45
AtMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected