From ae8a7596d2d80ff2b9fd3890913a29cfba81b08c Mon Sep 17 00:00:00 2001 From: Jerome Hue <jerome.hue@cea.fr> Date: Fri, 14 Feb 2025 11:11:02 +0100 Subject: [PATCH] Add basic test for Spikegen functions --- unit_tests/data/Test_Spikegen.cpp | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/unit_tests/data/Test_Spikegen.cpp b/unit_tests/data/Test_Spikegen.cpp index e69de29bb..d5255d725 100644 --- a/unit_tests/data/Test_Spikegen.cpp +++ b/unit_tests/data/Test_Spikegen.cpp @@ -0,0 +1,42 @@ +/******************************************************************************** + * Copyright (c) 2025 CEA-List + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0. + * + * SPDX-License-Identifier: EPL-2.0 + * + ********************************************************************************/ + +#include <cstdint> // std::uint8_t, std::uint16_t, std::int32_t +#include <vector> // std::vector + +#include <catch2/catch_test_macros.hpp> + +#include "aidge/data/Spikegen.hpp" +#include "aidge/data/Tensor.hpp" +#include "aidge/utils/ArrayHelpers.hpp" +#include "aidge/utils/TensorUtils.hpp" + + +namespace Aidge +{ +TEST_CASE("[core/data] SpikeGen zeros", "[SpikeGen]") { + auto input = Tensor(Array1D<float, 3>({0,0,0})); + auto expectedOutput = Tensor(Array2D<float, 3, 3>({{{0,0,0}, {0,0,0}, {0,0,0}}})); + + auto spikes = spikegenRate(std::make_shared<Tensor>(input), 3); + + approxEq<float>(spikes, expectedOutput); +} + +TEST_CASE("[core/data] SpikeGen ones", "[SpikeGen]") { + auto input = Tensor(Array1D<float, 3>({1,1,1})); + auto expectedOutput = Tensor(Array2D<float, 3, 3>({{{1,1,1}, {1,1,1}, {1,1,1}}})); + + auto spikes = spikegenRate(std::make_shared<Tensor>(input), 3); + + approxEq<float>(spikes, expectedOutput); +} +} // namespace Aidge -- GitLab