Re: [eigen] An insistent plea for an input operator

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


I am not a big fan of this mainly due to safety reasons and
consistency reasons.

Currently, you can even use an ifstream since it is an istream. We
also need to deal with the way in which the data is given. Why should
it be given as 1 2 3 4 ... and not 1,2,3,4 (probably because of the
locale, see my next point).

Also, I am not sure how this is going to work with floats on different
locals.  Some systems have '.' as their decimal separator and others
','. You don't recognize this when working in C++ but I think you
will, when you start processing user input.

For me, the inclusion of such an operator must at least be optional,
i.e. not automatically through Dense, Core or Eigen. If it were in the
Eigen namespace, how would I provide my own version? Does it have to
go to another namespace?

- Hauke

On Tue, Jul 20, 2010 at 3:41 PM, Gael Guennebaud
<gael.guennebaud@xxxxxxxxx> wrote:
> I'm ok to add it, I cannot see how it could block us in the future to
> support more sophisticated input format.
>
> gael
>
> On Tue, Jul 20, 2010 at 2:48 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
>> ok, my biggest objection was that getting general input right is hard,
>> and that we must then get the API right; but I can agree that in any
>> case we'll end up supporting the very simple stream format that your
>> operator>> is supporting. So, why not.
>>
>> Others?
>>
>> Benoit
>>
>> 2010/7/20 Helmut Jarausch <jarausch@xxxxxxxxxxxxxxxxxxx>:
>>> Hi,
>>>
>>> I know, I've asked for this feature several month, ago,
>>> but I'm obstinate to ask for it again and again.
>>>
>>> Background: I'm teaching C++ for beginners (mathematicians) and
>>> there should be an easy input operator for matrices and vectors.
>>>
>>> Currently, I have to patch Eigen (2 or 3) by adding
>>>
>>> namespace Eigen {
>>> template<typename Derived>
>>> std::istream & operator >>(std::istream & Inp, MatrixBase<Derived> & m)
>>> {
>>>  for (int i = 0; i < m.rows(); ++i)
>>>    for (int j = 0; j < m.cols(); j++)
>>>      Inp >> m(i,j);
>>>
>>>  return Inp;
>>> }
>>>
>>> }
>>>
>>> to make the following simple program run
>>>
>>>
>>> int main() {
>>> Eigen::MatrixXi A(2,3);
>>>  std::cerr << "intput 2x3 matrix:\n";
>>>  std::cin >> A;
>>>  std::cout << "I've got:\n" << A << std::endl;
>>> }
>>>
>>> I've never understood the objections against adding this.
>>> Pardon for being such obstinate,
>>> Helmut.
>>>
>>> My problem is, that students download Eigen themselves and forget about
>>> adding these few lines.
>>>
>>> --
>>> Helmut Jarausch
>>>
>>> Lehrstuhl fuer Numerische Mathematik
>>> RWTH - Aachen University
>>> D 52056 Aachen, Germany
>>>
>>>
>>>
>>>
>>
>>
>>
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/