This forum has been archived. All content is frozen. Please use KDE Discuss instead.

ei_print_matrix and custom scalar type

Tags: None
(comma "," separated)
kfriddile
Registered Member
Posts
23
Karma
0
In the development branch, line 150 of IO.h does this:

RealScalar explicit_precision_fp = ...
explicit_precision = static_cast<std::streamsize>(explicit_precision_fp);

In my case, RealScalar is a custom fixed-point type that is not implicitly convertible to an integer (though it has a member function to explicitly do the conversion). I suppose I could specialize ei_print_matrix for my type, but I was trying to think of a more generic solution before doing that. Any ideas? Perhaps the conversion could be abstracted out into some sort of "ei_to_integer" template function or something. Then I could just specialize that small function instead of the large ei_print_matrix function.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
ok, i just updated this file so this computation is now made in a separated templated struct ei_significant_decimals_impl which you can specialize to your custom type.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
kfriddile
Registered Member
Posts
23
Karma
0
Thanks! ...works great
User avatar
bjacob
Registered Member
Posts
658
Karma
3
by the way, the name "HasFloatingPoint" is not good for fixed-point... should be renamed to IsNonInteger, or rather its negation IsInteger... let's try to remember that for 3.0...


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
kfriddile
Registered Member
Posts
23
Karma
0
Yes, I prefer IsInteger
User avatar
bjacob
Registered Member
Posts
658
Karma
3
And, my solution was not as good as your idea, so i now added ei_cast_to_int in MathFunctions.h. You can extend it by specializing ei_cast_to_int_impl.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
kfriddile
Registered Member
Posts
23
Karma
0
Also, is there an easy way to specialize Matrix<>::data()? For example, if I wanted to convert my fixed-point data to floating-point data and then return a pointer to that. I could always wrap this functionality in my own function if there isn't an easy way to do this.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
data() is only available in plain matrices, not expressions, so the cast can't be lazy evaluated here.

Code: Select all
some_fixedpoint_matrix.cast<float>().eval().data();

but careful about the lifespan of the temporary returned by eval()... you may have to create a named variable for that.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
kfriddile
Registered Member
Posts
23
Karma
0
And if I need to call something like myFixedPointNumber.ToFloat() to explicitly perform the conversion, where would I do that?
User avatar
bjacob
Registered Member
Posts
658
Karma
3
excellent point :)
So I generalized your idea to all types of casts: there now is ei_cast and ei_cast_impl, see in MathFunctions.h. Just specialize (you can do partial specializations) that to any types combinations that you neeed. Should address both of your problems at once.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
bjacob
Registered Member
Posts
658
Karma
3
...forgot to update the cast functor. should work now.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
kfriddile
Registered Member
Posts
23
Karma
0
Yep, everything works great now...I can seamlessly toggle fixed-point usage on and off throughout my entire codebase :) Also, slightly off-topic, but thought you might like to know there are at least 3 iPhone games in the appstore right now that use Eigen...soon to be 4.
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Excellent, don't hesitate to mention them under "Projects using Eigen" on the wiki main page, if you think it's OK!


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
User avatar
bjacob
Registered Member
Posts
658
Karma
3
I just saw your update on the Main Page. Excellent! If I had a iphone, i'd buy a game... but I don't even have a cell phone :P

Just a question, out of curiosity, how are you handling (or planning to handle) the license requirement to say somewhere that you're using Eigen, that it's LGPL, and provide a way to get a copy of the LGPL? (see section 3 of the LGPL v3 pasted below, it's basically the same thing as a 2-clause BSD license as long as you're not forking Eigen itself).

Of course your end-users don't want to know about Eigen, so there's no point putting that info in a highly user-visible place ;) I'm mostly asking to know what I could suggest in the future when people ask what they should be doing.

Out of the top of my head, without thinking much, I'd say that a good solution is to ship with the game a text file (say license.txt) where you mention that; and I'd say there's no need to ship a copy of the LGPL and of the GPL, just giving links to them should be enough. But I'm not a lawyer. The only thing is to make sure that it is possible for the user to view this file (if he wants to).

For reference:
http://www.gnu.org/copyleft/lesser.html

3. Object Code Incorporating Material from Library Header Files.

The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following:

* a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License.
* b) Accompany the object code with a copy of the GNU GPL and this license document.


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!
kfriddile
Registered Member
Posts
23
Karma
0
I believe the plan was to put the statement of Eigen usage and link to the LGPL in the text description for each game that is displayed when a user views the game's entry in the Apple appstore. This seems to be the best way to handle it in the case of the iPhone since users must view that page prior to downloading the game and putting that information in the games themselves is difficult on a platform with limited screen space. Also, it would be difficult to include a text file with a game and have the user be able to view that file on the iPhone (iPhone doesn't expose a typical file system and doesn't have a typical text editor). All that being said, I'm not sure if that actually happened since publishing the games wasn't my responsibility, so I will check on that right away and have the text updated if necessary.


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]