This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 79 - LinSpaced does not work properly for row vectors
Summary: LinSpaced does not work properly for row vectors
Status: RESOLVED FIXED
Alias: None
Product: Eigen
Classification: Unclassified
Component: Core - expression templates (show other bugs)
Version: 3.0
Hardware: x86 - 64-bit Mac OS
: --- Unknown
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 3.0-beta3
  Show dependency treegraph
 
Reported: 2010-10-18 22:06 UTC by Ian Mackenzie
Modified: 2019-12-04 09:46 UTC (History)
4 users (show)



Attachments
Simple test cases (713 bytes, text/plain)
2010-10-18 22:06 UTC, Ian Mackenzie
no flags Details

Description Ian Mackenzie 2010-10-18 22:06:05 UTC
Created attachment 12 [details]
Simple test cases

There seem to be some issues with using LinSpaced with row vectors.  Simply outputting something like RowVectorXd::LinSpaced(3, 0, 1) works, but comparing RowVectorXd::LinSpaced(3, 0, 1) == RowVector3d(0, 0.5, 1) fails and performing the explicit conversion MatrixXd(RowVectorXd::LinSpaced(3, 0, 1)) produces a matrix of all zeros.  All the corresponding VectorXd versions work; I've attached a file that demonstrates the issue. 

Eigen 3 Beta 2
g++ --version: i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
Comment 1 Hauke Heibel 2010-10-19 09:44:27 UTC
Thanks for pointing this out. I just fixed it. The issue is that during two dimensional indexing the linspace functor always assumed 'row' to be the running index whereas in your example it is 'col'. My fix was to use

  row + col

as the new index since either of the to must be zero. I am also checking this with ei_assert. A regression test was added too.
Comment 2 Hauke Heibel 2010-10-20 10:27:41 UTC
I would fix it like this....

template<typename ExpressionType, typename Scalar = typename ExpressionType::Scalar>
struct ei_plain_row_type
{
  typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
                 ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> MatrixRowType;
  typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime,
                 ExpressionType::PlainObject::Options | RowMajor, 1, ExpressionType::MaxColsAtCompileTime> ArrayRowType;

  typedef typename ei_meta_if< ei_is_same_type< typename ei_traits<ExpressionType>::XprKind, MatrixXpr >::ret,
    MatrixRowType,
    ArrayRowType >::ret type;
};

- Hauke
Comment 3 Hauke Heibel 2010-10-20 13:48:30 UTC
(In reply to comment #2)
> I would fix it like this....
> 
> template<typename ExpressionType, typename Scalar = typename
> ExpressionType::Scalar>
> struct ei_plain_row_type
> {
>   typedef Matrix<Scalar, 1, ExpressionType::ColsAtCompileTime,
>                  ExpressionType::PlainObject::Options | RowMajor, 1,
> ExpressionType::MaxColsAtCompileTime> MatrixRowType;
>   typedef Array<Scalar, 1, ExpressionType::ColsAtCompileTime,
>                  ExpressionType::PlainObject::Options | RowMajor, 1,
> ExpressionType::MaxColsAtCompileTime> ArrayRowType;
> 
>   typedef typename ei_meta_if< ei_is_same_type< typename
> ei_traits<ExpressionType>::XprKind, MatrixXpr >::ret,
>     MatrixRowType,
>     ArrayRowType >::ret type;
> };
> 
> - Hauke

I don't know what happened here. Sorry for the noise.
Comment 4 Nobody 2019-12-04 09:46:43 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/79.

Note You need to log in before you can comment on or make changes to this bug.