Menu

#89 Allow public access to internal Num_T *data (now protected)

Next_Release
open
nobody
None
1
2012-11-01
2012-11-01
Frank
No

I think it's important to allow full access to the internal raw data. In IT++ the data pointer is protected. Some time ago I used IT++ in combination with GSL. I wrote interface code to convert vectors without element-wise copying the data. This is important for performance. Just for the matrices I had to copy element-wise, because C and Fortran-style orienation was not compatible. Also other interfaces might be interesting: to Gnuradio, to Python, to Matlab, to Octave etc. All have their own matrix/vector data structures. Raw access is very important to allow interchange without unnecessary overheads.

New constructor from raw data:

cmat matrix(datapointer_to_complex_array,datasize,rows,cols)

This would be the least-cost approach to interpret other math objects as C++. Of course you should be careful when the data storage is used by two different libraries, e.g. GSL and IT++. But performance ist the most important criterium in numerical computing.

Discussion

  • Bogdan Cristea

    Bogdan Cristea - 2012-11-01

    This is why the internal raw data are protected, from your derived class you will be able to access these data members.
    Also, the raw data pointer is available through _data() member function, and the construction is possible though C-style arrays:
    Mat (const Num_T c_array, int rows, int cols, bool row_major=true, const Factory &f=DEFAULT_FACTORY)
    Vec (const Num_T
    c_array, int size, const Factory &f=DEFAULT_FACTORY)

     
  • Frank

    Frank - 2012-11-01

    It's not the same. If you look at this construction implementation in mat.h, this is an element-wise copy of the whole structure. If you want to copy, Ok, but if you want performance with just a pointer assignment this is nonsense. I lost a lot of performance in my IT++ programs (mixed with other numerical libraries) because of unnecessary copy operations.

    In this Armadillo-Mex interface:
    http://www.myoutsourcedbrain.com/2009/08/fast-scientific-computation-in-mex.html
    the MATLAB matrix data pointer is assigned to the Armadillo Matrix. I think it could be made more elegant to directly construct the Mat with the MATLAB pointer, and in the end assign it to NULL that the Armadillo Mat object does not destroy the MATLAB object.

    It's not sufficient to gain read access to the pointer. Better is a full access, like not protecting the data pointer. It's a matter of security vs. performance. But in numerics, performance has a higher priority.

    Of course you could derive new classes, but I prefer to use the original Matrix and Vector data types. It does not make sense to derive all core data structures, only to gain full read/write access to the internal raw data.

    You could add a warning: "if you touch the data pointer, be aware what you're doing. You might crash your program."

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.