/** * @file * @author Navneet Dalal * @brief Defines some useful utilities for TinyVector and TinyMatrix. * * @warning Some functions may not be defined using blitz Expression Templates * and Meta Programming techniques. */ #ifndef _BLITZ_TVMUTILS_H__ #define _BLITZ_TVMUTILS_H__ #include #include #include BZ_NAMESPACE(blitz) //{{{ isInRange functions template inline bool isInRange( const TinyVector& p, const TinyVector& cMin, const TinyVector& cMax) { for (int i= 0; i< Rank; ++i) if (p[i] < cMin[i] || p[i] > cMax[i]) return false; return true; } #define TMP_ISINRANGE(TYPE) \ inline bool isInRange(const TYPE p, const TYPE cMin, const TYPE cMax){ \ if (p < cMin || p > cMax) \ return false; \ return true; \ } TMP_ISINRANGE(double) TMP_ISINRANGE(long double) TMP_ISINRANGE(float) TMP_ISINRANGE(int) TMP_ISINRANGE(unsigned int) TMP_ISINRANGE(short) TMP_ISINRANGE(unsigned short) TMP_ISINRANGE(long) TMP_ISINRANGE(unsigned long) TMP_ISINRANGE(char) TMP_ISINRANGE(unsigned char) #undef TMP_ISINRANGE //}}} // {{{ isEqual functions /** * @defgroup isEqual_Functions Overloaded isEqual functions * @brief Defines isEqual function for int, double and TinyVector. * * isEqual compares element by element and returns true only if all elements are equal. * */ // @{ #define TMP_ISEQUAL(TYPE) \ inline bool isEqual(const TYPE a, const TYPE b) { \ return a == b; \ } TMP_ISEQUAL(double) TMP_ISEQUAL(long double) TMP_ISEQUAL(float) TMP_ISEQUAL(int) TMP_ISEQUAL(unsigned int) TMP_ISEQUAL(short) TMP_ISEQUAL(unsigned short) TMP_ISEQUAL(long) TMP_ISEQUAL(unsigned long) TMP_ISEQUAL(char) TMP_ISEQUAL(unsigned char) #undef TMP_ISEQUAL template inline bool isEqual(const TinyVector&a, const TinyVector&b) { for (int i= 0; i inline bool isNotEqual(const TinyVector&a, const TinyVector&b) { for (int i= 0; i b; \ } TMP_ISGREATER(double) TMP_ISGREATER(long double) TMP_ISGREATER(float) TMP_ISGREATER(int) TMP_ISGREATER(unsigned int) TMP_ISGREATER(short) TMP_ISGREATER(unsigned short) TMP_ISGREATER(long) TMP_ISGREATER(unsigned long) TMP_ISGREATER(char) TMP_ISGREATER(unsigned char) #undef TMP_ISGREATER template inline bool isGreater(const TinyVector&a, const TinyVector&b) { for (int i= 0; i= b; \ } TMP_ISGREATEREQUAL(double) TMP_ISGREATEREQUAL(long double) TMP_ISGREATEREQUAL(float) TMP_ISGREATEREQUAL(int) TMP_ISGREATEREQUAL(unsigned int) TMP_ISGREATEREQUAL(short) TMP_ISGREATEREQUAL(unsigned short) TMP_ISGREATEREQUAL(long) TMP_ISGREATEREQUAL(unsigned long) TMP_ISGREATEREQUAL(char) TMP_ISGREATEREQUAL(unsigned char) #undef TMP_ISGREATEREQUAL template inline bool isGreaterEqual(const TinyVector&a, const TinyVector&b) { for (int i= 0; i inline bool isLess(const TinyVector&a, const TinyVector&b) { for (int i= 0; i= b[i]) return false; return true; } BZ_DECLARE_FUNCTION2_RET(isLess,bool) // @} // }}} // {{{ isLessEqual functions /** * @defgroup isLessEqual Overloaded isLessEqual functions * @brief Defines isLessEqual function for int, double and TinyVector. * * isLessEqual compares element by element and returns true only if all elements * of a are GreaterEqual than b. * */ // @{ #define TMP_ISLESSEQUAL(TYPE) \ inline bool isLessEqual(const TYPE a, const TYPE b) { \ return a <= b; \ } TMP_ISLESSEQUAL(double) TMP_ISLESSEQUAL(long double) TMP_ISLESSEQUAL(float) TMP_ISLESSEQUAL(int) TMP_ISLESSEQUAL(unsigned int) TMP_ISLESSEQUAL(short) TMP_ISLESSEQUAL(unsigned short) TMP_ISLESSEQUAL(long) TMP_ISLESSEQUAL(unsigned long) TMP_ISLESSEQUAL(char) TMP_ISLESSEQUAL(unsigned char) #undef TMP_ISLESSEQUAL template inline bool isLessEqual(const TinyVector&a, const TinyVector&b) { for (int i= 0; i b[i]) return false; return true; } BZ_DECLARE_FUNCTION2_RET(isLessEqual,bool) // @} // }}} // {{{ isZero functions /** * @defgroup isZero_Functions Overloaded isZero functions * @brief Defines isZero function for int, double and TinyVector. * * isZero compares element by element and returns true only if all elements are zero. * */ // @{ #define TMP_ISZERO(TYPE) \ inline bool isZero(const TYPE a) { \ return a == 0; \ } TMP_ISZERO(double) TMP_ISZERO(long double) TMP_ISZERO(float) TMP_ISZERO(int) TMP_ISZERO(unsigned int) TMP_ISZERO(short) TMP_ISZERO(unsigned short) TMP_ISZERO(long) TMP_ISZERO(unsigned long) TMP_ISZERO(char) TMP_ISZERO(unsigned char) #undef TMP_ISZERO template inline bool isZero(const TinyVector&a) { for (int i=0; i // inline T product(const TinyVector&a) { // T value=1; // for (int i= 0; i