diff --git a/api/src/main/java/ai/djl/ndarray/internal/NDFormat.java b/api/src/main/java/ai/djl/ndarray/internal/NDFormat.java index c60998c13bf..2bb36da4918 100644 --- a/api/src/main/java/ai/djl/ndarray/internal/NDFormat.java +++ b/api/src/main/java/ai/djl/ndarray/internal/NDFormat.java @@ -83,6 +83,7 @@ public static String format( sb.append(" hasGradient"); } if (!withContent) { + sb.append("\nCheck the \"Development Guideline\"->Debug to enable array display.\n"); return sb.toString(); } @@ -114,9 +115,7 @@ protected String dump( int maxDepth, int maxRows, int maxColumns) { - init(array); sb.append(LF); - long size = array.size(); long dimension = array.getShape().dimension(); if (size == 0) { @@ -130,6 +129,7 @@ protected String dump( } else if (dimension > maxDepth) { sb.append("[ Exceed max print dimension ]"); } else { + init(array); dump(sb, array, 0, true, maxRows, maxColumns); } return sb.toString(); diff --git a/api/src/test/java/ai/djl/ndarray/internal/NDFormatTest.java b/api/src/test/java/ai/djl/ndarray/internal/NDFormatTest.java index f629f51b4d5..9b3f0294cef 100644 --- a/api/src/test/java/ai/djl/ndarray/internal/NDFormatTest.java +++ b/api/src/test/java/ai/djl/ndarray/internal/NDFormatTest.java @@ -136,4 +136,14 @@ public void testFloat64Format() { Assert.assertEquals(str, "ND: (3) cpu() float64" + LF + "[ 1., 2., 100.]" + LF); } } + + @Test + public void testLargeArray() { + try (NDManager manager = NDManager.newBaseManager()) { + NDArray large = manager.arange(0f, 100000000f).reshape(100, 100, 100, 100); + String str = large.toString(); + Assert.assertEquals( + str, "ND: (100, 100, 100, 100) cpu() float32\n[ Exceed max print size ]"); + } + } } diff --git a/docs/development/development_guideline.md b/docs/development/development_guideline.md index 1b043de3b50..a4d8e42b39a 100644 --- a/docs/development/development_guideline.md +++ b/docs/development/development_guideline.md @@ -156,12 +156,11 @@ IntelliJ allows you to [customize the data view in the Debug Tools](https://www. You can create your own NDArray renderer as follows: ![](img/custom_debug_view.png) -Please make sure to: - -- Check the "On-demand" option, which causes IntelliJ to only render the NDArray when you click on the variable. -- Change the "Use following expression" field to `toDebugString(true)` to show NDArray content -- Change the "Use following expression" field to something like `toDebugString(1000, 10, 10, 20, true)` +Opening the IDE Settings/Preferences (`⌘ ,`), in *Java Type Renderer* section, you can enable array display by: +- Change the "Use following expression" field to `toDebugString(true)` to show NDArray content. +- Change the "Use following expression" field to something like `toDebugString(100, 10, 10, 20, true)`. if you want to adjust the range of NDArray's debug output. +- Check the "On-demand" option, if you want the IntelliJ to render the NDArray only on clicking the variable. ## Common Problems