/
glebestraikh
/
adept
Обзор
Документация
Войти
/
glebestraikh
/
adept
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
python/cpp_bindings/linear_py.cpp
25 строк
826 B
kolkir
Add python bindings for device configuration
19 июн 2025, 00:03
19 июн 2025, 00:03
c00b85c
Код
Авторство
О чём код?
#include <pybind11/pybind11.h> #include <pybind11/stl.h> #include <adept/nn/linear.hpp> #include <sstream> namespace py = pybind11; using namespace adept; void bind_linear(py::module& m) { py::class_<LinearImpl, Module, std::shared_ptr<LinearImpl>>(m, "Linear") .def(py::init<index_t, index_t, device_t, dtype_t, index_t>(), py::arg("in_features"), py::arg("out_features"), py::arg("device") = device_t::CPU, py::arg("dtype") = dtype_t::Float32, py::arg("device_id") = 0) .def("parameters", &LinearImpl::parameters) .def("forward", &LinearImpl::forward) .def("__call__", [](LinearImpl& self, Variable& input) { return self.forward(input); }) .def("__repr__", [](const Linear& v) { std::stringstream buf; buf << v; return buf.str(); }); }