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>:
> On Tue, Jul 20, 2010 at 4:51 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
>> 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?
>
> Not really but somebody might think hey, it accepts input from
> std::cin in the form of
>
> 1 2 3
> 4 5 6
>
> why not from a text file... I admit, we can easily deal with that. I
> was more like brainstorming. ;)

Just for the record: I don't see how allowing reading from a text file
is a drawback, I see it as a feature :-)

>
>>
>>> 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 ?
>
> I just can't see right now how we can use Eigen::IOFormat while
> keeping the suggested API. We need something like a class providing
> several static operator>> functions taking different parameters or
> such. I don't doubt that this is doable, I am just wondering whether
> we might be quickly introduce API breaks.

Why not do just like we do for output?

Output works like this:
cout << matrix.format(myIOFormat);

format returns a WithFormat proxy object. So the operator<< is taking
a const WithFormat&.

Why not define a operator>> taking a WithFormat& ? So the API would be:
cin >> matrix.format(myIOFormat);


>
>>> 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).
>
> Maybe, once the Eigen::IOFormat is specified this is then easily doable.

Yes, actually, writing the above I realized that if you agree with an
API like the above, then there is no clash at all, because Helmut's
default operator>> takes a DenseBase& while the IOFormat-enabled
variants take a WithFormat&.

Benoit

>
> I just want to emphasize that I am not all against incorporating
> extended IO functionality, I am just against quick shots which might
> back fire...
>
> - Hauke
>
>
>



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