xtensor icon indicating copy to clipboard operation
xtensor copied to clipboard

Implement pretty-printing for xtensor containers in GDB

Open xiuliren opened this issue 5 years ago • 4 comments

is there a way to print out the values in a xtensor?

this is the output I get now. Note that the coords variable is a xtensor rather than a xexpression.

(gdb) p coords
$7 = {<xt::xview_semantic<xt::xview<xt::xtensor_container<xt::uvector<float, std::allocator<float> >, 2, (xt::layout_t
ype)1, xt::xtensor_expression_tag> const&, xt::xall<unsigned long>, unsigned long> >> = {<xt::xsemantic_base<xt::xview
<xt::xtensor_container<xt::uvector<float, std::allocator<float> >, 2, (xt::layout_type)1, xt::xtensor_expression_tag> 
const&, xt::xall<unsigned long>, unsigned long> >> = {<xt::xexpression<xt::xview<xt::xtensor_container<xt::uvector<flo
at, std::allocator<float> >, 2, (xt::layout_type)1, xt::xtensor_expression_tag> const&, xt::xall<unsigned long>, unsig
ned long> >> = {
        p_shared = {<std::__shared_ptr<xt::xview<xt::xtensor_container<xt::uvector<float, std::allocator<float> >, 2, 
(xt::layout_type)1, xt::xtensor_expression_tag> const&, xt::xall<unsigned long>, unsigned long>, (__gnu_cxx::_Lock_pol
icy)2>> = {<std::__shared_ptr_access<xt::xview<xt::xtensor_container<xt::uvector<float, std::allocator<float> >, 2, (x
t::layout_type)1, xt::xtensor_expression_tag> const&, xt::xall<unsigned long>, unsigned long>, (__gnu_cxx::_Lock_polic
y)2, false, false>> = {<No data fields>}, _M_ptr = 0x0, _M_refcount = {
              _M_pi = 0x0}}, <No data fields>}}, <No data fields>}, <No data fields>}, <xt::xiterable<xt::xview<xt::xt
ensor_container<xt::uvector<float, std::allocator<float> >, 2, (xt::layout_type)1, xt::xtensor_expression_tag> const&,
 xt::xall<unsigned long>, unsigned long> >> = {<xt::xconst_iterable<xt::xview<xt::xtensor_container<xt::uvector<float,
 std::allocator<float> >, 2, (xt::layout_type)1, xt::xtensor_expression_tag> const&, xt::xall<unsigned long>, unsigned
 long> >> = {<No data fields>}, <No data fields>}, <xt::xaccessible<xt::xview<xt::xtensor_container<xt::uvector<float,
 std::allocator<float> >, 2, (xt::layout_type)1, xt::xtensor_expression_tag> const&, xt::xall<unsigned long>, unsigned
 long> >> = {<xt::xconst_accessible<xt::xview<xt::xtensor_container<xt::uvector<float, std::allocator<float> >, 2, (xt
::layout_type)1, xt::xtensor_expression_tag> const&, xt::xall<unsigned long>, unsigned long> >> = {<No data fields>}, 
<No data fields>}, <xt::extension::xtensor_empty_base> = {<No data fields>}, static is_const = true, 
  static static_layout = xt::layout_type::dynamic, static contiguous_layout = false, static is_strided_view = true, 
  static is_contiguous_view = false, static has_trivial_strides = false, m_e = @0x555555d72020, 
  m_slices = {<std::_Tuple_impl<0, xt::xall<unsigned long>, unsigned long>> = {<std::_Tuple_impl<1, unsigned long>> = 
{<std::_Head_base<1, unsigned long, false>> = {
          _M_head_impl = 1}, <No data fields>}, <std::_Head_base<0, xt::xall<unsigned long>, false>> = {
        _M_head_impl = {<xt::xslice<xt::xall<unsigned long> >> = {<No data fields>}, 
          m_size = 8}}, <No data fields>}, <No data fields>}, m_shape = {_M_elems = {8}}, m_strides = {_M_elems = {
      140737488340848}}, m_backstrides = {_M_elems = {140737488340848}}, m_data_offset = 93825000193232, 
  m_strides_computed = false}

xiuliren avatar Oct 18 '19 18:10 xiuliren

I don't use gdb so I'm not sure, can yo try to print coords.data() ? it should print the underlying 1-D buffer.

JohanMabille avatar Nov 26 '19 08:11 JohanMabille

I think there are ways to implement pretty printing for GDB ...

Here seems to be some good introduction on how to do it: http://www.kurokatta.org/grumble/2018/05/gdb-pretty

If someone wants to do that that would be awesome!

wolfv avatar Dec 19 '19 09:12 wolfv

I made an initial version of converting the xarray, xtensor, and xtensor_fixed containers for use in gdb's python interface. https://github.com/christopherburke/gdb_xt2np It actually goes beyond a pretty printer because it actually copies the array data into a numpy array, thus allowing one to use numpy or matplotlib plotting within gdb's python interpreter to examining the array data. It opens up development for any kind of data visualization one can think up in python to aid in debugging xtensor containers.

christopherburke avatar Oct 19 '21 18:10 christopherburke

Awesome!

JohanMabille avatar Oct 20 '21 16:10 JohanMabille