c++ "normal" arrays and it++ vectors

  • Carlos Pineda

    Carlos Pineda - 2013-01-24

    I am trying to call some routines made in fortran. These include arrays (in fortran sense), and should be called, acording to, say,
    via arrays, in the most traditional sense, as for example declared as
    double ar1[4]={1.0, 2.0, 3.0, 4.0};
    I would like however to use itpp classes to play around with these routines, so it would be crucial to be able to convert an Vector (in it++ sense) to an array (in traditional sense), or a Matrix (it++) to a 2 dimensional array. Is it possible? Sorry if this has already been answered, but some search in this forum has lead nowhere.

  • andy_panov

    andy_panov - 2013-01-24

    You should use data() member of Vector/Mat to get the access to raw data stored inside the container. This function returns pointer to container raw data. You should take care of bounds checking when accessing stored data via the raw pointers (make sure you are always access elements inside bounds since ITPP allocates raw data in heap) and be aware that container can change internal pointer when resized. Vec stores data in c array. The matrix is stored in c array as a row-major matrix (i.e. listing elements in sequence beginning with the first column). You should provide extra flag during matrix construction to export data from c array with different storage order. Further details can be found in vec.h and mat.h in itpp/base folder.

    Hope this helps.

    Last edit: andy_panov 2013-01-24
  • Carlos Pineda

    Carlos Pineda - 2013-01-24

    It does help. I will have time to try it not today but next week. However taking a quick look at the docs seems straightforward. Thanks!


Log in to post a comment.