//| Copyright: (C) 2009-2020 Kevin Larke //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file. #include "cmPrefix.h" #include "cmGlobal.h" #include "cmFloatTypes.h" #include "cmComplexTypes.h" #include "cmRpt.h" #include "cmErr.h" #include "cmCtx.h" #include "cmMem.h" #include "cmMallocDebug.h" #include "cmLinkedHeap.h" #include "cmSymTbl.h" #include "cmMath.h" #ifdef OS_LINUX #include #endif #include "cmAudioFile.h" #include "cmFileSys.h" #include "cmProcObj.h" #include "cmProcTemplate.h" #include "cmProc.h" #include "cmVectOps.h" #define cmVectOpsTemplateCode_h #define cmVectOpsRICode_h #include "cmVectOpsTemplateMain.h" unsigned _cmVOU_Abs( unsigned x ) { return x; } void cmVOU_VPrint( cmRpt_t* rpt, const char* fmt, ... ) { va_list vl; va_start(vl,fmt); if( rpt == NULL ) vprintf(fmt,vl); else cmRptVPrintf(rpt,fmt,vl); va_end(vl); } void cmVOI_Print( cmRpt_t* rpt, unsigned rn, unsigned cn, const int* sbp ) { unsigned fieldWidth = cmDefaultFieldWidth; if( fieldWidth < 0 ) fieldWidth = 10; unsigned ri,ci; for(ri=0; ri 0 ) cmVOU_VPrint(rpt,"\n"); } } void cmVOU_Print( cmRpt_t* rpt, unsigned rn, unsigned cn, const unsigned* sbp ) { unsigned fieldWidth = cmDefaultFieldWidth; if( fieldWidth < 0 ) fieldWidth = 10; unsigned ri,ci; for(ri=0; ri 0 ) cmVOU_VPrint(rpt,"\n"); } } void cmVOI_PrintL( const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const int* sp ) { cmVOU_VPrint(rpt,"%s ",label); return cmVOI_Print(rpt,rn,cn,sp); } void cmVOU_PrintL( const char* label, cmRpt_t* rpt, unsigned rn, unsigned cn, const unsigned* sp ) { cmVOU_VPrint(rpt,"%s ",label); return cmVOU_Print(rpt,rn,cn,sp); } unsigned* cmVOU_Mod( unsigned* dbp, unsigned dn, unsigned modVal ) { const unsigned* dep = dbp + dn; unsigned* dp = dbp; while( dbp < dep ) *dbp++ %= modVal; return dp; } unsigned* cmVOU_Hist( unsigned* hbp, unsigned hn, const unsigned* sbp, unsigned sn ) { const unsigned* sep = sbp + sn; unsigned* rp = hbp; memset(hbp,0,hn * sizeof(*hbp)); while( sbp < sep ) { assert( *sbp < hn ); ++hbp[ *sbp++ ]; } return rp; } unsigned* cmVOU_Random( unsigned* vbp, unsigned vn, unsigned maxValue ) { unsigned* rp = vbp; const unsigned* vep = vbp + vn; while( vbp < vep ) *vbp++ = rand() % (maxValue+1); return rp; } unsigned* cmVOU_UniqueRandom( unsigned* dV, unsigned dN, unsigned maxValue ) { assert( dN < maxValue ); if( dN == 0 ) return dV; // if maxValue is less than twice dN then use cmVOU_RandomSeq() to // generate the random numbers. This is intended to avoid a situation // where the attempt to generate a unique random number is confined // to an decreasing range of possible target values - as would occur // if dN==maxValue. if( maxValue / dN <= 2 ) { unsigned* v = cmMemAllocZ( unsigned, maxValue+1 ); cmVOU_RandomSeq(v,maxValue+1); cmVOU_Copy(dV,dN,v); cmMemPtrFree(&v); } unsigned* tV = cmMemAllocZ( unsigned, dN ); unsigned i = 0; unsigned j = 0; unsigned n = dN; while(n) { // generate a set of random integers cmVOU_Random(tV,n,maxValue); // store each unique random int for(j=0; j