Skip to content

Commit

Permalink
Correct issue #198 : weighted sum is a weighted average
Browse files Browse the repository at this point in the history
  • Loading branch information
christophe0606 committed Jul 17, 2024
1 parent fc6da81 commit bc00d19
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 59 deletions.
6 changes: 3 additions & 3 deletions Include/dsp/support_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,16 +499,16 @@ const q7_t * pSrc,


/**
* @brief Weighted sum
* @brief Weighted average
*
*
* @param[in] *in Array of input values.
* @param[in] *weigths Weights
* @param[in] blockSize Number of samples in the input array.
* @return Weighted sum
* @return Weighted average
*
*/
float32_t arm_weighted_sum_f32(const float32_t *in
float32_t arm_weighted_average_f32(const float32_t *in
, const float32_t *weigths
, uint32_t blockSize);

Expand Down
6 changes: 3 additions & 3 deletions Include/dsp/support_functions_f16.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ void arm_f16_to_float(const float16_t * pSrc, float32_t * pDst, uint32_t blockSi


/**
* @brief Weighted sum
* @brief Weighted average
* @param[in] *in Array of input values.
* @param[in] *weigths Weights
* @param[in] blockSize Number of samples in the input array.
* @return Weighted sum
* @return Weighted average
*/
float16_t arm_weighted_sum_f16(const float16_t *in
float16_t arm_weighted_average_f16(const float16_t *in
, const float16_t *weigths
, uint32_t blockSize);

Expand Down
6 changes: 3 additions & 3 deletions PythonWrapper/cmsisdsp_pkg/src/cmsisdsp_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ cmsis_arm_barycenter_f32(PyObject *obj, PyObject *args)
}

static PyObject *
cmsis_arm_weighted_sum_f32(PyObject *obj, PyObject *args)
cmsis_arm_weighted_average_f32(PyObject *obj, PyObject *args)
{

PyObject *pSrcA=NULL; // input
Expand All @@ -919,7 +919,7 @@ cmsis_arm_weighted_sum_f32(PyObject *obj, PyObject *args)
blockSize = arraySizepSrcA ;


dst=arm_weighted_sum_f32(pSrcA_converted,pSrcB_converted,blockSize);
dst=arm_weighted_average_f32(pSrcA_converted,pSrcB_converted,blockSize);
PyObject* pDstOBJ=Py_BuildValue("f",dst);
PyObject *pythonResult = Py_BuildValue("O",pDstOBJ);

Expand Down Expand Up @@ -993,7 +993,7 @@ static PyMethodDef CMSISDSPMethods[] = {
{"arm_sort_f32", cmsis_arm_sort_f32, METH_VARARGS,""},
{"arm_sort_init_f32", cmsis_arm_sort_init_f32, METH_VARARGS,""},
{"arm_barycenter_f32", cmsis_arm_barycenter_f32, METH_VARARGS,""},
{"arm_weighted_sum_f32", cmsis_arm_weighted_sum_f32, METH_VARARGS,""},
{"arm_weighted_average_f32", cmsis_arm_weighted_average_f32, METH_VARARGS,""},

{"error_out", (PyCFunction)error_out, METH_NOARGS, NULL},
{NULL, NULL, 0, NULL} /* Sentinel */
Expand Down
4 changes: 2 additions & 2 deletions Source/SupportFunctions/Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ SupportFunctions/arm_quick_sort_f32.c
SupportFunctions/arm_selection_sort_f32.c
SupportFunctions/arm_sort_f32.c
SupportFunctions/arm_sort_init_f32.c
SupportFunctions/arm_weighted_sum_f32.c
SupportFunctions/arm_weighted_average_f32.c
)


Expand All @@ -59,7 +59,7 @@ target_sources(CMSISDSP PRIVATE SupportFunctions/arm_f16_to_q15.c)
target_sources(CMSISDSP PRIVATE SupportFunctions/arm_q15_to_f16.c)
target_sources(CMSISDSP PRIVATE SupportFunctions/arm_float_to_f16.c)
target_sources(CMSISDSP PRIVATE SupportFunctions/arm_f16_to_float.c)
target_sources(CMSISDSP PRIVATE SupportFunctions/arm_weighted_sum_f16.c)
target_sources(CMSISDSP PRIVATE SupportFunctions/arm_weighted_average_f16.c)
target_sources(CMSISDSP PRIVATE SupportFunctions/arm_barycenter_f16.c)
target_sources(CMSISDSP PRIVATE SupportFunctions/arm_f16_to_f64.c)
target_sources(CMSISDSP PRIVATE SupportFunctions/arm_f64_to_f16.c)
Expand Down
2 changes: 1 addition & 1 deletion Source/SupportFunctions/SupportFunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#include "arm_selection_sort_f32.c"
#include "arm_sort_f32.c"
#include "arm_sort_init_f32.c"
#include "arm_weighted_sum_f32.c"
#include "arm_weighted_average_f32.c"

#include "arm_f64_to_float.c"
#include "arm_f64_to_q31.c"
Expand Down
2 changes: 1 addition & 1 deletion Source/SupportFunctions/SupportFunctionsF16.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
#include "arm_f64_to_f16.c"
#include "arm_q15_to_f16.c"
#include "arm_float_to_f16.c"
#include "arm_weighted_sum_f16.c"
#include "arm_weighted_average_f16.c"
#include "arm_barycenter_f16.c"
21 changes: 11 additions & 10 deletions ...e/SupportFunctions/arm_weighted_sum_f16.c → ...pportFunctions/arm_weighted_average_f16.c
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ----------------------------------------------------------------------
* Project: CMSIS DSP Library
* Title: arm_weighted_sum_f16.c
* Description: Weighted Sum
* Title: arm_weighted_average_f16.c
* Description: Weighted average
*
* $Date: 23 April 2021
* $Revision: V1.9.0
Expand Down Expand Up @@ -38,34 +38,35 @@
*/

/**
@defgroup weightedsum Weighted Sum
@defgroup weightedaverage Weighted Average
Weighted sum of values
Weighted average of values
*/


/**
* @addtogroup weightedsum
* @addtogroup weightedaverage
* @{
*/


/**
* @brief Weighted sum
* @brief Weighted average
*
*
* @param[in] *in Array of input values.
* @param[in] *weigths Weights
* @param[in] blockSize Number of samples in the input array.
* @return Weighted sum
*
* @return Weighted average
*
*/

#if defined(ARM_MATH_MVE_FLOAT16) && !defined(ARM_MATH_AUTOVECTORIZE)

#include "arm_helium_utils.h"

ARM_DSP_ATTRIBUTE float16_t arm_weighted_sum_f16(const float16_t *in,const float16_t *weigths, uint32_t blockSize)
ARM_DSP_ATTRIBUTE float16_t arm_weighted_average_f16(const float16_t *in,const float16_t *weigths, uint32_t blockSize)
{
_Float16 accum1, accum2;
float16x8_t accum1V, accum2V;
Expand Down Expand Up @@ -112,7 +113,7 @@ ARM_DSP_ATTRIBUTE float16_t arm_weighted_sum_f16(const float16_t *in,const float

#else

ARM_DSP_ATTRIBUTE float16_t arm_weighted_sum_f16(const float16_t *in, const float16_t *weigths, uint32_t blockSize)
ARM_DSP_ATTRIBUTE float16_t arm_weighted_average_f16(const float16_t *in, const float16_t *weigths, uint32_t blockSize)
{

_Float16 accum1, accum2;
Expand All @@ -139,7 +140,7 @@ ARM_DSP_ATTRIBUTE float16_t arm_weighted_sum_f16(const float16_t *in, const floa
#endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */

/**
* @} end of weightedsum group
* @} end of weightedaverage group
*/

#endif /* #if defined(ARM_FLOAT16_SUPPORTED) */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* ----------------------------------------------------------------------
* Project: CMSIS DSP Library
* Title: arm_weighted_sum_f32.c
* Description: Weighted Sum
* Title: arm_weighted_average_f32.c
* Description: Weighted Average
*
* $Date: 23 April 2021
* $Revision: V1.9.0
Expand Down Expand Up @@ -32,27 +32,27 @@
#include "dsp/support_functions.h"

/**
* @addtogroup weightedsum
* @addtogroup weightedaverage
* @{
*/


/**
* @brief Weighted sum
* @brief Weighted average
*
*
* @param[in] *in Array of input values.
* @param[in] *weigths Weights
* @param[in] blockSize Number of samples in the input array.
* @return Weighted sum
* @return Weighted average
*
*/

#if defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE)

#include "arm_helium_utils.h"

ARM_DSP_ATTRIBUTE float32_t arm_weighted_sum_f32(const float32_t *in,const float32_t *weigths, uint32_t blockSize)
ARM_DSP_ATTRIBUTE float32_t arm_weighted_average_f32(const float32_t *in,const float32_t *weigths, uint32_t blockSize)
{
float32_t accum1, accum2;
f32x4_t accum1V, accum2V;
Expand Down Expand Up @@ -101,7 +101,7 @@ ARM_DSP_ATTRIBUTE float32_t arm_weighted_sum_f32(const float32_t *in,const float
#if defined(ARM_MATH_NEON)

#include "NEMath.h"
ARM_DSP_ATTRIBUTE float32_t arm_weighted_sum_f32(const float32_t *in,const float32_t *weigths, uint32_t blockSize)
ARM_DSP_ATTRIBUTE float32_t arm_weighted_average_f32(const float32_t *in,const float32_t *weigths, uint32_t blockSize)
{

float32_t accum1, accum2;
Expand Down Expand Up @@ -155,7 +155,7 @@ ARM_DSP_ATTRIBUTE float32_t arm_weighted_sum_f32(const float32_t *in,const float
return(accum1 / accum2);
}
#else
ARM_DSP_ATTRIBUTE float32_t arm_weighted_sum_f32(const float32_t *in, const float32_t *weigths, uint32_t blockSize)
ARM_DSP_ATTRIBUTE float32_t arm_weighted_average_f32(const float32_t *in, const float32_t *weigths, uint32_t blockSize)
{

float32_t accum1, accum2;
Expand Down Expand Up @@ -183,5 +183,5 @@ ARM_DSP_ATTRIBUTE float32_t arm_weighted_sum_f32(const float32_t *in, const floa
#endif /* defined(ARM_MATH_MVEF) && !defined(ARM_MATH_AUTOVECTORIZE) */

/**
* @} end of weightedsum group
* @} end of weightedaverage group
*/
6 changes: 3 additions & 3 deletions Testing/Source/Benchmarks/SupportF16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
arm_float_to_f16(this->pSrcF32,this->pDst,this->nbSamples);
}

void SupportF16::test_weighted_sum_f16()
void SupportF16::test_weighted_average_f16()
{
arm_weighted_sum_f16(this->pSrc, this->pWeights,this->nbSamples);
arm_weighted_average_f16(this->pSrc, this->pWeights,this->nbSamples);
}

void SupportF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
Expand Down Expand Up @@ -56,7 +56,7 @@
break;


case TEST_WEIGHTED_SUM_F16_5:
case TEST_WEIGHTED_AVERAGE_F16_5:
samples.reload(SupportF16::INPUTS6_F16_ID,mgr,this->nbSamples);
weights.reload(SupportF16::WEIGHTS6_F16_ID,mgr,this->nbSamples);

Expand Down
6 changes: 3 additions & 3 deletions Testing/Source/Benchmarks/SupportF32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
arm_q31_to_float(this->pSrcQ31,this->pDst,this->nbSamples);
}

void SupportF32::test_weighted_sum_f32()
void SupportF32::test_weighted_average_f32()
{
arm_weighted_sum_f32(this->pSrc, this->pWeights,this->nbSamples);
arm_weighted_average_f32(this->pSrc, this->pWeights,this->nbSamples);
}

void SupportF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>& params,Client::PatternMgr *mgr)
Expand Down Expand Up @@ -64,7 +64,7 @@
this->pSrcQ7=samplesQ7.ptr();
break;

case TEST_WEIGHTED_SUM_F32_6:
case TEST_WEIGHTED_AVERAGE_F32_6:
samples.reload(SupportF32::INPUTS6_F32_ID,mgr,this->nbSamples);
weights.reload(SupportF32::WEIGHTS6_F32_ID,mgr,this->nbSamples);

Expand Down
10 changes: 5 additions & 5 deletions Testing/Source/Tests/SupportTestsF16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define ABS_Q7_ERROR ((q7_t)10)


void SupportTestsF16::test_weighted_sum_f16()
void SupportTestsF16::test_weighted_average_f16()
{
const float16_t *inp = input.ptr();
const float16_t *coefsp = coefs.ptr();
Expand All @@ -28,7 +28,7 @@ void SupportTestsF16::test_weighted_sum_f16()
float16_t *outp = output.ptr();


*outp=arm_weighted_sum_f16(inp, coefsp,this->nbSamples);
*outp=arm_weighted_average_f16(inp, coefsp,this->nbSamples);

ASSERT_CLOSE_ERROR(*outp,refp[this->offset],ABS_WEIGHTEDSUM_ERROR,REL_WEIGHTEDSUM_ERROR);
ASSERT_EMPTY_TAIL(output);
Expand Down Expand Up @@ -160,7 +160,7 @@ void SupportTestsF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>&
switch(id)
{

case TEST_WEIGHTED_SUM_F16_1:
case TEST_WEIGHTED_AVERAGE_F16_1:
this->nbSamples = 7;
input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
Expand All @@ -171,7 +171,7 @@ void SupportTestsF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>&
this->offset=0;
break;

case TEST_WEIGHTED_SUM_F16_2:
case TEST_WEIGHTED_AVERAGE_F16_2:
this->nbSamples = 16;
input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
Expand All @@ -182,7 +182,7 @@ void SupportTestsF16::setUp(Testing::testID_t id,std::vector<Testing::param_t>&
this->offset=1;
break;

case TEST_WEIGHTED_SUM_F16_3:
case TEST_WEIGHTED_AVERAGE_F16_3:
this->nbSamples = 23;
input.reload(SupportTestsF16::INPUTS_F16_ID,mgr,this->nbSamples);
coefs.reload(SupportTestsF16::WEIGHTS_F16_ID,mgr,this->nbSamples);
Expand Down
10 changes: 5 additions & 5 deletions Testing/Source/Tests/SupportTestsF32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define ABS_Q7_ERROR ((q7_t)10)


void SupportTestsF32::test_weighted_sum_f32()
void SupportTestsF32::test_weighted_average_f32()
{
const float32_t *inp = input.ptr();
const float32_t *coefsp = coefs.ptr();
Expand All @@ -20,7 +20,7 @@ void SupportTestsF32::test_weighted_sum_f32()
float32_t *outp = output.ptr();


*outp=arm_weighted_sum_f32(inp, coefsp,this->nbSamples);
*outp=arm_weighted_average_f32(inp, coefsp,this->nbSamples);


ASSERT_REL_ERROR(*outp,refp[this->offset],REL_ERROR);
Expand Down Expand Up @@ -436,7 +436,7 @@ void SupportTestsF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>&
(void)paramsArgs;
switch(id)
{
case TEST_WEIGHTED_SUM_F32_1:
case TEST_WEIGHTED_AVERAGE_F32_1:
this->nbSamples = 3;
input.reload(SupportTestsF32::INPUTS_F32_ID,mgr,this->nbSamples);
coefs.reload(SupportTestsF32::WEIGHTS_F32_ID,mgr,this->nbSamples);
Expand All @@ -447,7 +447,7 @@ void SupportTestsF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>&
this->offset=0;
break;

case TEST_WEIGHTED_SUM_F32_2:
case TEST_WEIGHTED_AVERAGE_F32_2:
this->nbSamples = 8;
input.reload(SupportTestsF32::INPUTS_F32_ID,mgr,this->nbSamples);
coefs.reload(SupportTestsF32::WEIGHTS_F32_ID,mgr,this->nbSamples);
Expand All @@ -458,7 +458,7 @@ void SupportTestsF32::setUp(Testing::testID_t id,std::vector<Testing::param_t>&
this->offset=1;
break;

case TEST_WEIGHTED_SUM_F32_3:
case TEST_WEIGHTED_AVERAGE_F32_3:
this->nbSamples = 11;
input.reload(SupportTestsF32::INPUTS_F32_ID,mgr,this->nbSamples);
coefs.reload(SupportTestsF32::WEIGHTS_F32_ID,mgr,this->nbSamples);
Expand Down
4 changes: 2 additions & 2 deletions Testing/Source/Tests/SupportTestsF64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define ABS_Q7_ERROR ((q7_t)10)

/*
void SupportTestsF64::test_weighted_sum_f64()
void SupportTestsF64::test_weighted_average_f64()
{
const float64_t *inp = input.ptr();
const float64_t *coefsp = coefs.ptr();
Expand All @@ -20,7 +20,7 @@ void SupportTestsF64::test_weighted_sum_f64()
float64_t *outp = output.ptr();
*outp=arm_weighted_sum_f64(inp, coefsp,this->nbSamples);
*outp=arm_weighted_average_f64(inp, coefsp,this->nbSamples);
ASSERT_REL_ERROR(*outp,refp[this->offset],REL_ERROR);
Expand Down
Loading

0 comments on commit bc00d19

Please sign in to comment.