xtensor-stack / xtensor

C++ tensors with broadcasting and lazy computing
BSD 3-Clause "New" or "Revised" License
3.33k stars 398 forks source link

Bug in rich rendering in Jupyter Notebook #1351

Closed agoose77 closed 5 years ago

agoose77 commented 5 years ago

It seems that there is a bug in the rich rendering of arrays. I haven't tested this for a little while, but I haven't seen any mention of this being fixed.

{
    xt::xarray<double> x = xt::arange(5*5*1);
    x.reshape({5,5, 1});
    xcpp::display(x);
}

This produces this output.

I have a numpy implementation inspired by xtensor, which doesn't have these bugs. I'm placing it here for reference: this issue is mainly just for bookkeeping.

Additionally, we could use unicode characters for the ellipses (e.g for the diagonals).

martinRenou commented 5 years ago

Thanks for reporting! I'll see if I can fix it

martinRenou commented 5 years ago

@agoose77 Can you tell me what version of xtensor you are using? I tried your code example both using master and using 0.19.1 on binder and could not see the issue

agoose77 commented 5 years ago

@martinRenou I just tried it and it seems fixed. Apologies - this was mainly something I wanted to come back and check once I had recreated my conda environment. I think it's fixed, given that this example definitely failed at one point.

martinRenou commented 5 years ago

Ok, thanks for reporting anyway :) feel free to reopen the issue if it shows up again.

agoose77 commented 5 years ago

Sorry @martinRenou, I've found a new corner case:

#include <iostream>

#include "xtensor/xarray.hpp"
#include "xtensor/xio.hpp"
#include "xtensor/xview.hpp"
#include "xcpp/xdisplay.hpp"

unsigned long n = 5;

unsigned long j = 100;

{
    xt::xarray<double> arr = xt::arange(n*j*n);
    arr.reshape({n,j,n});
    xcpp::display(arr);
}
    0.
    1.
    2.
    3.
    4.
    5.
    6.
    7.
    8.
    9.
   10.
   11.
   12.
   13.
   14.
...
...
...
...
...
...
...
  485.
  486.
  487.
  488.
  489.
  490.
  491.
  492.
  493.
  494.
  495.
  496.
  497.
  498.
  499.
  500.
  501.
  502.
  503.
  504.
  505.
  506.
  507.
  508.
  509.
  510.
  511.
  512.
  513.
  514.
...
...
...
...
...
...
...
  985.
  986.
  987.
  988.
  989.
  990.
  991.
  992.
  993.
  994.
  995.
  996.
  997.
  998.
  999.
 1000.
 1001.
 1002.
 1003.
 1004.
 1005.
 1006.
 1007.
 1008.
 1009.
 1010.
 1011.
 1012.
 1013.
 1014.
...
...
...
...
...
...
...
 1485.
 1486.
 1487.
 1488.
 1489.
 1490.
 1491.
 1492.
 1493.
 1494.
 1495.
 1496.
 1497.
 1498.
 1499.
 1500.
 1501.
 1502.
 1503.
 1504.
 1505.
 1506.
 1507.
 1508.
 1509.
 1510.
 1511.
 1512.
 1513.
 1514.
...
...
...
...
...
...
...
 1985.
 1986.
 1987.
 1988.
 1989.
 1990.
 1991.
 1992.
 1993.
 1994.
 1995.
 1996.
 1997.
 1998.
 1999.
 2000.
 2001.
 2002.
 2003.
 2004.
 2005.
 2006.
 2007.
 2008.
 2009.
 2010.
 2011.
 2012.
 2013.
 2014.
...
...
...
...
...
...
...
 2485.
 2486.
 2487.
 2488.
 2489.
 2490.
 2491.
 2492.
 2493.
 2494.
 2495.
 2496.
 2497.
 2498.
 2499.

Here's the same output in the numpy_html implementation:

0 1 2 3 4
5 6 7 8 9
10 11 12 13 14
485 486 487 488 489
490 491 492 493 494
495 496 497 498 499
500 501 502 503 504
505 506 507 508 509
510 511 512 513 514
985 986 987 988 989
990 991 992 993 994
995 996 997 998 999
1000 1001 1002 1003 1004
1005 1006 1007 1008 1009
1010 1011 1012 1013 1014
1485 1486 1487 1488 1489
1490 1491 1492 1493 1494
1495 1496 1497 1498 1499
1500 1501 1502 1503 1504
1505 1506 1507 1508 1509
1510 1511 1512 1513 1514
1985 1986 1987 1988 1989
1990 1991 1992 1993 1994
1995 1996 1997 1998 1999
2000 2001 2002 2003 2004
2005 2006 2007 2008 2009
2010 2011 2012 2013 2014
2485 2486 2487 2488 2489
2490 2491 2492 2493 2494
2495 2496 2497 2498 2499
martinRenou commented 5 years ago

That was quick :P

martinRenou commented 5 years ago

1353 should fix the issue. I looked at your implementation for numpy, your code is way cleaner than ours :P !

I will open an other PR replacing the ellipsis by unicode characters. Thanks!

agoose77 commented 5 years ago

Thanks for doing the leg work! To be honest, it's slightly tricky to get right, and I found the Python generators made the whole thing far easier :P Awesome, will keep my eyes open!