Skip to content
Snippets Groups Projects
Commit 7b0e38c6 authored by Olivier BICHLER's avatar Olivier BICHLER
Browse files
parents ca36b9a7 a53d5892
No related branches found
No related tags found
No related merge requests found
......@@ -2,11 +2,21 @@
You can find here the C++ code of the Core library of Aidge.
## Compilation
## Pip installation
To install aidge_core using pip, make sure to set the desired install path :
``` bash
export AIDGE_INSTALL = '<path_to_aidge>/install'
```
Create two directories ``build`` and ``ìnstall``.
Then run in your python environnement :
``` bash
pip install . -v
```
## Standard C++ Compilation
Create two directories ``build`` and ``ìnstall``.
Then **inside** ``build`` :
......
......@@ -101,17 +101,17 @@ public:
///////////////////////////////////////////////////////
/**
* @brief Run forward() function of the associated Operator
* @brief Run forward() function of the associated Operator.
*/
void forward();
/**
* @brief Run backward() function of the associated Operator
* @brief Run backward() function of the associated Operator.
*/
void backward();
/**
* @brief Get the Operator object of the Node
* @brief Get the Operator object of the Node.
* @return std::shared_ptr<Operator>
*/
inline std::shared_ptr<Operator> getOperator() const { return mOperator; }
......@@ -136,7 +136,7 @@ public:
std::vector<std::pair<NodePtr, IOIndex_t>> dataInputs() const;
/**
* @brief List of pair <Parent, ID of the intput>. When an input is not linked
* @brief List of pair <Parent, ID of the parent output>. When an input is not linked
* to any Parent, the pair is <nullptr, gk_IODefaultIndex>.
* @return std::vector<std::pair<NodePtr, IOIndex_t>>
*/
......@@ -193,7 +193,7 @@ public:
output(IOIndex_t outID) const;
/**
* @brief Number of input specifically for data
* @brief Number of inputs, including both data and learnable parameters.
* @details [data, data, weight, bias] => 4
* @return IOIndex_t
*/
......@@ -252,9 +252,9 @@ public:
/**
* @brief Link another Node to an output of the current Node.
* @param otherNode Pointer to the other Node.
* @param outId ID of the output Tensor to connect to the other Node.
* @param outId ID of the current Node output to connect to the other Node.
* Default to 0.
* @param otherInId ID of the input Tensor to connect to the current Node.
* @param otherInId ID of the other Node input to connect to the current Node.
* Default to the first avaible data input.
*/
void addChild(NodePtr otherNode,
......
......@@ -22,27 +22,57 @@ namespace py = pybind11;
namespace Aidge {
void init_GraphView(py::module& m) {
py::class_<GraphView, std::shared_ptr<GraphView>>(m, "GraphView")
.def(py::init<>())
.def("save", &GraphView::save, py::arg("path"), py::arg("verbose") = false)
.def("get_output_nodes", &GraphView::outputNodes)
.def("get_input_nodes", &GraphView::inputNodes)
.def("add", (void (GraphView::*)(std::shared_ptr<Node>, bool)) & GraphView::add,
py::arg("other_node"), py::arg("include_learnable_parameters") = true)
.def("add_child",
(void (GraphView::*)(std::shared_ptr<Node>,
std::shared_ptr<Node>,
const IOIndex_t,
IOIndex_t)) &
GraphView::addChild,
py::arg("toOtherNode"), py::arg("fromOutNode") = nullptr,
py::arg("fromTensor") = 0U, py::arg("toTensor") = gk_IODefaultIndex)
.def("replace_with", &GraphView::replaceWith, py::arg("new_nodes"))
.def("get_nodes", &GraphView::getNodes)
.def("get_node", &GraphView::getNode, py::arg("node_name"))
.def("forward_dims", &GraphView::forwardDims)
.def("__call__", &GraphView::operator(), py::arg("connectors"))
.def("set_datatype", &GraphView::setDatatype, py::arg("datatype"))
.def("set_backend", &GraphView::setBackend, py::arg("backend"))
.def(py::init<>())
.def("save", &GraphView::save, py::arg("path"), py::arg("verbose") = false,
R"mydelimiter(
Save the GraphView as a Mermaid graph in a .md file at the specified location.
:param path: save location
:type path: str
)mydelimiter")
.def("get_output_nodes", &GraphView::outputNodes,
R"mydelimiter(
Get set of output Nodes.
:rtype: list[Node]
)mydelimiter")
.def("get_input_nodes", &GraphView::inputNodes,
R"mydelimiter(
Get set of input Nodes.
:rtype: list[Node]
)mydelimiter")
.def("add", (void (GraphView::*)(std::shared_ptr<Node>, bool)) & GraphView::add,
py::arg("other_node"), py::arg("include_learnable_parameters") = true,
R"mydelimiter(
Include a Node to the current GraphView object.
:param other_node: Node to add
:type oth_Node: Node
:param includeLearnableParameter: include non-data inputs, like weights and biases. Default True.
:type includeLearnableParameter: bool
)mydelimiter")
.def("add_child",
(void (GraphView::*)(std::shared_ptr<Node>,
std::shared_ptr<Node>,
const IOIndex_t,
IOIndex_t)) &
GraphView::addChild,
py::arg("toOtherNode"), py::arg("fromOutNode") = nullptr,
py::arg("fromTensor") = 0U, py::arg("toTensor") = gk_IODefaultIndex)
.def("replace_with", &GraphView::replaceWith, py::arg("new_nodes"))
.def("get_nodes", &GraphView::getNodes)
.def("get_node", &GraphView::getNode, py::arg("node_name"))
.def("forward_dims", &GraphView::forwardDims)
.def("__call__", &GraphView::operator(), py::arg("connectors"))
.def("set_datatype", &GraphView::setDatatype, py::arg("datatype"))
.def("set_backend", &GraphView::setBackend, py::arg("backend"))
// .def("__getitem__", [](Tensor& b, size_t idx)-> py::object {
// // TODO : Should return error if backend not compatible with get
// if (idx >= b.size()) throw py::index_error();
......
......@@ -22,28 +22,120 @@ namespace py = pybind11;
namespace Aidge {
void init_Node(py::module& m) {
py::class_<Node, std::shared_ptr<Node>>(m, "Node")
.def("name", &Node::name)
.def("type", &Node::type)
.def("get_operator", &Node::getOperator)
.def("set_name", &Node::setName, py::arg("name"))
.def("name", &Node::name,
R"mydelimiter(
Name of the Node.
)mydelimiter")
.def("type", &Node::type,
R"mydelimiter(
Type of the node.
)mydelimiter")
.def("get_operator", &Node::getOperator,
R"mydelimiter(
Get the Operator object of the Node.
)mydelimiter")
.def("set_name", &Node::setName, py::arg("name"),
R"mydelimiter(
Set the Node name.
:param name: New name for the node.
:type name: str
:rtype: str
)mydelimiter")
.def("add_child",
(void (Node::*)(std::shared_ptr<Node>, const IOIndex_t, IOIndex_t)) &
Node::addChild,
py::arg("other_node"), py::arg("out_id") = 0, py::arg("other_in_id") = -1)
py::arg("other_node"), py::arg("out_id") = 0, py::arg("other_in_id") = gk_IODefaultIndex,
R"mydelimiter(
Link another Node to an output of the current Node.
:param other_node: Pointer to the other Node.
:type other_node: :py:class: Node
:param out_id: ID of the current Node output to connect to the other Node. Default to 0.
:type out_id: int
:param other_in_id: ID of the other Node input to connect to the current Node. Default to the first avaible data input.
:type other_in_id: int
)mydelimiter")
.def("add_child",
(void (Node::*)(std::shared_ptr<GraphView>, const IOIndex_t,
std::pair<std::shared_ptr<Node>, IOIndex_t>)) &
Node::addChild,
py::arg("other_graph"), py::arg("out_id") = 0,
py::arg("other_in_id") =
std::pair<std::shared_ptr<Node>, IOIndex_t>(nullptr, gk_IODefaultIndex))
.def("inputs", &Node::inputs)
.def("input", &Node::input, py::arg("inID"))
.def("outputs", &Node::outputs)
.def("output", &Node::output, py::arg("outID"))
.def("get_nb_inputs", &Node::nbInputs)
.def("get_nb_datainputs", &Node::nbDataInputs)
.def("get_nb_outputs", &Node::nbOutputs)
std::pair<std::shared_ptr<Node>, IOIndex_t>(nullptr, gk_IODefaultIndex),
R"mydelimiter(
Link a Node from a specific GraphView to the current Node.
:param other_view: Pointer to the GraphView whose content should be linked to the current Node.
:type other_view: :py:class: GraphView
:param out_id: ID of the current Node output to connect to the other Node. Default to 0.
:type out_id: int
:param other_in_id: Pair of Node and input connection ID for specifying the connection. If the GraphView whose content is linked has only one input Node, then it defaults to the first available data input ID of this Node.
:type other_in_id: tuple[:py:class: Node, int]
)mydelimiter")
.def("inputs", &Node::inputs,
R"mydelimiter(
Get ordered list of parent Node and the associated output index connected to the current Node's inputs.
:return: List of connections. When an input is not linked to any parent, the default value is (None, default_index)
:rtype: list[tuple[Node, int]]
)mydelimiter")
.def("input", &Node::input, py::arg("in_id"),
R"mydelimiter(
Get the parent Node and the associated output index connected to the i-th input of the current Node.
:param in_id: input index of the current Node object.
:type in_id: int
:return: i-th connection. When an input is not linked to any parent, the default value is (None, default_index)
:rtype: tuple[Node, int]
)mydelimiter")
.def("outputs", &Node::outputs,
R"mydelimiter(
Get, for each output of the Node, a list of the children Node and the associated input index connected to it.
:return: List of a list of connections. When an outut is not linked to any child, its list a empty.
:rtype: list[list[tuple[Node, int]]]
)mydelimiter")
.def("output", &Node::output, py::arg("out_id"),
R"mydelimiter(
Get a list of the children Node for a specific output and the associated input index connected to it.
:param out_id: input index of the current Node object.
:type out_id: int
:return: i-th connection. When an input is not linked to any parent, the default value is (None, default_index)
:rtype: list[tuple[Node, int]]
)mydelimiter")
.def("get_nb_inputs", &Node::nbInputs,
R"mydelimiter(
Number of inputs.
:rtype: int
)mydelimiter")
.def("get_nb_datainputs", &Node::nbDataInputs,
R"mydelimiter(
Number of data inputs.
:rtype: int
)mydelimiter")
.def("get_nb_outputs", &Node::nbOutputs,
R"mydelimiter(
Number of outputs.
:rtype: int
)mydelimiter")
.def("__call__", &Node::operator(), py::arg("connectors"));
}
} // namespace Aidge
......@@ -65,9 +65,10 @@ class CMakeBuild(build_ext):
# Impose to use the executable of the python
# used to launch setup.py to setup PythonInterp
param_py = "-DPYTHON_EXECUTABLE=" + sys.executable
self.spawn(['cmake', str(cwd), param_py, '-DTEST=OFF', f'-DCMAKE_INSTALL_PREFIX:PATH={build_temp}/install'])
install_path = f"{build_temp}/install" if "AIDGE_INSTALL" not in os.environ else os.environ["AIDGE_INSTALL"]
self.spawn(['cmake', str(cwd), param_py, '-DTEST=OFF', f'-DCMAKE_INSTALL_PREFIX:PATH={install_path}'])
if not self.dry_run:
self.spawn(['make', 'all', 'install', '-j', max_jobs])
os.chdir(str(cwd))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment