// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2008-2009 Gael Guennebaud <gael.guennebaud@inria.fr> // Copyright (C) 2006-2008 Benoit Jacob <jacob.benoit.1@gmail.com> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
// The following implement bitwise operations on floating point types template<typename T,typename Bits,typename Func>
T apply_bit_op(Bits a, Bits b, Func f) {
Array<unsignedchar,sizeof(T),1> data;
T res; for(Index i = 0; i < data.size(); ++i)
data[i] = f(a[i], b[i]); // Note: The reinterpret_cast works around GCC's class-memaccess warnings:
std::memcpy(reinterpret_cast<unsignedchar*>(&res), data.data(), sizeof(T)); return res;
}
#define EIGEN_TEST_MAKE_BITWISE2(OP,FUNC,T) \ template<> T EIGEN_CAT(p,OP)(const T& a,const T& b) { \ return apply_bit_op<T>(bits(a),bits(b),FUNC); \
}
EIGEN_TEST_MAKE_BITWISE(xor,std::bit_xor<unsignedchar>())
EIGEN_TEST_MAKE_BITWISE(and,std::bit_and<unsignedchar>())
EIGEN_TEST_MAKE_BITWISE(or, std::bit_or<unsignedchar>()) struct bit_andnot{ template<typename T> T operator()(T a, T b) const { return a & (~b); }
};
EIGEN_TEST_MAKE_BITWISE(andnot, bit_andnot()) template<typename T> bool biteq(T a, T b) { return (bits(a) == bits(b)).all();
}
}
namespace test {
// NOTE: we disable inlining for this function to workaround a GCC issue when using -O3 and the i387 FPU. template<typename Scalar> EIGEN_DONT_INLINE bool isApproxAbs(const Scalar& a, const Scalar& b, consttypename NumTraits<Scalar>::Real& refvalue)
{ return internal::isMuchSmallerThan(a-b, refvalue);
}
// Checks component-wise for input of size N. All of data1, data2, and ref // should have size at least ceil(N/PacketSize)*PacketSize to avoid memory // access errors. #define CHECK_CWISE1_N(REFOP, POP, N) { \ for (int i=0; i<N; ++i) \
ref[i] = REFOP(data1[i]); \ for (int j=0; j<N; j+=PacketSize) \
internal::pstore(data2 + j, POP(internal::pload<Packet>(data1 + j))); \
VERIFY(test::areApprox(ref, data2, N) && #POP); \
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.