jacobian

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit aa60d38b5635de5a3552f17104e80fc205b46f32
parent 3bb4bedeb5f12db6543c126a8461df61d0522c17
Author: David Freifeld <freifeld.david@gmail.com>
Date:   Sat, 27 Mar 2021 22:58:49 -0700

Successful build of Python bindings

Diffstat:
MCMakeLists.txt | 19++++++++++---------
Mjacobian/__init__.py | 2+-
Msrc/pybind.cpp | 34+++++++++++++++++++---------------
3 files changed, 30 insertions(+), 25 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -14,21 +14,22 @@ endif() if (FAST) set(COMPILE_FLAGS "${COMPILE_FLAGS} -O3") elseif (FASTER) - set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -mavx -mfma -march=native -mfpmath=sse -fno-pic -DMKL_ILP64") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -mavx -mfma -march=native -mfpmath=sse -DMKL_ILP64") elseif (TRADEOFFS) - set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -mavx -msse2 -msse3 -march=native -mfpmath=sse -DMKL_ILP64 -fno-pic -ffast-math -ffast-math") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -mavx -msse2 -msse3 -march=native -mfpmath=sse -DMKL_ILP64 -ffast-math -ffast-math") elseif (RECKLESS) - set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -mavx -msse2 -msse3 -march=native -mfpmath=sse -DMKL_ILP64 -fno-pic -D NDEBUG -ffast-math -D RECKLESS") + set(COMPILE_FLAGS "${COMPILE_FLAGS} -mavx -O3 -mavx -msse2 -msse3 -march=native -mfpmath=sse -DMKL_ILP64 -D NDEBUG -ffast-math -D RECKLESS") endif() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMPILE_FLAGS} -fPIE") -# if (PYTHON) -# project(jacobian) -# find_package(pybind11 CONFIG REQUIRED) -# include_directories(${pybind11_INCLUDE_DIRS}) -# pybind11_add_module(_jacobian example.cpp ./src/bpnn.cpp ./src/utils.cpp) -# endif (PYTHON) +if (PYTHON) + project(jacobian) + find_package(pybind11 CONFIG REQUIRED) + include_directories(${pybind11_INCLUDE_DIRS}) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + pybind11_add_module(_jacobian ./src/pybind.cpp ./src/bpnn.cpp ./src/utils.cpp) +endif (PYTHON) if (CXX) project(jacobian_cli) diff --git a/jacobian/__init__.py b/jacobian/__init__.py @@ -1 +1 @@ -from ._jacobian import * +from _jacobian import * diff --git a/src/pybind.cpp b/src/pybind.cpp @@ -10,24 +10,28 @@ #include "bpnn.hpp" namespace py = pybind11; -PYBIND11_MODULE(mrbpnn, m) { +PYBIND11_MODULE(_jacobian, m) { m.doc() = "Fast machine learning in C++"; // optional module docstring + py::enum_<Regularization>(m, "Regularization") + .value("L1", Regularization::L1) + .value("L2", Regularization::L2) + .export_values(); py::class_<Network>(m, "Network") - .def(py::init<char*, int, float, float, int, float, float, bool, float>()) - .def("add_layer", &Network::add_layer, py::arg("nodes"), py::arg("activation"), py::arg("activation_deriv")) - .def("initialize", &Network::initialize) + .def(py::init<char*, int, float, float, Regularization, float, float, bool, float>()) + .def("add_layer", &Network::add_layer, py::arg("nodes"), py::arg("name"), py::arg("activation"), py::arg("activation_deriv")) + .def("initialize", &Network::initialize) //.def("init_decay", &Network::init_decay, py::arg("type"), py::arg("a_0"), py::arg("k")) //.def("set_activation", &Network::set_activation) - .def("feedforward", &Network::feedforward) - .def("backpropagate", &Network::backpropagate) - .def("list_net", &Network::list_net) - .def("cost", &Network::cost) - .def("accuracy", &Network::accuracy) + .def("feedforward", &Network::feedforward) + .def("backpropagate", &Network::backpropagate) + .def("list_net", &Network::list_net) + .def("cost", &Network::cost) + .def("accuracy", &Network::accuracy) //.def("update_layer", &Network::update_layer, py::arg("vals"), py::arg("len"), py::arg("index")) - .def("next_batch", &Network::next_batch) - .def("train", &Network::train) - .def("get_acc", &Network::get_acc) - .def("get_cost", &Network::get_cost) - .def("get_val_acc", &Network::get_val_acc) - .def("get_val_cost", &Network::get_val_cost); + .def("next_batch", &Network::next_batch) + .def("train", &Network::train) + .def("get_acc", &Network::get_acc) + .def("get_cost", &Network::get_cost) + .def("get_val_acc", &Network::get_val_acc) + .def("get_val_cost", &Network::get_val_cost); }