MCPcopy Create free account
hub / github.com/Samsung/ONE / numpyArray

Function numpyArray

compiler/dalgona/src/Utils.cpp:40–74  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38{
39
40py::array numpyArray(const Tensor *tensor)
41{
42 assert(tensor != nullptr); // FIX_CALLER_UNLESS
43
44 const auto tensor_shape = tensor->shape();
45
46 uint32_t size = 1;
47 std::vector<uint32_t> shape(tensor_shape.num_dims());
48 for (int i = 0; i < tensor_shape.num_dims(); i++)
49 {
50 THROW_UNLESS(tensor_shape.dim(i) >= 0, "Negative dimension detected in " + tensor->name());
51
52 shape[i] = tensor_shape.dim(i);
53 size *= shape[i];
54 }
55
56 if (size == 0)
57 return py::none();
58
59 switch (tensor->element_type())
60 {
61 case loco::DataType::FLOAT32:
62 return py::array_t<float, py::array::c_style>(shape, tensor->data<float>());
63 case loco::DataType::S16:
64 return py::array_t<int16_t, py::array::c_style>(shape, tensor->data<int16_t>());
65 case loco::DataType::S32:
66 return py::array_t<int32_t, py::array::c_style>(shape, tensor->data<int32_t>());
67 case loco::DataType::S64:
68 return py::array_t<int64_t, py::array::c_style>(shape, tensor->data<int64_t>());
69 case loco::DataType::U8:
70 return py::array_t<uint8_t, py::array::c_style>(shape, tensor->data<uint8_t>());
71 default:
72 throw std::runtime_error("Unsupported data type");
73 }
74}
75
76py::dict quantparam(const Tensor *tensor)
77{

Callers 3

inputsPyArrayFunction · 0.85
outputsPyArrayFunction · 0.85
outputPyArrayFunction · 0.85

Calls 6

noneFunction · 0.85
shapeMethod · 0.45
num_dimsMethod · 0.45
dimMethod · 0.45
nameMethod · 0.45
element_typeMethod · 0.45

Tested by

no test coverage detected