Beatmup
Beatmup::Python Namespace Reference

Python binding utilities More...

Classes

class  Bitmap
 Wrapper of Android.Graphics.Bitmap object. More...
 
class  WritableChunkCollection
 Writable ChunkCollection implementation for Python. More...
 

Functions

template<typename T >
CustomPoint< T > toPoint (const py::tuple &tuple)
 
template<typename T >
CustomRectangle< T > toRectangle (const py::tuple &tuple)
 
template<typename T >
py::tuple toTuple (const CustomPoint< T > &point)
 
template<typename T >
py::tuple toTuple (const CustomRectangle< T > &rectangle)
 
template<typename T >
py::tuple toTuple (const CustomMatrix2< T > &matrix)
 
py::tuple toTuple (const color3f &color)
 
py::tuple toTuple (const color4i &color)
 
pixfloat4 toPixfloat4 (const py::tuple &tuple)
 
color3f toColor3f (const py::tuple &tuple)
 
color4f toColor4f (const py::tuple &tuple)
 
color4i toColor4i (const py::tuple &tuple)
 
py::object getModelOutputDataByName (NNets::Model &model, const std::string &opName, int output)
 
py::object getModelOutputDataByOp (NNets::Model &model, const NNets::AbstractOperation &operation, int output)
 

Detailed Description

Python binding utilities

Function Documentation

◆ toPoint()

template<typename T >
CustomPoint<T> Beatmup::Python::toPoint ( const py::tuple &  tuple)
inline

Definition at line 34 of file binding_tools.hpp.

34  {
35  if (tuple.size() != 2)
36  throw std::invalid_argument("Expected a tuple of 2 elements");
37  return CustomPoint<T>(tuple[0].cast<T>(), tuple[1].cast<T>());
38  }

◆ toRectangle()

template<typename T >
CustomRectangle<T> Beatmup::Python::toRectangle ( const py::tuple &  tuple)
inline

Definition at line 41 of file binding_tools.hpp.

41  {
42  if (tuple.size() != 4)
43  throw std::invalid_argument("Expected a tuple of 4 elements");
44  return CustomRectangle<T>(tuple[0].cast<T>(), tuple[1].cast<T>(), tuple[2].cast<T>(), tuple[3].cast<T>());
45  }

◆ toTuple() [1/5]

template<typename T >
py::tuple Beatmup::Python::toTuple ( const CustomPoint< T > &  point)
inline

Definition at line 49 of file binding_tools.hpp.

49  {
50  return py::make_tuple(point.x, point.y);
51  }

◆ toTuple() [2/5]

template<typename T >
py::tuple Beatmup::Python::toTuple ( const CustomRectangle< T > &  rectangle)
inline

Definition at line 54 of file binding_tools.hpp.

54  {
55  return py::make_tuple(rectangle.a.x, rectangle.a.y, rectangle.b.x, rectangle.b.y);
56  }

◆ toTuple() [3/5]

template<typename T >
py::tuple Beatmup::Python::toTuple ( const CustomMatrix2< T > &  matrix)
inline

Definition at line 59 of file binding_tools.hpp.

59  {
60  return py::make_tuple(
61  py::make_tuple(matrix.getA11(), matrix.getA12()),
62  py::make_tuple(matrix.getA21(), matrix.getA22())
63  );
64  }

◆ toTuple() [4/5]

py::tuple Beatmup::Python::toTuple ( const color3f color)
inline

Definition at line 66 of file binding_tools.hpp.

66  {
67  return py::make_tuple(color.r, color.g, color.b);
68  }

◆ toTuple() [5/5]

py::tuple Beatmup::Python::toTuple ( const color4i color)
inline

Definition at line 70 of file binding_tools.hpp.

70  {
71  return py::make_tuple(color.r, color.g, color.b, color.a);
72  }

◆ toPixfloat4()

pixfloat4 Beatmup::Python::toPixfloat4 ( const py::tuple &  tuple)
inline

Definition at line 74 of file binding_tools.hpp.

74  {
75  if (tuple.size() != 4)
76  throw std::invalid_argument("Expected a tuple of 4 elements");
77  return pixfloat4(tuple[0].cast<float>(), tuple[1].cast<float>(), tuple[2].cast<float>(), tuple[3].cast<float>());
78  }

◆ toColor3f()

color3f Beatmup::Python::toColor3f ( const py::tuple &  tuple)
inline

Definition at line 80 of file binding_tools.hpp.

80  {
81  if (tuple.size() != 3)
82  throw std::invalid_argument("Expected a tuple of 3 elements");
83  return color3f{ tuple[0].cast<float>(), tuple[1].cast<float>(), tuple[2].cast<float>() };
84  }

◆ toColor4f()

color4f Beatmup::Python::toColor4f ( const py::tuple &  tuple)
inline

Definition at line 86 of file binding_tools.hpp.

86  {
87  if (tuple.size() != 4)
88  throw std::invalid_argument("Expected a tuple of 4 elements");
89  return color4f{ tuple[0].cast<float>(), tuple[1].cast<float>(), tuple[2].cast<float>(), tuple[3].cast<float>() };
90  }

◆ toColor4i()

color4i Beatmup::Python::toColor4i ( const py::tuple &  tuple)
inline

Definition at line 92 of file binding_tools.hpp.

92  {
93  if (tuple.size() != 4)
94  throw std::invalid_argument("Expected a tuple of 4 elements");
95  return color4i{ tuple[0].cast<uint8_t>(), tuple[1].cast<uint8_t>(), tuple[2].cast<uint8_t>(), tuple[3].cast<uint8_t>() };
96  }

◆ getModelOutputDataByName()

py::object Beatmup::Python::getModelOutputDataByName ( NNets::Model model,
const std::string &  opName,
int  output 
)

Definition at line 40 of file binding_tools.cpp.

40  {
41  return getModelOutputDataByOp(model, model.getOperation(opName), output);
42 }
py::object getModelOutputDataByOp(NNets::Model &model, const NNets::AbstractOperation &operation, int output)
JNIEnv jlong jobject jstring opName

◆ getModelOutputDataByOp()

py::object Beatmup::Python::getModelOutputDataByOp ( NNets::Model model,
const NNets::AbstractOperation operation,
int  output 
)

Definition at line 22 of file binding_tools.cpp.

22  {
23  size_t numSamples;
24  auto data = model.getOutputData(numSamples, operation, output);
25  auto size = operation.getOutputSize(output);
26  if (!data)
27  return py::none();
28  if (size[0] == 1 && size[2] == 1)
29  // column vector got, return flat
30  return py::array_t<float>({ size[1] }, { sizeof(float) }, data);
31  else
32  return py::array_t<float>(
33  { size[1], size[0], size[2] }, // "H, W, C"
34  { size[0] * size[2] * sizeof(float), size[2] * sizeof(float), sizeof(float) },
35  data
36  );
37 }
jlong jobject size