From c92b78e4c77c18165578a17caee985ad3a6108ce Mon Sep 17 00:00:00 2001 From: Jerome Hue <jerome.hue@cea.fr> Date: Tue, 4 Mar 2025 10:09:25 +0100 Subject: [PATCH] Format file and remove unused variable --- src/operator/HeavisideImpl.cpp | 51 +++++++++++++++------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/src/operator/HeavisideImpl.cpp b/src/operator/HeavisideImpl.cpp index 8349a0ad..3932eb33 100644 --- a/src/operator/HeavisideImpl.cpp +++ b/src/operator/HeavisideImpl.cpp @@ -13,42 +13,37 @@ #include <stdexcept> -#include "aidge/backend/cpu/operator/HeavisideImpl_kernels.hpp" #include "aidge/backend/cpu/data/GetCPUPtr.h" +#include "aidge/backend/cpu/operator/HeavisideImpl_kernels.hpp" #include "aidge/utils/ErrorHandling.hpp" template <> void Aidge::HeavisideImplCpu::forward() { - const Heaviside_Op &op_ = dynamic_cast<const Heaviside_Op &>(mOp); - std::shared_ptr<Tensor> input0 = op_.getInput(0); - std::shared_ptr<Tensor> output0 = op_.getOutput(0); - AIDGE_ASSERT(input0, "missing input #0"); - - const auto impl = - Registrar<HeavisideImplCpu>::create(getBestMatch(getRequiredSpec())); - - impl.forward(input0->size(), - getCPUPtr(mOp.getRawInput(0)), - getCPUPtr(mOp.getRawOutput(0)), - op_.value()); -} + const Heaviside_Op &op_ = dynamic_cast<const Heaviside_Op &>(mOp); + std::shared_ptr<Tensor> input0 = op_.getInput(0); + std::shared_ptr<Tensor> output0 = op_.getOutput(0); + AIDGE_ASSERT(input0, "missing input #0"); -template <> -void Aidge::HeavisideImplCpu::backward() { + const auto impl = + Registrar<HeavisideImplCpu>::create(getBestMatch(getRequiredSpec())); - // TODO: The following lines are assuming that the surrogate gradient is Atan - // remove that assumption by providing an attribute to Heaviside, - // allowing to choose between different surrogate gradients. - - const Heaviside_Op& op_ = dynamic_cast<const Heaviside_Op &>(mOp); + impl.forward(input0->size(), getCPUPtr(mOp.getRawInput(0)), + getCPUPtr(mOp.getRawOutput(0)), op_.value()); +} - const auto impl = Registrar<HeavisideImplCpu>::create(getBestMatch(getRequiredSpec())); +template <> void Aidge::HeavisideImplCpu::backward() { - auto gra_int0 = op_.getInput(0)->grad(); - auto gra_out0 = op_.getOutput(0)->grad(); + // TODO: The following lines are assuming that the surrogate gradient is Atan + // remove that assumption by providing an attribute to Heaviside, + // allowing to choose between different surrogate gradients. - std::shared_ptr<Tensor> in0 = op_.getInput(0); - std::shared_ptr<Tensor> out0 = op_.getOutput(0); + const Heaviside_Op &op_ = dynamic_cast<const Heaviside_Op &>(mOp); + const auto impl = + Registrar<HeavisideImplCpu>::create(getBestMatch(getRequiredSpec())); - impl.backward(gra_int0->size(), getCPUPtr(in0), getCPUPtr(gra_out0), getCPUPtr(gra_int0)); -} + auto in0 = op_.getInput(0); + auto gra_int0 = op_.getInput(0)->grad(); + auto gra_out0 = op_.getOutput(0)->grad(); + impl.backward(gra_int0->size(), getCPUPtr(in0), getCPUPtr(gra_out0), + getCPUPtr(gra_int0)); +} -- GitLab