diff --git a/include/aidge/operator/OperatorTensor.hpp b/include/aidge/operator/OperatorTensor.hpp index 19e2f13e4ff39fee181c6ad0cf2fbab510f22c3e..5a4fcb5f492bb60899f00e11f35793df0e65789f 100644 --- a/include/aidge/operator/OperatorTensor.hpp +++ b/include/aidge/operator/OperatorTensor.hpp @@ -43,7 +43,7 @@ public: /** * @brief Operator tensor constructor. This function is not meant to be called directly but by a derived class constructor * every operator class derive from this class. - * + * * @param[in] type : type of operator (i.e. "Add", "AveragePool",...) * @param[in] inputsCategory : describes the type of each input. * @param[in] nbOut : Number of tensors this operator will output @@ -67,11 +67,14 @@ public: // input management void setInput(const IOIndex_t inputIdx, const std::shared_ptr<Data>& data) override; const std::shared_ptr<Tensor>& getInput(const IOIndex_t inputIdx) const; + virtual const std::vector<std::shared_ptr<Tensor>>& getInputs() const; std::shared_ptr<Data> getRawInput(const IOIndex_t inputIdx) const override final; // output management void setOutput(const IOIndex_t outputIdx, const std::shared_ptr<Data>& data) const override; virtual const std::shared_ptr<Tensor>& getOutput(const IOIndex_t outputIdx) const; + virtual const std::vector<std::shared_ptr<Tensor>>& getOutputs() const; + std::shared_ptr<Aidge::Data> getRawOutput(const Aidge::IOIndex_t outputIdx) const override final; /////////////////////////////////////////////////// @@ -94,7 +97,7 @@ public: * - TOKEN mode means that forwarddims will only ensure that all inputs and outputs of the graph the node is within are connected. * @param[in] allowDataDependency if set to true, this means that this operator output dimensions depends on the dimensions of optional parameter tensors. * @return true if dims have been properly forwarded. false otherwise. If set to false, then forwardDims will enter in token mode. - * + * */ virtual bool forwardDims(bool allowDataDependency = false); virtual bool dimsForwarded() const; @@ -110,4 +113,4 @@ protected: }; } // namespace Aidge -#endif // AIDGE_CORE_OPERATOR_OPERATORTENSOR_H_ \ No newline at end of file +#endif // AIDGE_CORE_OPERATOR_OPERATORTENSOR_H_ diff --git a/python_binding/operator/pybind_OperatorTensor.cpp b/python_binding/operator/pybind_OperatorTensor.cpp index 8c515e321207605c20acc9e5b02271906c9707d1..2602e115d43d805451aa9f0836c8151b2cd4b109 100644 --- a/python_binding/operator/pybind_OperatorTensor.cpp +++ b/python_binding/operator/pybind_OperatorTensor.cpp @@ -26,7 +26,9 @@ namespace Aidge { void init_OperatorTensor(py::module& m){ py::class_<OperatorTensor, std::shared_ptr<OperatorTensor>, Operator>(m, "OperatorTensor") .def("get_output", &OperatorTensor::getOutput, py::arg("outputIdx")) + .def("get_outputs", &OperatorTensor::getOutputs) .def("get_input", &OperatorTensor::getInput, py::arg("inputIdx")) + .def("get_inputs", &OperatorTensor::getInputs) .def("set_output", (void (OperatorTensor::*)(const IOIndex_t, const std::shared_ptr<Data>&) const) &OperatorTensor::setOutput, py::arg("outputIdx"), py::arg("data")) .def("set_input", (void (OperatorTensor::*)(const IOIndex_t, const std::shared_ptr<Data>&)) &OperatorTensor::setInput, py::arg("outputIdx"), py::arg("data")) diff --git a/src/operator/OperatorTensor.cpp b/src/operator/OperatorTensor.cpp index 3bdb4b17127eb8a9115f8dec045db32bf041b00b..873e93f3296bae6c5eae8cf2b5ec7bacc82c45ce 100644 --- a/src/operator/OperatorTensor.cpp +++ b/src/operator/OperatorTensor.cpp @@ -92,6 +92,12 @@ const std::shared_ptr<Aidge::Tensor>& Aidge::OperatorTensor::getOutput(const Aid return mOutputs[outputIdx]; } +const std::vector<std::shared_ptr<Aidge::Tensor>>& Aidge::OperatorTensor::getOutputs() const{ + return mOutputs; +} +const std::vector<std::shared_ptr<Aidge::Tensor>>& Aidge::OperatorTensor::getInputs() const{ + return mInputs; +} std::vector<std::pair<std::vector<Aidge::DimSize_t>, std::vector<Aidge::DimSize_t>>> Aidge::OperatorTensor::computeReceptiveField( const std::vector<DimSize_t>& firstEltDims, diff --git a/src/operator/Slice.cpp b/src/operator/Slice.cpp index ab2d5b264ab0605f4b414287381c059e1289ce68..8e9f71e73efa7b3b99a3bcd03b5f23806a48869f 100644 --- a/src/operator/Slice.cpp +++ b/src/operator/Slice.cpp @@ -101,8 +101,9 @@ void Aidge::Slice_OpImpl::forward() { int step = op.steps()[axisIdx]; start = start >= 0 ? start: start + inputDims[axisIdx]; + start = std::max(0, std::min(start, static_cast<int>(inputDims[axisIdx]))); end = end >= 0 ? end: end + inputDims[axisIdx]; - + end = std::max(0, std::min(end, static_cast<int>(inputDims[axisIdx]))); // Generate the range of indices for this axis for (int idx = start; (step > 0) ? (idx < end) : (idx > end); idx += step) { ranges[axisIdx].push_back(idx); @@ -257,13 +258,13 @@ bool Aidge::Slice_Op::forwardDims(bool allowDataDependency) { static_cast<DimSize_t>(this->starts()[i]) : static_cast<DimSize_t>(this->starts()[i] + static_cast<DimSize_t>(getInput(0)->dims()[axis])); // Clamp start to the range [0, axis_dim] - start = std::max(static_cast<DimSize_t>(0), std::min(start, getInput(0)->dims()[axis]-1)); + start = std::max(static_cast<DimSize_t>(0), std::min(start, getInput(0)->dims()[axis])); DimSize_t end = this->ends()[i] >= 0 ? static_cast<DimSize_t>(this->ends()[i]) : static_cast<DimSize_t>(this->ends()[i] + static_cast<DimSize_t>(getInput(0)->dims()[axis])); // Clamp end to the range [0, axis_dim] - end = std::max(static_cast<DimSize_t>(0), std::min(end, getInput(0)->dims()[axis]-1)); + end = std::max(static_cast<DimSize_t>(0), std::min(end, getInput(0)->dims()[axis])); const std::int64_t step = this->steps()[i]; AIDGE_ASSERT(step != 0, "Slice_Op: Step ({}) must have a non-zero value on axis {}!", this->steps(), axis);