mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-29 23:34:12 +08:00
Merged eigen/eigen into default
This commit is contained in:
commit
7e4a6754b2
@ -53,7 +53,7 @@ cholmod_sparse viewAsCholmod(SparseMatrix<_Scalar,_Options,_StorageIndex>& mat)
|
|||||||
{
|
{
|
||||||
cholmod_sparse res;
|
cholmod_sparse res;
|
||||||
res.nzmax = mat.nonZeros();
|
res.nzmax = mat.nonZeros();
|
||||||
res.nrow = mat.rows();;
|
res.nrow = mat.rows();
|
||||||
res.ncol = mat.cols();
|
res.ncol = mat.cols();
|
||||||
res.p = mat.outerIndexPtr();
|
res.p = mat.outerIndexPtr();
|
||||||
res.i = mat.innerIndexPtr();
|
res.i = mat.innerIndexPtr();
|
||||||
|
@ -355,30 +355,27 @@ pexp<Packet4d>(const Packet4d& _x) {
|
|||||||
// Functions for sqrt.
|
// Functions for sqrt.
|
||||||
// The EIGEN_FAST_MATH version uses the _mm_rsqrt_ps approximation and one step
|
// The EIGEN_FAST_MATH version uses the _mm_rsqrt_ps approximation and one step
|
||||||
// of Newton's method, at a cost of 1-2 bits of precision as opposed to the
|
// of Newton's method, at a cost of 1-2 bits of precision as opposed to the
|
||||||
// exact solution. The main advantage of this approach is not just speed, but
|
// exact solution. It does not handle +inf, or denormalized numbers correctly.
|
||||||
// also the fact that it can be inlined and pipelined with other computations,
|
// The main advantage of this approach is not just speed, but also the fact that
|
||||||
// further reducing its effective latency.
|
// it can be inlined and pipelined with other computations, further reducing its
|
||||||
|
// effective latency. This is similar to Quake3's fast inverse square root.
|
||||||
|
// For detail see here: http://www.beyond3d.com/content/articles/8/
|
||||||
#if EIGEN_FAST_MATH
|
#if EIGEN_FAST_MATH
|
||||||
template <>
|
template <>
|
||||||
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f
|
EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED Packet8f
|
||||||
psqrt<Packet8f>(const Packet8f& _x) {
|
psqrt<Packet8f>(const Packet8f& _x) {
|
||||||
_EIGEN_DECLARE_CONST_Packet8f(one_point_five, 1.5f);
|
Packet8f half = pmul(_x, pset1<Packet8f>(.5f));
|
||||||
_EIGEN_DECLARE_CONST_Packet8f(minus_half, -0.5f);
|
Packet8f denormal_mask = _mm256_and_ps(
|
||||||
_EIGEN_DECLARE_CONST_Packet8f_FROM_INT(flt_min, 0x00800000);
|
_mm256_cmp_ps(_x, pset1<Packet8f>((std::numeric_limits<float>::min)()),
|
||||||
|
_CMP_LT_OQ),
|
||||||
Packet8f neg_half = pmul(_x, p8f_minus_half);
|
_mm256_cmp_ps(_x, _mm256_setzero_ps(), _CMP_GE_OQ));
|
||||||
|
|
||||||
// select only the inverse sqrt of positive normal inputs (denormals are
|
|
||||||
// flushed to zero and cause infs as well).
|
|
||||||
Packet8f non_zero_mask = _mm256_cmp_ps(_x, p8f_flt_min, _CMP_GE_OQ);
|
|
||||||
Packet8f x = _mm256_and_ps(non_zero_mask, _mm256_rsqrt_ps(_x));
|
|
||||||
|
|
||||||
|
// Compute approximate reciprocal sqrt.
|
||||||
|
Packet8f x = _mm256_rsqrt_ps(_x);
|
||||||
// Do a single step of Newton's iteration.
|
// Do a single step of Newton's iteration.
|
||||||
x = pmul(x, pmadd(neg_half, pmul(x, x), p8f_one_point_five));
|
x = pmul(x, psub(pset1<Packet8f>(1.5f), pmul(half, pmul(x,x))));
|
||||||
|
// Flush results for denormals to zero.
|
||||||
// Multiply the original _x by it's reciprocal square root to extract the
|
return _mm256_andnot_ps(denormal_mask, pmul(_x,x));
|
||||||
// square root.
|
|
||||||
return pmul(_x, x);
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
|
template <> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
|
||||||
|
@ -16,8 +16,14 @@ namespace Eigen {
|
|||||||
namespace internal {
|
namespace internal {
|
||||||
|
|
||||||
inline uint32x4_t p4ui_CONJ_XOR() {
|
inline uint32x4_t p4ui_CONJ_XOR() {
|
||||||
|
// See bug 1325, clang fails to call vld1q_u64.
|
||||||
|
#if EIGEN_COMP_CLANG
|
||||||
|
uint32x4_t ret = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 };
|
||||||
|
return ret;
|
||||||
|
#else
|
||||||
static const uint32_t conj_XOR_DATA[] = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 };
|
static const uint32_t conj_XOR_DATA[] = { 0x00000000, 0x80000000, 0x00000000, 0x80000000 };
|
||||||
return vld1q_u32( conj_XOR_DATA );
|
return vld1q_u32( conj_XOR_DATA );
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32x2_t p2ui_CONJ_XOR() {
|
inline uint32x2_t p2ui_CONJ_XOR() {
|
||||||
@ -282,8 +288,13 @@ ptranspose(PacketBlock<Packet2cf,2>& kernel) {
|
|||||||
//---------- double ----------
|
//---------- double ----------
|
||||||
#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
|
#if EIGEN_ARCH_ARM64 && !EIGEN_APPLE_DOUBLE_NEON_BUG
|
||||||
|
|
||||||
|
// See bug 1325, clang fails to call vld1q_u64.
|
||||||
|
#if EIGEN_COMP_CLANG
|
||||||
|
static uint64x2_t p2ul_CONJ_XOR = {0x0, 0x8000000000000000};
|
||||||
|
#else
|
||||||
const uint64_t p2ul_conj_XOR_DATA[] = { 0x0, 0x8000000000000000 };
|
const uint64_t p2ul_conj_XOR_DATA[] = { 0x0, 0x8000000000000000 };
|
||||||
static uint64x2_t p2ul_CONJ_XOR = vld1q_u64( p2ul_conj_XOR_DATA );
|
static uint64x2_t p2ul_CONJ_XOR = vld1q_u64( p2ul_conj_XOR_DATA );
|
||||||
|
#endif
|
||||||
|
|
||||||
struct Packet1cd
|
struct Packet1cd
|
||||||
{
|
{
|
||||||
|
@ -444,20 +444,28 @@ Packet4f pcos<Packet4f>(const Packet4f& _x)
|
|||||||
|
|
||||||
#if EIGEN_FAST_MATH
|
#if EIGEN_FAST_MATH
|
||||||
|
|
||||||
// This is based on Quake3's fast inverse square root.
|
// Functions for sqrt.
|
||||||
|
// The EIGEN_FAST_MATH version uses the _mm_rsqrt_ps approximation and one step
|
||||||
|
// of Newton's method, at a cost of 1-2 bits of precision as opposed to the
|
||||||
|
// exact solution. It does not handle +inf, or denormalized numbers correctly.
|
||||||
|
// The main advantage of this approach is not just speed, but also the fact that
|
||||||
|
// it can be inlined and pipelined with other computations, further reducing its
|
||||||
|
// effective latency. This is similar to Quake3's fast inverse square root.
|
||||||
// For detail see here: http://www.beyond3d.com/content/articles/8/
|
// For detail see here: http://www.beyond3d.com/content/articles/8/
|
||||||
// It lacks 1 (or 2 bits in some rare cases) of precision, and does not handle negative, +inf, or denormalized numbers correctly.
|
|
||||||
template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
|
template<> EIGEN_DEFINE_FUNCTION_ALLOWING_MULTIPLE_DEFINITIONS EIGEN_UNUSED
|
||||||
Packet4f psqrt<Packet4f>(const Packet4f& _x)
|
Packet4f psqrt<Packet4f>(const Packet4f& _x)
|
||||||
{
|
{
|
||||||
Packet4f half = pmul(_x, pset1<Packet4f>(.5f));
|
Packet4f half = pmul(_x, pset1<Packet4f>(.5f));
|
||||||
|
Packet4f denormal_mask = _mm_and_ps(
|
||||||
|
_mm_cmpge_ps(_x, _mm_setzero_ps()),
|
||||||
|
_mm_cmplt_ps(_x, pset1<Packet4f>((std::numeric_limits<float>::min)())));
|
||||||
|
|
||||||
/* select only the inverse sqrt of non-zero inputs */
|
// Compute approximate reciprocal sqrt.
|
||||||
Packet4f non_zero_mask = _mm_cmpge_ps(_x, pset1<Packet4f>((std::numeric_limits<float>::min)()));
|
Packet4f x = _mm_rsqrt_ps(_x);
|
||||||
Packet4f x = _mm_and_ps(non_zero_mask, _mm_rsqrt_ps(_x));
|
// Do a single step of Newton's iteration.
|
||||||
|
|
||||||
x = pmul(x, psub(pset1<Packet4f>(1.5f), pmul(half, pmul(x,x))));
|
x = pmul(x, psub(pset1<Packet4f>(1.5f), pmul(half, pmul(x,x))));
|
||||||
return pmul(_x,x);
|
// Flush results for denormals to zero.
|
||||||
|
return _mm_andnot_ps(denormal_mask, pmul(_x,x));
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -392,8 +392,8 @@
|
|||||||
// Does the compiler support variadic templates?
|
// Does the compiler support variadic templates?
|
||||||
#ifndef EIGEN_HAS_VARIADIC_TEMPLATES
|
#ifndef EIGEN_HAS_VARIADIC_TEMPLATES
|
||||||
#if EIGEN_MAX_CPP_VER>=11 && (__cplusplus > 199711L || EIGEN_COMP_MSVC >= 1900) \
|
#if EIGEN_MAX_CPP_VER>=11 && (__cplusplus > 199711L || EIGEN_COMP_MSVC >= 1900) \
|
||||||
&& ( !defined(__NVCC__) || !EIGEN_ARCH_ARM_OR_ARM64 )
|
&& ( !defined(__NVCC__) || !EIGEN_ARCH_ARM_OR_ARM64 || (defined __CUDACC_VER__ && __CUDACC_VER__ >= 80000) )
|
||||||
// ^^ Disable the use of variadic templates when compiling with nvcc on ARM devices:
|
// ^^ Disable the use of variadic templates when compiling with versions of nvcc older than 8.0 on ARM devices:
|
||||||
// this prevents nvcc from crashing when compiling Eigen on Tegra X1
|
// this prevents nvcc from crashing when compiling Eigen on Tegra X1
|
||||||
#define EIGEN_HAS_VARIADIC_TEMPLATES 1
|
#define EIGEN_HAS_VARIADIC_TEMPLATES 1
|
||||||
#else
|
#else
|
||||||
|
12
Eigen/src/Geometry/Scaling.h
Normal file → Executable file
12
Eigen/src/Geometry/Scaling.h
Normal file → Executable file
@ -118,28 +118,28 @@ operator*(const MatrixBase<Derived>& matrix, const UniformScaling<Scalar>& s)
|
|||||||
{ return matrix.derived() * s.factor(); }
|
{ return matrix.derived() * s.factor(); }
|
||||||
|
|
||||||
/** Constructs a uniform scaling from scale factor \a s */
|
/** Constructs a uniform scaling from scale factor \a s */
|
||||||
static inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); }
|
inline UniformScaling<float> Scaling(float s) { return UniformScaling<float>(s); }
|
||||||
/** Constructs a uniform scaling from scale factor \a s */
|
/** Constructs a uniform scaling from scale factor \a s */
|
||||||
static inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); }
|
inline UniformScaling<double> Scaling(double s) { return UniformScaling<double>(s); }
|
||||||
/** Constructs a uniform scaling from scale factor \a s */
|
/** Constructs a uniform scaling from scale factor \a s */
|
||||||
template<typename RealScalar>
|
template<typename RealScalar>
|
||||||
static inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s)
|
inline UniformScaling<std::complex<RealScalar> > Scaling(const std::complex<RealScalar>& s)
|
||||||
{ return UniformScaling<std::complex<RealScalar> >(s); }
|
{ return UniformScaling<std::complex<RealScalar> >(s); }
|
||||||
|
|
||||||
/** Constructs a 2D axis aligned scaling */
|
/** Constructs a 2D axis aligned scaling */
|
||||||
template<typename Scalar>
|
template<typename Scalar>
|
||||||
static inline DiagonalMatrix<Scalar,2> Scaling(const Scalar& sx, const Scalar& sy)
|
inline DiagonalMatrix<Scalar,2> Scaling(const Scalar& sx, const Scalar& sy)
|
||||||
{ return DiagonalMatrix<Scalar,2>(sx, sy); }
|
{ return DiagonalMatrix<Scalar,2>(sx, sy); }
|
||||||
/** Constructs a 3D axis aligned scaling */
|
/** Constructs a 3D axis aligned scaling */
|
||||||
template<typename Scalar>
|
template<typename Scalar>
|
||||||
static inline DiagonalMatrix<Scalar,3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
|
inline DiagonalMatrix<Scalar,3> Scaling(const Scalar& sx, const Scalar& sy, const Scalar& sz)
|
||||||
{ return DiagonalMatrix<Scalar,3>(sx, sy, sz); }
|
{ return DiagonalMatrix<Scalar,3>(sx, sy, sz); }
|
||||||
|
|
||||||
/** Constructs an axis aligned scaling expression from vector expression \a coeffs
|
/** Constructs an axis aligned scaling expression from vector expression \a coeffs
|
||||||
* This is an alias for coeffs.asDiagonal()
|
* This is an alias for coeffs.asDiagonal()
|
||||||
*/
|
*/
|
||||||
template<typename Derived>
|
template<typename Derived>
|
||||||
static inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs)
|
inline const DiagonalWrapper<const Derived> Scaling(const MatrixBase<Derived>& coeffs)
|
||||||
{ return coeffs.asDiagonal(); }
|
{ return coeffs.asDiagonal(); }
|
||||||
|
|
||||||
/** \deprecated */
|
/** \deprecated */
|
||||||
|
@ -119,9 +119,9 @@ class SPQR : public SparseSolverBase<SPQR<_MatrixType> >
|
|||||||
max2Norm = RealScalar(1);
|
max2Norm = RealScalar(1);
|
||||||
pivotThreshold = 20 * (mat.rows() + mat.cols()) * max2Norm * NumTraits<RealScalar>::epsilon();
|
pivotThreshold = 20 * (mat.rows() + mat.cols()) * max2Norm * NumTraits<RealScalar>::epsilon();
|
||||||
}
|
}
|
||||||
|
|
||||||
cholmod_sparse A;
|
cholmod_sparse A;
|
||||||
A = viewAsCholmod(mat);
|
A = viewAsCholmod(mat);
|
||||||
|
m_rows = matrix.rows();
|
||||||
Index col = matrix.cols();
|
Index col = matrix.cols();
|
||||||
m_rank = SuiteSparseQR<Scalar>(m_ordering, pivotThreshold, col, &A,
|
m_rank = SuiteSparseQR<Scalar>(m_ordering, pivotThreshold, col, &A,
|
||||||
&m_cR, &m_E, &m_H, &m_HPinv, &m_HTau, &m_cc);
|
&m_cR, &m_E, &m_H, &m_HPinv, &m_HTau, &m_cc);
|
||||||
@ -139,7 +139,7 @@ class SPQR : public SparseSolverBase<SPQR<_MatrixType> >
|
|||||||
/**
|
/**
|
||||||
* Get the number of rows of the input matrix and the Q matrix
|
* Get the number of rows of the input matrix and the Q matrix
|
||||||
*/
|
*/
|
||||||
inline Index rows() const {return m_cR->nrow; }
|
inline Index rows() const {return m_rows; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the number of columns of the input matrix.
|
* Get the number of columns of the input matrix.
|
||||||
@ -245,6 +245,7 @@ class SPQR : public SparseSolverBase<SPQR<_MatrixType> >
|
|||||||
mutable Index m_rank; // The rank of the matrix
|
mutable Index m_rank; // The rank of the matrix
|
||||||
mutable cholmod_common m_cc; // Workspace and parameters
|
mutable cholmod_common m_cc; // Workspace and parameters
|
||||||
bool m_useDefaultThreshold; // Use default threshold
|
bool m_useDefaultThreshold; // Use default threshold
|
||||||
|
Index m_rows;
|
||||||
template<typename ,typename > friend struct SPQR_QProduct;
|
template<typename ,typename > friend struct SPQR_QProduct;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
0
test/geo_transformations.cpp
Normal file → Executable file
0
test/geo_transformations.cpp
Normal file → Executable file
@ -440,12 +440,9 @@ template<typename Scalar> void packetmath_real()
|
|||||||
data1[0] = Scalar(-1.0f);
|
data1[0] = Scalar(-1.0f);
|
||||||
h.store(data2, internal::plog(h.load(data1)));
|
h.store(data2, internal::plog(h.load(data1)));
|
||||||
VERIFY((numext::isnan)(data2[0]));
|
VERIFY((numext::isnan)(data2[0]));
|
||||||
#if !EIGEN_FAST_MATH
|
|
||||||
h.store(data2, internal::psqrt(h.load(data1)));
|
h.store(data2, internal::psqrt(h.load(data1)));
|
||||||
VERIFY((numext::isnan)(data2[0]));
|
VERIFY((numext::isnan)(data2[0]));
|
||||||
VERIFY((numext::isnan)(data2[1]));
|
VERIFY((numext::isnan)(data2[1]));
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ int generate_sparse_rectangular_problem(MatrixType& A, DenseMat& dA, int maxRows
|
|||||||
int cols = internal::random<int>(1,rows);
|
int cols = internal::random<int>(1,rows);
|
||||||
double density = (std::max)(8./(rows*cols), 0.01);
|
double density = (std::max)(8./(rows*cols), 0.01);
|
||||||
|
|
||||||
A.resize(rows,rows);
|
A.resize(rows,cols);
|
||||||
dA.resize(rows,rows);
|
dA.resize(rows,cols);
|
||||||
initSparse<Scalar>(density, dA, A,ForceNonZeroDiag);
|
initSparse<Scalar>(density, dA, A,ForceNonZeroDiag);
|
||||||
A.makeCompressed();
|
A.makeCompressed();
|
||||||
return rows;
|
return rows;
|
||||||
|
@ -61,7 +61,7 @@ template<typename _Scalar> class AlignedVector3
|
|||||||
Scalar* data() { return m_coeffs.data(); }
|
Scalar* data() { return m_coeffs.data(); }
|
||||||
const Scalar* data() const { return m_coeffs.data(); }
|
const Scalar* data() const { return m_coeffs.data(); }
|
||||||
Index innerStride() const { return 1; }
|
Index innerStride() const { return 1; }
|
||||||
Index outerStride() const { return m_coeffs.outerStride(); }
|
Index outerStride() const { return 3; }
|
||||||
|
|
||||||
inline const Scalar& coeff(Index row, Index col) const
|
inline const Scalar& coeff(Index row, Index col) const
|
||||||
{ return m_coeffs.coeff(row, col); }
|
{ return m_coeffs.coeff(row, col); }
|
||||||
|
@ -34,6 +34,8 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
typedef __int16 int16_t;
|
||||||
|
typedef unsigned __int16 uint16_t;
|
||||||
typedef __int32 int32_t;
|
typedef __int32 int32_t;
|
||||||
typedef unsigned __int32 uint32_t;
|
typedef unsigned __int32 uint32_t;
|
||||||
typedef __int64 int64_t;
|
typedef __int64 int64_t;
|
||||||
|
@ -124,7 +124,8 @@ template <typename T> struct SumReducer
|
|||||||
}
|
}
|
||||||
template <typename Packet>
|
template <typename Packet>
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||||
return saccum + predux(vaccum);
|
internal::scalar_sum_op<T> sum_op;
|
||||||
|
return sum_op(saccum, predux(vaccum));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -173,7 +174,8 @@ template <typename T> struct MeanReducer
|
|||||||
}
|
}
|
||||||
template <typename Packet>
|
template <typename Packet>
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||||
return (saccum + predux(vaccum)) / (scalarCount_ + packetCount_ * unpacket_traits<Packet>::size);
|
internal::scalar_sum_op<T> sum_op;
|
||||||
|
return sum_op(saccum, predux(vaccum)) / (scalarCount_ + packetCount_ * unpacket_traits<Packet>::size);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -304,7 +306,8 @@ template <typename T> struct ProdReducer
|
|||||||
static const bool IsStateful = false;
|
static const bool IsStateful = false;
|
||||||
|
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) const {
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reduce(const T t, T* accum) const {
|
||||||
(*accum) *= t;
|
internal::scalar_product_op<T> prod_op;
|
||||||
|
(*accum) = prod_op(*accum, t);
|
||||||
}
|
}
|
||||||
template <typename Packet>
|
template <typename Packet>
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reducePacket(const Packet& p, Packet* accum) const {
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void reducePacket(const Packet& p, Packet* accum) const {
|
||||||
@ -328,7 +331,8 @@ template <typename T> struct ProdReducer
|
|||||||
}
|
}
|
||||||
template <typename Packet>
|
template <typename Packet>
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE T finalizeBoth(const T saccum, const Packet& vaccum) const {
|
||||||
return saccum * predux_mul(vaccum);
|
internal::scalar_product_op<T> prod_op;
|
||||||
|
return prod_op(saccum, predux_mul(vaccum));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -116,10 +116,10 @@ void test_cuda_argmax_dim()
|
|||||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||||
|
|
||||||
VERIFY_IS_EQUAL(tensor_arg.dimensions().TotalSize(),
|
VERIFY_IS_EQUAL(tensor_arg.size(),
|
||||||
size_t(2*3*5*7 / tensor.dimension(dim)));
|
size_t(2*3*5*7 / tensor.dimension(dim)));
|
||||||
|
|
||||||
for (size_t n = 0; n < tensor_arg.dimensions().TotalSize(); ++n) {
|
for (DenseIndex n = 0; n < tensor_arg.size(); ++n) {
|
||||||
// Expect max to be in the first index of the reduced dimension
|
// Expect max to be in the first index of the reduced dimension
|
||||||
VERIFY_IS_EQUAL(tensor_arg.data()[n], 0);
|
VERIFY_IS_EQUAL(tensor_arg.data()[n], 0);
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ void test_cuda_argmax_dim()
|
|||||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||||
|
|
||||||
for (size_t n = 0; n < tensor_arg.dimensions().TotalSize(); ++n) {
|
for (DenseIndex n = 0; n < tensor_arg.size(); ++n) {
|
||||||
// Expect max to be in the last index of the reduced dimension
|
// Expect max to be in the last index of the reduced dimension
|
||||||
VERIFY_IS_EQUAL(tensor_arg.data()[n], tensor.dimension(dim) - 1);
|
VERIFY_IS_EQUAL(tensor_arg.data()[n], tensor.dimension(dim) - 1);
|
||||||
}
|
}
|
||||||
@ -205,10 +205,10 @@ void test_cuda_argmin_dim()
|
|||||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||||
|
|
||||||
VERIFY_IS_EQUAL(tensor_arg.dimensions().TotalSize(),
|
VERIFY_IS_EQUAL(tensor_arg.size(),
|
||||||
size_t(2*3*5*7 / tensor.dimension(dim)));
|
2*3*5*7 / tensor.dimension(dim));
|
||||||
|
|
||||||
for (size_t n = 0; n < tensor_arg.dimensions().TotalSize(); ++n) {
|
for (DenseIndex n = 0; n < tensor_arg.size(); ++n) {
|
||||||
// Expect min to be in the first index of the reduced dimension
|
// Expect min to be in the first index of the reduced dimension
|
||||||
VERIFY_IS_EQUAL(tensor_arg.data()[n], 0);
|
VERIFY_IS_EQUAL(tensor_arg.data()[n], 0);
|
||||||
}
|
}
|
||||||
@ -233,7 +233,7 @@ void test_cuda_argmin_dim()
|
|||||||
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
assert(cudaMemcpyAsync(tensor_arg.data(), d_out, out_bytes, cudaMemcpyDeviceToHost, gpu_device.stream()) == cudaSuccess);
|
||||||
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
assert(cudaStreamSynchronize(gpu_device.stream()) == cudaSuccess);
|
||||||
|
|
||||||
for (size_t n = 0; n < tensor_arg.dimensions().TotalSize(); ++n) {
|
for (DenseIndex n = 0; n < tensor_arg.size(); ++n) {
|
||||||
// Expect max to be in the last index of the reduced dimension
|
// Expect max to be in the last index of the reduced dimension
|
||||||
VERIFY_IS_EQUAL(tensor_arg.data()[n], tensor.dimension(dim) - 1);
|
VERIFY_IS_EQUAL(tensor_arg.data()[n], tensor.dimension(dim) - 1);
|
||||||
}
|
}
|
||||||
|
@ -108,8 +108,46 @@ static void test_cuda_sum_reductions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void test_cuda_product_reductions() {
|
||||||
|
|
||||||
|
Eigen::CudaStreamDevice stream;
|
||||||
|
Eigen::GpuDevice gpu_device(&stream);
|
||||||
|
|
||||||
|
const int num_rows = internal::random<int>(1024, 5*1024);
|
||||||
|
const int num_cols = internal::random<int>(1024, 5*1024);
|
||||||
|
|
||||||
|
Tensor<std::complex<float>, 2> in(num_rows, num_cols);
|
||||||
|
in.setRandom();
|
||||||
|
|
||||||
|
Tensor<std::complex<float>, 0> full_redux;
|
||||||
|
full_redux = in.prod();
|
||||||
|
|
||||||
|
std::size_t in_bytes = in.size() * sizeof(std::complex<float>);
|
||||||
|
std::size_t out_bytes = full_redux.size() * sizeof(std::complex<float>);
|
||||||
|
std::complex<float>* gpu_in_ptr = static_cast<std::complex<float>*>(gpu_device.allocate(in_bytes));
|
||||||
|
std::complex<float>* gpu_out_ptr = static_cast<std::complex<float>*>(gpu_device.allocate(out_bytes));
|
||||||
|
gpu_device.memcpyHostToDevice(gpu_in_ptr, in.data(), in_bytes);
|
||||||
|
|
||||||
|
TensorMap<Tensor<std::complex<float>, 2> > in_gpu(gpu_in_ptr, num_rows, num_cols);
|
||||||
|
TensorMap<Tensor<std::complex<float>, 0> > out_gpu(gpu_out_ptr);
|
||||||
|
|
||||||
|
out_gpu.device(gpu_device) = in_gpu.prod();
|
||||||
|
|
||||||
|
Tensor<std::complex<float>, 0> full_redux_gpu;
|
||||||
|
gpu_device.memcpyDeviceToHost(full_redux_gpu.data(), gpu_out_ptr, out_bytes);
|
||||||
|
gpu_device.synchronize();
|
||||||
|
|
||||||
|
// Check that the CPU and GPU reductions return the same result.
|
||||||
|
VERIFY_IS_APPROX(full_redux(), full_redux_gpu());
|
||||||
|
|
||||||
|
gpu_device.deallocate(gpu_in_ptr);
|
||||||
|
gpu_device.deallocate(gpu_out_ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void test_cxx11_tensor_complex()
|
void test_cxx11_tensor_complex()
|
||||||
{
|
{
|
||||||
CALL_SUBTEST(test_cuda_nullary());
|
CALL_SUBTEST(test_cuda_nullary());
|
||||||
CALL_SUBTEST(test_cuda_sum_reductions());
|
CALL_SUBTEST(test_cuda_sum_reductions());
|
||||||
|
CALL_SUBTEST(test_cuda_product_reductions());
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user