#ifndef cwVectOps_h #define cwVectOps_h namespace cw { namespace vop { //================================================================================================================== // Input / Output // template< typename T0 > void print( const T0* v0, unsigned n, const char* fmt, const char* label=nullptr ) { if( label != nullptr ) printf("%s : ",label); for(unsigned i=0; i void copy( T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i void fill( T0* v, unsigned n, const T1& value=0 ) { for(unsigned i=0; i void zero( T* v, unsigned n ) { fill(v,n,0); } //================================================================================================================== // Compare // template< typename T0, typename T1 > bool is_equal( const T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i unsigned arg_max( const T* v, unsigned n ) { if( n == 0 ) return kInvalidIdx; unsigned mi = 0; for(unsigned i=1; i v[mi]) mi = i; return mi; } template< typename T > unsigned arg_min( const T* v, unsigned n ) { if( n == 0 ) return kInvalidIdx; unsigned mi = 0; for(unsigned i=1; i const T max( const T* v, unsigned n ) { unsigned mi; if((mi = arg_max(v,n)) == kInvalidIdx ) return std::numeric_limits::max(); return v[mi]; } template< typename T > const T min( const T* v, unsigned n ) { unsigned mi; if((mi = arg_min(v,n)) == kInvalidIdx ) return std::numeric_limits::max(); return v[mi]; } template< typename T0, typename T1 > T0 mac( const T0* v0, const T1* v1, unsigned n ) { T0 acc = 0; for(unsigned i=0; i void mul( T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i void mul( T0* y0, const T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i void mul( T0* v0, const T1& scalar, unsigned n ) { for(unsigned i=0; i void mul( T0* y0, const T0* v0, const T1& scalar, unsigned n ) { for(unsigned i=0; i void add( T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i void add( T0* y0, const T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i void add( T0* v0, const T1& scalar, unsigned n ) { for(unsigned i=0; i void add( T0* y0, const T0* v0, const T1& scalar, unsigned n ) { for(unsigned i=0; i void div( T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i void div( T0* y0, const T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i void div( T0* v0, const T1& scalar, unsigned n ) { for(unsigned i=0; i void div( T0* y0, const T0* v0, const T1& scalar, unsigned n ) { for(unsigned i=0; i void sub( T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i void sub( T0* y0, const T0* v0, const T1* v1, unsigned n ) { for(unsigned i=0; i void sub( T0* v0, const T1& scalar, unsigned n ) { for(unsigned i=0; i void sub( T0* y0, const T0* v0, const T1& scalar, unsigned n ) { for(unsigned i=0; i void seq( T* y, unsigned n, const T& beg, const T& cnt, const T& step=1 ) { if( cnt < n ) n = cnt; T v = beg; for(unsigned i=0; i T* linspace( T* y, unsigned yN, T base, T limit ) { unsigned i = 0; for(; i T seq( T* dbp, unsigned dn, const T& beg, const T& incr ) { const T* dep = dbp + dn; unsigned i = 0; for(; dbp T cumsum( const T* v, unsigned n ) { T y = 0; for(unsigned i=0; i T cumprod( const T* v, unsigned n ) { T y = 1; for(unsigned i=0; i unsigned phasor( T* y, unsigned n, T srate, T hz, unsigned init_idx=0 ) { for(unsigned i=init_idx; i unsigned sine( T* y, unsigned n, T srate, T hz, unsigned init_idx=0 ) { init_idx = phasor(y,n,srate,hz,init_idx); for(unsigned i=0; i