Tensor as scalar
A Tensor is a scalar in the case of empty dimensions.
Problem
Scalars are not handled by Aidge.
For now, in OperatorTensor::forwardDims()
, operators check that their input is not empty to proceed in the computation of their output dimensions. However such behaviour prevents the propagation of scalar Tensors.
Actually, with the introduction of scalar Tensor, Tensor::empty()
has no real purpose anymore and should be removed entirely.
Solution
Remove the condition based on Tensors emptyness. Improve the GraphView::forwardDims()
function that calls successively OperatorTensor::forwardDims()
. GraphView::forwardDims()
could internaly create a very simple tree structure of its GraphView and call corresponding OperatorTensor::forwardDims()
function in the right order.
struct nodeDim {
std::uint8_t nb_active_parents;
std::shared_ptr<Node> associated_node;
nodeDims* children;
const std::uint8_t nb_children;
nodeDims(std::shared_ptr<Node> node) {
// create ``children`` list
}
/// if reaches 0 then the current nodeDim is a leaf of the graph
void update() {
--nb_active_parents;
}
void forward_dims() {
if (!nb_active_parents) {
std::static_pointer_cast<OperatorTensor>(associated_node -> getOperator()) -> computeOutputDims();
for (std::uint8_t idx; idx < nb_children; ++idx) {
children[static_cast<std::size_t>(idx)]->update();
}
}
}
}