/
vuron
/
adept
Обзор
Документация
Войти
/
vuron
/
adept
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
with_cpu
python/cpp_bindings/tensor_props_py.cpp
39 строк
1 KB
kolkir
Refactor python folder structure
01 мар 2025, 22:16
01 мар 2025, 22:16
ef25f05
Код
Авторство
О чём код?
#include <pybind11/pybind11.h> #include <pybind11/stl.h> #include <adept/tensor_props.hpp> namespace py = pybind11; using namespace adept; void bind_tensor_props(py::module& m) { py::enum_<device_t>(m, "device_t") .value("CPU", device_t::CPU) .value("GPU", device_t::GPU) .export_values(); py::enum_<dtype_t>(m, "dtype_t") .value("Float32", dtype_t::Float32) .value("Float64", dtype_t::Float64) .value("Int32", dtype_t::Int32) .value("Int8", dtype_t::Int8) .export_values(); py::class_<TensorProperties>(m, "TensorProperties") .def(py::init([](const Shape& shape) { TensorProperties props{.shape = shape, .device = device_t::CPU, .dtype = dtype_t::Float32}; return props; })) .def(py::init([](const Shape& shape, device_t device) { TensorProperties props{.shape = shape, .device = device, .dtype = dtype_t::Float32}; return props; })) .def(py::init([](const Shape& shape, device_t device, dtype_t dtype) { TensorProperties props{.shape = shape, .device = device, .dtype = dtype}; return props; })) .def_readwrite("shape", &TensorProperties::shape) .def_readwrite("device", &TensorProperties::device) .def_readwrite("dtype", &TensorProperties::dtype); }