blitzpp / blitz

Blitz++ Multi-Dimensional Array Library for C++
https://github.com/blitzpp/blitz/wiki
Other
405 stars 84 forks source link

Using GDB to print Blitz++ Array #43

Closed jipuwang closed 6 years ago

jipuwang commented 6 years ago

Does anyone know how to use GDB to print Blitz++ Array?

Thanks!

slayoo commented 6 years ago

this could help: https://blog.semicolonsoftware.de/debugging-numerical-c-c-fortran-code-with-gdb-and-numpy/

jipuwang commented 6 years ago

Thanks! @slayoo I can see that'd work for C++ arrays, but is that also true for Blitz++ Arrays?

slayoo commented 6 years ago

While there might be some ways of achieving higher-level understanding of Blitz++ arrays from gdb, here the low-level one should be enough, i.e.:

#include <blitz/array.h>

using T = blitz::Array<float,2>;

void fun(T &arg)
{
  arg = 3;
}

int main()
{
  T a(3,3);
  a = 1,2,3,
      4,5,6,
      7,8,9;
  fun(a);
}
$ g++ -g -std=c++11 test.cpp
$ gdb a.out
(gdb) break fun
Breakpoint 1 at 0x4008a2: file test.cpp, line 7.
(gdb) run
Breakpoint 1, fun (arg=...) at test.cpp:7
7         arg = 3;
(gdb) print arg.data()
$1 = (const blitz::Array<float, 2>::T_numtype * restrict) 0x619eb8
(gdb) print *arg.data()
$2 = 1
(gdb) print *(arg.data()+1)
$3 = 2
(gdb) print *(arg.data()+2)
$4 = 3
(gdb) print *(arg.data()+3)
$5 = 4

So from NumPy perspective, there would be no difference between Blitz++ or any other array that uses contiguous memory as storage (non-contiguous cases can likely also be handled as NumPy offers similar flexibility as Blitz when it comes to defining memory ordering, strides, etc).

Note that the referenced gdb_numpy module is Python 2 code hence will likely not be compatible out of the box with current gdb installation.

HTH

slayoo commented 6 years ago

let me close this one - please reopen if needed