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

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


2010/7/20 Hauke Heibel <hauke.heibel@xxxxxxxxxxxxxx>:
> 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.

Sure! How is this a problem?

> 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

I think the whole point is that just because we support 1 2 3 4
doesn't prevent us from supporting other formats too. We can accept
multiple formats and for the general solution (in the future) I would
like input to support any Eigen::IOFormat, just like output does. But
even then, I don't see how it could be a problem that we support the
very simple default format 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.

C++ i/o streams store the locale parameters as member data. You can
set it by calling the imbue() method on them.

http://www.cplusplus.com/reference/iostream/ios/imbue/

Does this address your concern?

> 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?

Aaah, good point !!

Indeed if we accept Helmut's operator, you can't provide your own anymore.

At least not unless we do something about it. We could certainly
provide Helmut's operator as a simple default while letting you
override it; there are various ways we could achieve that in c++. (Let
it call a function from a template helper struct that you can
specialize, etc, etc).

Opinions?
Benoit


> 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/