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

Function OFStrideToNumpyStride

oneflow/extension/python/numpy.cpp:93–99  ·  view source on GitHub ↗

NumPy strides use bytes. OneFlow strides use element counts.

Source from the content-addressed store, hash-verified

91
92// NumPy strides use bytes. OneFlow strides use element counts.
93std::vector<size_t> OFStrideToNumpyStride(const Stride& stride, const DataType data_type) {
94 size_t ndim = stride.size();
95 auto result = std::vector<size_t>(ndim);
96 int byte_per_elem = GetSizeOfDataType(data_type);
97 for (int i = 0; i < ndim; i++) { result[i] = stride.at(i) * byte_per_elem; }
98 return result;
99}
100
101bool PyArrayCheckLongScalar(PyObject* obj) {
102 return PyArray_CheckScalar(obj) && PyDataType_ISINTEGER(PyArray_DescrFromScalar(obj));

Callers 1

EagerLocalTensorToNumpyFunction · 0.85

Calls 3

GetSizeOfDataTypeFunction · 0.85
sizeMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected