pulsatrix
Loading...
Searching...
No Matches
node.hpp
Go to the documentation of this file.
1
5#pragma once
6
7#include <cstddef>
8#include <optional>
9#include <string>
10#include <vector>
11
12#include "pulsatrix/op_type.hpp"
13#include "pulsatrix/shape.hpp"
14
15namespace pulsatrix {
16
18using NodeId = size_t;
19
29class Node {
30public:
38 Node(NodeId id, OpType op_type, Shape shape, std::optional<std::string> label = std::nullopt)
39 : id_(id), op_type_(op_type), shape_(std::move(shape)), label_(std::move(label)) {}
40
41 [[nodiscard]] NodeId id() const { return id_; }
42 [[nodiscard]] OpType op_type() const { return op_type_; }
43 [[nodiscard]] const Shape& shape() const { return shape_; }
44 [[nodiscard]] const std::optional<std::string>& label() const { return label_; }
45
47 [[nodiscard]] const std::vector<Node*>& parents() const { return parents_; }
48
50 [[nodiscard]] const std::vector<Node*>& children() const { return children_; }
51
53 void add_parent(Node* parent) { parents_.push_back(parent); }
54
56 void add_child(Node* child) { children_.push_back(child); }
57
58private:
59 NodeId id_;
60 OpType op_type_;
61 Shape shape_;
62 std::optional<std::string> label_;
63 std::vector<Node*> parents_;
64 std::vector<Node*> children_;
65};
66
67} // namespace pulsatrix
A single computation graph node. Owned exclusively by its ComputationGraph (see computation_graph....
Definition node.hpp:29
const std::vector< Node * > & parents() const
This node's parent nodes (edges point from parent to this node).
Definition node.hpp:47
const Shape & shape() const
Definition node.hpp:43
const std::vector< Node * > & children() const
This node's child nodes.
Definition node.hpp:50
void add_child(Node *child)
Registers child as a child of this node. Non-owning; child must outlive this node.
Definition node.hpp:56
OpType op_type() const
Definition node.hpp:42
const std::optional< std::string > & label() const
Definition node.hpp:44
void add_parent(Node *parent)
Registers parent as a parent of this node. Non-owning; parent must outlive this node.
Definition node.hpp:53
Node(NodeId id, OpType op_type, Shape shape, std::optional< std::string > label=std::nullopt)
Constructs a node.
Definition node.hpp:38
NodeId id() const
Definition node.hpp:41
An N-dimensional shape. A plain aggregate of dimensions with no invariant beyond "non-negative dimens...
Definition shape.hpp:24
Definition acquisition_functions.hpp:16
size_t NodeId
Stable identifier for a Node within its owning ComputationGraph.
Definition node.hpp:18
OpType
The op-type tag a Node carries. Charter Part 2 §3: nodes are tagged by a small closed set of op types...
Definition op_type.hpp:19
Closed set of operation categories every graph Node is tagged with.
Tensor dimension arithmetic – rank, element count, per-dimension access.