mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-11 07:31:48 +08:00
bug #1417: make LinSpace compatible with std::complex
(grafted from 8508db52ab832bfd52ac314c862b7beeb64dc182 )
This commit is contained in:
parent
9f25cdf4f6
commit
72fa6775e8
@ -44,16 +44,16 @@ struct linspaced_op_impl<Scalar,Packet,/*IsInteger*/false>
|
|||||||
{
|
{
|
||||||
linspaced_op_impl(const Scalar& low, const Scalar& high, Index num_steps) :
|
linspaced_op_impl(const Scalar& low, const Scalar& high, Index num_steps) :
|
||||||
m_low(low), m_high(high), m_size1(num_steps==1 ? 1 : num_steps-1), m_step(num_steps==1 ? Scalar() : (high-low)/Scalar(num_steps-1)),
|
m_low(low), m_high(high), m_size1(num_steps==1 ? 1 : num_steps-1), m_step(num_steps==1 ? Scalar() : (high-low)/Scalar(num_steps-1)),
|
||||||
m_interPacket(plset<Packet>(0)),
|
|
||||||
m_flip(numext::abs(high)<numext::abs(low))
|
m_flip(numext::abs(high)<numext::abs(low))
|
||||||
{}
|
{}
|
||||||
|
|
||||||
template<typename IndexType>
|
template<typename IndexType>
|
||||||
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (IndexType i) const {
|
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const Scalar operator() (IndexType i) const {
|
||||||
|
typedef typename NumTraits<Scalar>::Real RealScalar;
|
||||||
if(m_flip)
|
if(m_flip)
|
||||||
return (i==0)? m_low : (m_high - (m_size1-i)*m_step);
|
return (i==0)? m_low : (m_high - RealScalar(m_size1-i)*m_step);
|
||||||
else
|
else
|
||||||
return (i==m_size1)? m_high : (m_low + i*m_step);
|
return (i==m_size1)? m_high : (m_low + RealScalar(i)*m_step);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename IndexType>
|
template<typename IndexType>
|
||||||
@ -63,7 +63,7 @@ struct linspaced_op_impl<Scalar,Packet,/*IsInteger*/false>
|
|||||||
// [low, ..., low] + ( [step, ..., step] * ( [i, ..., i] + [0, ..., size] ) )
|
// [low, ..., low] + ( [step, ..., step] * ( [i, ..., i] + [0, ..., size] ) )
|
||||||
if(m_flip)
|
if(m_flip)
|
||||||
{
|
{
|
||||||
Packet pi = padd(pset1<Packet>(Scalar(i-m_size1)),m_interPacket);
|
Packet pi = plset<Packet>(Scalar(i-m_size1));
|
||||||
Packet res = padd(pset1<Packet>(m_high), pmul(pset1<Packet>(m_step), pi));
|
Packet res = padd(pset1<Packet>(m_high), pmul(pset1<Packet>(m_step), pi));
|
||||||
if(i==0)
|
if(i==0)
|
||||||
res = pinsertfirst(res, m_low);
|
res = pinsertfirst(res, m_low);
|
||||||
@ -71,7 +71,7 @@ struct linspaced_op_impl<Scalar,Packet,/*IsInteger*/false>
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Packet pi = padd(pset1<Packet>(Scalar(i)),m_interPacket);
|
Packet pi = plset<Packet>(Scalar(i));
|
||||||
Packet res = padd(pset1<Packet>(m_low), pmul(pset1<Packet>(m_step), pi));
|
Packet res = padd(pset1<Packet>(m_low), pmul(pset1<Packet>(m_step), pi));
|
||||||
if(i==m_size1-unpacket_traits<Packet>::size+1)
|
if(i==m_size1-unpacket_traits<Packet>::size+1)
|
||||||
res = pinsertlast(res, m_high);
|
res = pinsertlast(res, m_high);
|
||||||
@ -83,7 +83,6 @@ struct linspaced_op_impl<Scalar,Packet,/*IsInteger*/false>
|
|||||||
const Scalar m_high;
|
const Scalar m_high;
|
||||||
const Index m_size1;
|
const Index m_size1;
|
||||||
const Scalar m_step;
|
const Scalar m_step;
|
||||||
const Packet m_interPacket;
|
|
||||||
const bool m_flip;
|
const bool m_flip;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user