| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037 |
- /* ----------------------------------------------------------------------
- * Project: CMSIS DSP Library
- * Title: Error.cpp
- * Description: Error functions
- *
- * $Date: 20. June 2019
- * $Revision: V1.0.0
- *
- * Target Processor: Cortex-M cores
- * -------------------------------------------------------------------- */
- /*
- * Copyright (C) 2010-2019 ARM Limited or its affiliates. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- #include <cstdlib>
- #include <cstdio>
- #include "arm_math_types.h"
- #include "arm_math_types_f16.h"
- #include "Error.h"
- namespace Client {
- template <typename T>
- void assert_not_empty_generic(unsigned long nb, AnyPattern<T> &p)
- {
- if (p.nbSamples() == 0)
- {
- throw (Error(EMPTY_PATTERN_ERROR,nb));
- }
- if (p.ptr() == NULL)
- {
- throw (Error(EMPTY_PATTERN_ERROR,nb));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,double pa, double pb, double threshold)
- {
- if (fabs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %g > %g (%g,%g)",fabs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,float32_t pa, float32_t pb, float32_t threshold)
- {
- if (fabs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %g > %g (%g,%g)",fabs(pa - pb) , threshold, pa, pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- #if !defined (__CC_ARM) && defined(ARM_FLOAT16_SUPPORTED)
- template <>
- void assert_near_equal(unsigned long nb,float16_t pa, float16_t pb, float16_t threshold)
- {
- if (fabs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %g > %g (%g,%g)",fabs(pa - pb) , threshold, pa, pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- #endif
- template <>
- void assert_near_equal(unsigned long nb,q63_t pa, q63_t pb, q63_t threshold)
- {
- if (abs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %lld > %lld (%016llX,%016llX)",abs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,q31_t pa, q31_t pb, q31_t threshold)
- {
- if (abs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %d > %d (%08X,%08X)",abs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,q15_t pa, q15_t pb, q15_t threshold)
- {
- if (abs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %d > %d (%04X,%04X)",abs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- template <>
- void assert_near_equal(unsigned long nb,q7_t pa, q7_t pb, q7_t threshold)
- {
- if (abs(pa - pb) > threshold)
- {
- char details[200];
- sprintf(details,"diff %d > %d (%02X,%02X)",abs(pa - pb) , threshold,pa,pb);
- throw (Error(EQUAL_ERROR,nb,details));
- }
- };
- void assert_not_empty(unsigned long nb, AnyPattern<float64_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<float32_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_not_empty(unsigned long nb, AnyPattern<float16_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- #endif
- void assert_not_empty(unsigned long nb, AnyPattern<q63_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<q31_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<q15_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<q7_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<uint32_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<uint16_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_not_empty(unsigned long nb, AnyPattern<uint8_t> &p)
- {
- assert_not_empty_generic(nb,p);
- }
- void assert_relative_error(unsigned long nb,float64_t &a, float64_t &b, double threshold)
- {
- float64_t rel,delta,average;
- delta=abs(a-b);
- average = (abs(a) + abs(b)) / 2.0f;
- if (average !=0)
- {
- rel = delta / average;
- //printf("%6.9f %6.9f %6.9f %g %g\n",a,b,rel,delta,average);
- if (rel > threshold)
- {
- //printf("rel = %g, threshold %g \n",rel,threshold);
- char details[200];
- sprintf(details,"diff (%g,%g), %g > %g",a,b,rel , threshold);
- throw (Error(RELATIVE_ERROR,nb,details));
- }
- }
- };
- void assert_relative_error(unsigned long nb,float32_t &a, float32_t &b, double threshold)
- {
- double rel,delta,average;
- delta=abs(a-b);
- average = (abs((float)a) + abs((float)b)) / 2.0f;
- if (average !=0)
- {
- rel = delta / average;
- //printf("%6.9f %6.9f %6.9f %g %g\n",a,b,rel,delta,average);
- if (rel > threshold)
- {
- //printf("rel = %g, threshold %g \n",rel,threshold);
- char details[200];
- sprintf(details,"diff (%g,%g), %g > %g",a,b,rel , threshold);
- throw (Error(RELATIVE_ERROR,nb,details));
- }
- }
- };
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_relative_error(unsigned long nb,float16_t &a, float16_t &b, double threshold)
- {
- double rel,delta,average;
- delta=abs(a-b);
- average = (abs(a) + abs(b)) / 2.0f;
- if (average !=0)
- {
- rel = delta / average;
- //printf("%6.9f %6.9f %6.9f %g %g\n",a,b,rel,delta,average);
- if (rel > threshold)
- {
- //printf("rel = %g, threshold %g \n",rel,threshold);
- char details[200];
- sprintf(details,"diff (%g,%g), %g > %g",a,b,rel , threshold);
- throw (Error(RELATIVE_ERROR,nb,details));
- }
- }
- };
- #endif
- void assert_relative_error(unsigned long nb,AnyPattern<float64_t> &pa, AnyPattern<float64_t> &pb, double threshold)
- {
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- float64_t *ptrA = pa.ptr();
- float64_t *ptrB = pb.ptr();
- char id[40];
- for(i=0; i < pa.nbSamples(); i++)
- {
- try
- {
- assert_relative_error(nb,ptrA[i],ptrB[i],threshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
- }
- };
- void assert_relative_error(unsigned long nb,AnyPattern<float32_t> &pa, AnyPattern<float32_t> &pb, double threshold)
- {
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- float32_t *ptrA = pa.ptr();
- float32_t *ptrB = pb.ptr();
- char id[40];
- for(i=0; i < pa.nbSamples(); i++)
- {
- try
- {
- assert_relative_error(nb,ptrA[i],ptrB[i],threshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
- }
- };
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_relative_error(unsigned long nb,AnyPattern<float16_t> &pa, AnyPattern<float16_t> &pb, double threshold)
- {
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- float16_t *ptrA = pa.ptr();
- float16_t *ptrB = pb.ptr();
- char id[40];
- for(i=0; i < pa.nbSamples(); i++)
- {
- try
- {
- assert_relative_error(nb,ptrA[i],ptrB[i],threshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
- }
- };
- #endif
- void assert_close_error(unsigned long nb,float64_t &ref, float64_t &val, double absthreshold,double relthreshold)
- {
-
- if (abs(val - ref) > (absthreshold + relthreshold * abs(ref)))
- {
- char details[200];
- sprintf(details,"close %g : abs=%g, rel=%g",abs(val - ref) , absthreshold,relthreshold);
- throw (Error(CLOSE_ERROR,nb,details));
- }
- };
- void assert_close_error(unsigned long nb,AnyPattern<float64_t> &pref, AnyPattern<float64_t> &pval, double absthreshold,double relthreshold)
- {
- ASSERT_NOT_EMPTY(pref);
- ASSERT_NOT_EMPTY(pval);
- if (pref.nbSamples() != pval.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- char id[40];
- float64_t *ptrA = pref.ptr();
- float64_t *ptrB = pval.ptr();
- for(i=0; i < pref.nbSamples(); i++)
- {
- try
- {
- assert_close_error(nb,ptrA[i],ptrB[i],absthreshold,relthreshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
-
- }
- };
- void assert_close_error(unsigned long nb,float32_t &ref, float32_t &val, double absthreshold,double relthreshold)
- {
-
- if (abs(val - ref) > (absthreshold + relthreshold * abs(ref)))
- {
- char details[200];
- sprintf(details,"close %g : abs=%g, rel=%g",abs(val - ref) , absthreshold,relthreshold);
- throw (Error(CLOSE_ERROR,nb,details));
- }
- };
- void assert_close_error(unsigned long nb,AnyPattern<float32_t> &pref, AnyPattern<float32_t> &pval, double absthreshold,double relthreshold)
- {
- ASSERT_NOT_EMPTY(pref);
- ASSERT_NOT_EMPTY(pval);
- if (pref.nbSamples() != pval.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- char id[40];
- float32_t *ptrA = pref.ptr();
- float32_t *ptrB = pval.ptr();
- for(i=0; i < pref.nbSamples(); i++)
- {
- try
- {
- assert_close_error(nb,ptrA[i],ptrB[i],absthreshold,relthreshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
-
- }
- };
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_close_error(unsigned long nb,float16_t &ref, float16_t &val, double absthreshold,double relthreshold)
- {
-
- if (abs((float)val - (float)ref) > (absthreshold + relthreshold * abs((float)ref)))
- {
- char details[200];
- sprintf(details,"close %g : abs=%g, rel=%g",abs(val - ref) , absthreshold,relthreshold);
- throw (Error(CLOSE_ERROR,nb,details));
- }
- };
- void assert_close_error(unsigned long nb,AnyPattern<float16_t> &pref, AnyPattern<float16_t> &pval, double absthreshold,double relthreshold)
- {
- ASSERT_NOT_EMPTY(pref);
- ASSERT_NOT_EMPTY(pval);
- if (pref.nbSamples() != pval.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- unsigned long i=0;
- char id[40];
- float16_t *ptrA = pref.ptr();
- float16_t *ptrB = pval.ptr();
- for(i=0; i < pref.nbSamples(); i++)
- {
- try
- {
- assert_close_error(nb,ptrA[i],ptrB[i],absthreshold,relthreshold);
- }
- catch(Error &err)
- {
- sprintf(id," (nb=%lu)",i+1);
- strcat(err.details,id);
- throw(err);
- }
-
- }
- };
- #endif
- /**
- * @brief Calculation of SNR
- * @param float* Pointer to the reference buffer
- * @param float* Pointer to the test buffer
- * @param uint32_t total number of samples
- * @return float SNR
- * The function calculates signal to noise ratio for the reference output
- * and test output
- */
- /* If NaN, force SNR to 0.0 to ensure test will fail */
- #define IFNANRETURNZERO(val)\
- if (isnan((val))) \
- { \
- return(0.0); \
- }
- #define IFINFINITERETURN(val,def)\
- if (isinf((val))) \
- { \
- if ((val) > 0) \
- { \
- return(def); \
- } \
- else \
- { \
- return(-def); \
- } \
- }
- float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- for (i = 0; i < buffSize; i++)
- {
- /* Checking for a NAN value in pRef array */
- IFNANRETURNZERO(pRef[i]);
-
- /* Checking for a NAN value in pTest array */
- IFNANRETURNZERO(pTest[i]);
- EnergySignal += pRef[i] * pRef[i];
- EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]);
- }
- /* Checking for a NAN value in EnergyError */
- IFNANRETURNZERO(EnergyError);
- SNR = 10 * log10f (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
-
- return (SNR);
- }
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- float arm_snr_f16(float16_t *pRef, float16_t *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- for (i = 0; i < buffSize; i++)
- {
- /* Checking for a NAN value in pRef array */
- IFNANRETURNZERO((float)pRef[i]);
-
- /* Checking for a NAN value in pTest array */
- IFNANRETURNZERO((float)pTest[i]);
- EnergySignal += pRef[i] * pRef[i];
- EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]);
- }
- /* Checking for a NAN value in EnergyError */
- IFNANRETURNZERO(EnergyError);
- SNR = 10 * log10f (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
-
- return (SNR);
- }
- #endif
- float arm_snr_q63(q63_t *pRef, q63_t *pTest, uint32_t buffSize)
- {
- double EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- double testVal,refVal;
- for (i = 0; i < buffSize; i++)
- {
-
- testVal = ((double)pTest[i]) / 9223372036854775808.0;
- refVal = ((double)pRef[i]) / 9223372036854775808.0;
- EnergySignal += refVal * refVal;
- EnergyError += (refVal - testVal) * (refVal - testVal);
- }
- SNR = 10 * log10 (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
-
- //printf("SNR = %f\n",SNR);
- return (SNR);
- }
- float arm_snr_q31(q31_t *pRef, q31_t *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- float32_t testVal,refVal;
- for (i = 0; i < buffSize; i++)
- {
-
- testVal = ((float32_t)pTest[i]) / 2147483648.0f;
- refVal = ((float32_t)pRef[i]) / 2147483648.0f;
- EnergySignal += refVal * refVal;
- EnergyError += (refVal - testVal) * (refVal - testVal);
- }
- SNR = 10 * log10f (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
-
- //printf("SNR = %f\n",SNR);
- return (SNR);
- }
- float arm_snr_q15(q15_t *pRef, q15_t *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
- float32_t testVal,refVal;
- for (i = 0; i < buffSize; i++)
- {
-
- testVal = ((float32_t)pTest[i]) / 32768.0f;
- refVal = ((float32_t)pRef[i]) / 32768.0f;
- EnergySignal += refVal * refVal;
- EnergyError += (refVal - testVal) * (refVal - testVal);
- }
- SNR = 10 * log10f (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
- //printf("SNR = %f\n",SNR);
- return (SNR);
- }
- float arm_snr_q7(q7_t *pRef, q7_t *pTest, uint32_t buffSize)
- {
- float EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- float SNR;
-
- float32_t testVal,refVal;
- for (i = 0; i < buffSize; i++)
- {
-
- testVal = ((float32_t)pTest[i]) / 128.0f;
- refVal = ((float32_t)pRef[i]) / 128.0f;
- EnergySignal += refVal * refVal;
- EnergyError += (refVal - testVal) * (refVal - testVal);
- }
- SNR = 10 * log10f (EnergySignal / EnergyError);
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
- return (SNR);
- }
- double arm_snr_f64(double *pRef, double *pTest, uint32_t buffSize)
- {
- double EnergySignal = 0.0, EnergyError = 0.0;
- uint32_t i;
- double SNR;
-
- for (i = 0; i < buffSize; i++)
- {
- /* Checking for a NAN value in pRef array */
- IFNANRETURNZERO(pRef[i]);
-
- /* Checking for a NAN value in pTest array */
- IFNANRETURNZERO(pTest[i]);
-
- EnergySignal += pRef[i] * pRef[i];
- EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]);
- }
- /* Checking for a NAN value in EnergyError */
- IFNANRETURNZERO(EnergyError);
- SNR = 10 * log10 (EnergySignal / EnergyError);
- /* Checking for a NAN value in SNR */
- IFNANRETURNZERO(SNR);
- IFINFINITERETURN(SNR,100000.0);
- return (SNR);
- }
- void assert_snr_error(unsigned long nb,AnyPattern<float32_t> &pa,AnyPattern<float32_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- float32_t *ptrA = pa.ptr();
- float32_t *ptrB = pb.ptr();
- snr = arm_snr_f32(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,float32_t a,float32_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_f32(&a, &b, 1);
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- #if !defined( __CC_ARM ) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_snr_error(unsigned long nb,AnyPattern<float16_t> &pa,AnyPattern<float16_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- float16_t *ptrA = pa.ptr();
- float16_t *ptrB = pb.ptr();
- snr = arm_snr_f16(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- #endif
- #if !defined (__CC_ARM) && defined(ARM_FLOAT16_SUPPORTED)
- void assert_snr_error(unsigned long nb,float16_t a,float16_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_f16(&a, &b, 1);
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- #endif
- void assert_snr_error(unsigned long nb,AnyPattern<float64_t> &pa,AnyPattern<float64_t> &pb, float64_t threshold)
- {
- float64_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- float64_t *ptrA = pa.ptr();
- float64_t *ptrB = pb.ptr();
- snr = arm_snr_f64(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
-
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,AnyPattern<q63_t> &pa,AnyPattern<q63_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- q63_t *ptrA = pa.ptr();
- q63_t *ptrB = pb.ptr();
- snr = arm_snr_q63(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,q63_t a,q63_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_q63(&a, &b, 1);
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,AnyPattern<q31_t> &pa,AnyPattern<q31_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- q31_t *ptrA = pa.ptr();
- q31_t *ptrB = pb.ptr();
- snr = arm_snr_q31(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,q31_t a,q31_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_q31(&a, &b, 1);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,AnyPattern<q15_t> &pa,AnyPattern<q15_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- q15_t *ptrA = pa.ptr();
- q15_t *ptrB = pb.ptr();
- snr = arm_snr_q15(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,q15_t a,q15_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_q15(&a, &b, 1);
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,AnyPattern<q7_t> &pa,AnyPattern<q7_t> &pb, float32_t threshold)
- {
- float32_t snr;
- ASSERT_NOT_EMPTY(pa);
- ASSERT_NOT_EMPTY(pb);
- if (pa.nbSamples() != pb.nbSamples())
- {
- throw (Error(DIFFERENT_LENGTH_ERROR,nb));
- }
- q7_t *ptrA = pa.ptr();
- q7_t *ptrB = pb.ptr();
- snr = arm_snr_q7(ptrA, ptrB, pa.nbSamples());
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_snr_error(unsigned long nb,q7_t a,q7_t b, float32_t threshold)
- {
- float32_t snr;
- snr = arm_snr_q7(&a, &b, 1);
- //printf("SNR = %f\n",snr);
- if (snr < threshold)
- {
- char details[200];
- sprintf(details,"SNR %g < %g",snr,threshold);
- throw (Error(SNR_ERROR,nb,details));
- }
- }
- void assert_true(unsigned long nb,bool cond)
- {
- if (!cond)
- {
- throw (Error(BOOL_ERROR,nb));
- }
- }
- void assert_false(unsigned long nb,bool cond)
- {
- if (cond)
- {
- throw (Error(BOOL_ERROR,nb));
- }
- }
- }
|