📄 mvector.h
字号:
return MVectorMethods::numNotEqual<TScalar, TIntegral>(*this, test_value); } //--------------------------------------------------------------------------- // // class-specific public methods: // dsp related methods // //-------------------------------------------------------------------------- // dsp methods // boolean limit(TIntegral min_val, TIntegral max_val) { return MVectorMethods::limit<TScalar, TIntegral>(*this, min_val, max_val, *this); } boolean limit(TIntegral min_val, TIntegral max_val, const MVector& vector) { return MVectorMethods::limit<TScalar, TIntegral>(*this, min_val, max_val, vector); } boolean limitMin(TIntegral min_val) { return MVectorMethods::limitMin<TScalar, TIntegral>(*this, min_val, *this); } boolean limitMin(TIntegral min_val, const MVector& vector) { return MVectorMethods:: limitMin<TScalar, TIntegral>(*this, min_val, vector); } boolean limitMax(TIntegral max_val) { return MVectorMethods::limitMax<TScalar, TIntegral>(*this, max_val, *this); } boolean limitMax(TIntegral max_val, const MVector& vector) { return MVectorMethods:: limitMax<TScalar, TIntegral>(*this, max_val, vector); } boolean limitMag(TIntegral cmp_val, TIntegral new_val) { return MVectorMethods::limitMag<TScalar, TIntegral>(*this, cmp_val, new_val, *this); } boolean limitMag(TIntegral cmp_val, TIntegral new_val, const MVector& vector) { return MVectorMethods::limitMag<TScalar, TIntegral>(*this, cmp_val, new_val, vector); } boolean centerClip(TIntegral min_val, TIntegral max_val) { return MVectorMethods::centerClip<TScalar, TIntegral>(*this, min_val, max_val, *this); } boolean centerClip(TIntegral min_val, TIntegral max_val, const MVector& vector) { return MVectorMethods::centerClip<TScalar, TIntegral>(*this, min_val, max_val, vector); } // random number generation methods // boolean rand(Random& generator = Random::GLOBAL_UNIFORM) { return MVectorMethods::rand<TScalar, TIntegral>(*this, generator); } boolean rand(TIntegral min_val, TIntegral max_val, Random& generator = Random::GLOBAL_UNIFORM) { return MVectorMethods::rand<TScalar, TIntegral>(*this, min_val, max_val, generator); } boolean grand(TIntegral mean, TIntegral stdev, Random& generator = Random::GLOBAL_GAUSSIAN) { return MVectorMethods::grand<TScalar, TIntegral>(*this, mean, stdev, generator); } //--------------------------------------------------------------------------- // // class-specific public methods: // position operation and search methods // //-------------------------------------------------------------------------- // position operation methods // boolean move(const MVector& vector, long num_elements, long source_offset, long dest_offset) { return MVectorMethods::move<TScalar, TIntegral>(*this, vector, num_elements, source_offset, dest_offset); } boolean shift(long delta) { return MVectorMethods::shift<TScalar, TIntegral>(*this, delta); } boolean shift(const MVector& vector, long delta) { return MVectorMethods::shift<TScalar, TIntegral>(*this, vector, delta); } boolean concat(const MVector& v2) { return MVectorMethods::concat<TScalar, TIntegral>(*this, v2); } boolean concat(const MVector& v1, const MVector& v2) { return MVectorMethods::concat<TScalar, TIntegral>(*this, v1, v2); } boolean deleteRange(long offset, long num_elements) { return MVectorMethods::deleteRange<TScalar, TIntegral>(*this, *this, offset, num_elements); } boolean deleteRange(const MVector& v1, long offset, long num_elements) { return MVectorMethods::deleteRange<TScalar, TIntegral>(*this, v1, offset, num_elements); } boolean setRange(long offset, long num_elements, TIntegral value) { return MVectorMethods::setRange<TScalar, TIntegral>(*this, offset, num_elements, value); } // search and ordering methods // long first(TIntegral value, long start_pos = Integral::NO_POS) { return MVectorMethods::first<TScalar, TIntegral>(*this, value, start_pos); } long last(TIntegral value, long end_pos = Integral::NO_POS) { return MVectorMethods::last<TScalar, TIntegral>(*this, value, end_pos); } boolean reorder(const MVector<Long, long>& indexes) { return MVectorMethods::reorder<TScalar, TIntegral>(*this, indexes); } boolean reorder(const MVector& arg, const MVector<Long,long>& indexes) { return MVectorMethods::reorder<TScalar, TIntegral>(*this, arg, indexes); } boolean reverse() { return MVectorMethods::reverse<TScalar, TIntegral>(*this); } //--------------------------------------------------------------------------- // // private methods // //---------------------------------------------------------------------------private: // apply methods: // these methods apply the specified function to each element of the vector // boolean apply(const MVector& arg1, TIntegral (TScalar::*method)(TIntegral)); template<class TAScalar, class TAIntegral> boolean apply(const MVector& arg1, const MVector<TAScalar,TAIntegral>& arg2, TIntegral (TScalar::*method) (TIntegral, TIntegral)); boolean apply(const MVector& arg1, TIntegral arg2, TIntegral (TScalar::*method) (TIntegral, TIntegral)); boolean apply(TIntegral arg2, boolean (TScalar::*method) (TIntegral) const) const; // friend classes: // while friend classes and functions are generally discouraged, // they are used in the MVector class to circumvent the // template delayed compilation problem. // friend class MVectorMethods;};// method: apply// // arguments:// const MVector& v: (input) input vector// TIntegral (TScalar::*method_a) (TIntegral,TIntegral): (input) function// pointer// // return: a boolean value indicating status//// this method applies method_a function to every element of v_a//template<class TScalar, class TIntegral>boolean MVector<TScalar, TIntegral>::apply(const MVector& v_a, TIntegral (TScalar::*method_a) (TIntegral arg)) { if (!setLength((long)v_a.length_d, false)) { v_a.debug(L"v_a"); return Error::handle(name(), L"apply", Error::NOMEM, __FILE__, __LINE__); } // compute piecewise // for (long index = (long)length_d - 1; index >= 0; index--) { (v_d[index].*method_a)(v_a.v_d[index]); } // exit gracefully // return true; }// method: apply// // arguments:// const MVector& v1: (input) input vector// const MVector<TAScalar, TAIntegral>& v2: (input) input vector// TIntegral (TScalar::*method_a) (TIntegral,TIntegral): (input) function// pointer//// return: a boolean value indicating status//// this method applies method_a function to every element of v1_a and v2_a//template<class TScalar, class TIntegral>template<class TAScalar, class TAIntegral>boolean MVector<TScalar, TIntegral>::apply(const MVector& v1_a, const MVector<TAScalar, TAIntegral>& v2_a, TIntegral (TScalar::*method_a) (TIntegral,TIntegral)) { // make sure the lengths are equal // long last_index = (long)v1_a.length_d; if (last_index != (long)v2_a.length()) { v1_a.debug(L"v1_a"); v2_a.debug(L"v2_a"); return Error::handle(name(), L"apply", Error::ARG, __FILE__, __LINE__); } // resize // if (!setLength(last_index, false)) { this->debug(L"this"); return Error::handle(name(), L"apply", Error::NOMEM, __FILE__, __LINE__); } // loop through each element // for (long index = 0; index < last_index; index++) { (v_d[index].*method_a)((TIntegral)v1_a.v_d[index], (TIntegral)v2_a(index)); } // exit gracefully // return true;}// method: apply// // arguments:// const MVector& v: (input) input vector// TIntegral val: (input) input parameter// TIntegral (TScalar::*method_a) (TIntegral,TIntegral): (input) function// pointer// // return: a boolean value indicating status//// this method applies method_a function to every element of v with// parameter val//template<class TScalar, class TIntegral>boolean MVector<TScalar, TIntegral>::apply(const MVector& v_a, TIntegral val_a, TIntegral (TScalar::*method_a) (TIntegral,TIntegral)) { // make sure the lengths are equal // long last_index = (long)v_a.length_d; // resize // if (!setLength(last_index, false)) { v_a.debug(L"v_a"); this->debug(L"this"); return Error::handle(name(), L"apply", Error::NOMEM, __FILE__, __LINE__); } // loop through each element // for (long index = 0; index < last_index; index++) { (v_d[index].*method_a)((TIntegral)v_a.v_d[index], val_a); } // exit gracefully // return true;}// method: apply// // arguments:// TIntegral val: (input) input parameter// TIntegral (TScalar::*method_a) (TIntegral,TIntegral): (input) function// pointer// // return: a boolean value indicating status//// this method applies method_a function to every element of the current vector//template<class TScalar, class TIntegral>boolean MVector<TScalar, TIntegral>::apply(TIntegral val_a, boolean (TScalar::*method_a) (TIntegral) const) const { // make sure the lengths are equal // long last_index = (long)length_d; // loop through each element // for (long index = 0; index < last_index; index++) { if (!(v_d[index].*method_a)(val_a)) { return false; } } // exit gracefully // return true;}// method: assign//// arguments:// const MVector<TAScalar, TAIntegral>& vector: (input) operand//// return: a boolean value indicating status//// this method copies the input vector to the current vector// template<class TScalar, class TIntegral>template<class TAScalar, class TAIntegral>boolean MVector<TScalar, TIntegral>::assign(const MVector<TAScalar, TAIntegral>& vector_a) { // resize // if (!setLength(vector_a.length(), false)) { this->debug(L"this"); vector_a.debug(L"vector_a"); return Error::handle(name(), L"assign", Error::NOMEM, __FILE__, __LINE__); } if (!setCapacity(vector_a.getCapacity(), false)) { this->debug(L"this"); vector_a.debug(L"vector_a"); return Error::handle(name(), L"assign", Error::NOMEM, __FILE__, __LINE__); } // copy the data // long last_index = (long)length_d; for (long index = 0; index < last_index; index++) { v_d[index] = (TIntegral)vector_a(index); } // exit gracefully // return true;}// method: assign//// arguments:// MVector<TScalar, TIntegral>& this: (output) class operand// long length: (input) length// const TAIntegral* v: (input) Vector data//// return: a boolean value indicating status//// this method creates a vector from a TAIntegral* array//template<class TScalar, class TIntegral, class TAIntegral>boolean MVectorMethods::assign(MVector<TScalar, TIntegral>& this_a, long length_a, const TAIntegral* v_a) { // check argument // if (length_a <= 0) { this_a.debug(L"this_a"); return Error::handle(name(), L"assign", Error::ARG, __FILE__, __LINE__); } // resize // if (!this_a.setLength(length_a, false)) { this_a.debug(L"this_a"); return Error::handle(name(), L"assign", Error::NOMEM, __FILE__, __LINE__); } // copy the data // TAIntegral* ptr_cdata = (TAIntegral*)v_a; for (long index = 0; index < length_a; index++) { this_a.v_d[index] = (TIntegral)(*ptr_cdata++); } // exit gracefully // return true;}//-----------------------------------------------------------------------------//// template specializations: the remainder of this file contains template// specializations for all functions that require a specific implementation// for each data type.////-----------------------------------------------------------------------------// template specialization for Byte//template<> booleanMVector<Byte, byte>::abs() { return false ;}template<> booleanMVector<Byte, byte>::abs(const MVector<Byte, byte>& v1) { return false ;}template<> booleanMVector<Byte, byte>::neg() { return false;}template<> booleanMVector<Byte, byte>::neg(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::round() { return false;}template<> booleanMVector<Byte, byte>::round(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::ceil() { return false;}template<> booleanMVector<Byte, byte>::ceil(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::floor() { return false;}template<> booleanMVector<Byte, byte>::floor(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::rfloor() { return false;}template<> booleanMVector<Byte, byte>::rfloor(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::rceil() { return false;}template<> booleanMVector<Byte, byte>::rceil(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::sign() { return false;}template<> booleanMVector<Byte, byte>::sign(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::sin() { return false;}template<> booleanMVector<Byte, byte>::sin(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::cos() { return false;}template<> booleanMVector<Byte, byte>::cos(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::tan() { return false;}template<> booleanMVector<Byte, byte>::tan(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::sinh() { return false;}template<> booleanMVector<Byte, byte>::sinh(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::cosh() { return false;}template<> booleanMVector<Byte, byte>::cosh(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::tanh() { return false;}template<> booleanMVector<Byte, byte>::tanh(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::asin() { return false;}template<> booleanMVector<Byte, byte>::asin(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::asinh() { return false;}template<> booleanMVector<Byte, byte>::asinh(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::acos() { return false;}template<> booleanMVector<Byte, byte>::acos(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::acosh() { return false;}template<> booleanMVector<Byte, byte>::acosh(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::atan() { return false;}template<> booleanMVector<Byte, byte>::atan(const MVector<Byte, byte>& v1) { return false;}template<> booleanMVector<Byte, byte>::atanh() { return false;}template<> booleanMVector<Byte, byte>::atanh(const MVector<Byte, byte>& v1) { return false;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -