Skip to content

Commit

Permalink
add datatype enum to python module (#404)
Browse files Browse the repository at this point in the history
* add datatype enum to python module

Signed-off-by: koubaa <[email protected]>

* add datatype enum to python module

Signed-off-by: koubaa <[email protected]>

* add doc

Signed-off-by: koubaa <[email protected]>

---------

Signed-off-by: koubaa <[email protected]>
Co-authored-by: koubaa <[email protected]>
  • Loading branch information
koubaa and koubaa authored Dec 10, 2024
1 parent cb85d21 commit 48c127d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def kompute(shader):
# Explicit type constructor supports uint32, int32, double, float and bool
tensor_out_a = mgr.tensor_t(np.array([0, 0, 0], dtype=np.uint32))
tensor_out_b = mgr.tensor_t(np.array([0, 0, 0], dtype=np.uint32))
assert(t_data.data_type() == kp.DataTypes.uint)
params = [tensor_in_a, tensor_in_b, tensor_out_a, tensor_out_b]
Expand Down
5 changes: 4 additions & 1 deletion docs/overview/python-examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ Similarly you can find the same extended example as above:
# Can be initialized with List[] or np.Array
tensor_in_a = mgr.tensor([2, 2, 2])
tensor_in_b = mgr.tensor([1, 2, 3])
tensor_out = mgr.tensor([0, 0, 0])
# By default, tensors use a float type, but that can be explicitly specified
tensor_out = mgr.tensor_t([0, 0, 0], dtype=np.float32)
assert(tensor_out.data_type() == kp.DataTypes.float)
seq = mgr.sequence()
seq.eval(kp.OpTensorSyncDevice([tensor_in_a, tensor_in_b, tensor_out]))
Expand Down
13 changes: 13 additions & 0 deletions docs/overview/python-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,16 @@ TensorType
.. automodule:: kp
:members:

MemoryTypes
-------

.. automodule:: kp
:members:

DataTypes
-------

.. automodule:: kp
:members:


33 changes: 33 additions & 0 deletions python/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,39 @@ PYBIND11_MODULE(kp, m)

py::module_ np = py::module_::import("numpy");

py::enum_<kp::Memory::DataTypes>(m, "DataTypes")
.value("bool",
kp::Memory::DataTypes::eBool,
DOC(kp, Memory, DataTypes, eBool))
.value("int",
kp::Memory::DataTypes::eInt,
DOC(kp, Memory, DataTypes, eInt))
.value("uint",
kp::Memory::DataTypes::eUnsignedInt,
DOC(kp, Memory, DataTypes, eUnsignedInt))
.value("float",
kp::Memory::DataTypes::eFloat,
DOC(kp, Memory, DataTypes, eFloat))
.value("double",
kp::Memory::DataTypes::eDouble,
DOC(kp, Memory, DataTypes, eDouble))
.value("custom",
kp::Memory::DataTypes::eCustom,
DOC(kp, Memory, DataTypes, eCustom))
.value("short",
kp::Memory::DataTypes::eShort,
DOC(kp, Memory, DataTypes, eShort))
.value("ushort",
kp::Memory::DataTypes::eUnsignedShort,
DOC(kp, Memory, DataTypes, eUnsignedShort))
.value("char",
kp::Memory::DataTypes::eChar,
DOC(kp, Memory, DataTypes, eChar))
.value("uchar",
kp::Memory::DataTypes::eUnsignedChar,
DOC(kp, Memory, DataTypes, eUnsignedChar))
.export_values();

py::enum_<kp::Memory::MemoryTypes>(m, "MemoryTypes")
.value("device",
kp::Memory::MemoryTypes::eDevice,
Expand Down

0 comments on commit 48c127d

Please sign in to comment.