JuliaMath / Interpolations.jl

Fast, continuous interpolation of discrete datasets in Julia
http://juliamath.github.io/Interpolations.jl/
Other
518 stars 110 forks source link

Use abbreviated show methods #586

Open jonniediegelman opened 5 months ago

jonniediegelman commented 5 months ago

Most things define verbose printing for MIME"text/plain" and truncated printing otherwise so when they inside of a struct or something else, the outer type will still be readable. Take matrices, for example. When printing directly to the REPL, they take up the whole window, but when put in a tuple or some other struct, they print in a much more condensed form:

julia> A = rand(1001, 1001)
1001×1001 Matrix{Float64}:
 0.168526    0.549699    0.0326513  …  0.689658  0.868495   0.704479
 0.412381    0.797748    0.937137      0.747912  0.245714   0.840844
 0.274522    0.960224    0.0925576     0.221326  0.395387   0.772199
 0.296631    0.659681    0.184955      0.772198  0.783902   0.399211
 0.790719    0.381456    0.433416      0.817596  0.253842   0.345235
 0.00314871  0.0108288   0.823216   …  0.946155  0.245693   0.51076
 0.420072    0.654261    0.983304      0.457144  0.901755   0.443147
 0.404672    0.171471    0.735651      0.2607    0.644765   0.358372
 0.0465253   0.0385684   0.0290915     0.359137  0.352027   0.299264
 0.41703     0.750281    0.262274      0.908039  0.991868   0.792859
 0.233106    0.348446    0.359622   …  0.433735  0.0504895  0.933677
 0.260753    0.990929    0.882082      0.280586  0.457071   0.203239
 0.362754    0.585338    0.165051      0.355599  0.484482   0.956111
 0.832655    0.0803322   0.109812      0.220103  0.101719   0.94846
 0.982362    0.00378605  0.0350508     0.508623  0.692363   0.00388105
 ⋮                                  ⋱                       ⋮
 0.101199    0.198407    0.0349042     0.41007   0.950857   0.140985
 0.129417    0.963972    0.57683       0.104811  0.643553   0.917997
 0.994738    0.143453    0.335371      0.929024  0.34614    0.127911
 0.205302    0.231426    0.273763      0.214067  0.911433   0.00804951
 0.08724     0.313376    0.738153   …  0.464586  0.766788   0.554506
 0.855904    0.10522     0.77979       0.541346  0.621518   0.114377
 0.842088    0.234734    0.237107      0.68299   0.361913   0.170344
 0.0131141   0.433266    0.694657      0.742115  0.448451   0.477161
 0.83097     0.916517    0.431026      0.503254  0.0289623  0.350191
 0.268161    0.127445    0.621656   …  0.347098  0.579827   0.731732
 0.904751    0.970566    0.657812      0.26672   0.864982   0.199579
 0.896121    0.59722     0.595378      0.398617  0.638768   0.121907
 0.123954    0.26273     0.845212      0.81751   0.0507404  0.580197
 0.592213    0.421117    0.186021      0.802073  0.24506    0.00536394
 0.744174    0.153742    0.269324   …  0.619734  0.327764   0.050728

julia> (A,)
([0.16852603536656086 0.5496990216213994 … 0.8684947607745489 0.7044790820893152; 0.41238117070105706 0.7977478377361625 … 0.2457139093419155 0.8408442100733167; … ; 0.5922127468575193 0.4211172026905 … 0.24506033984915288 0.005363937696689525; 0.744174333586125 0.1537423738436272 … 0.3277643439895145 0.05072796055057449],)

When that same matrix is in an interpolator, though, it prints in it's expanded form regardless of whether the interpolator is the outermost type or not:

julia> using Interpolations

julia> itp = linear_interpolation((0:0.1:100, 0:0.1:100), A)
1001×1001 extrapolate(scale(interpolate(::Matrix{Float64}, BSpline(Linear())), (0.0:0.1:100.0, 0.0:0.1:100.0)), Throw()) with element type Float64:
 0.168526    0.549699    0.0326513  …  0.689658  0.868495   0.704479
 0.412381    0.797748    0.937137      0.747912  0.245714   0.840844
 0.274522    0.960224    0.0925576     0.221326  0.395387   0.772199
 0.296631    0.659681    0.184955      0.772198  0.783902   0.399211
 0.790719    0.381456    0.433416      0.817596  0.253842   0.345235
 0.00314871  0.0108288   0.823216   …  0.946155  0.245693   0.51076
 0.420072    0.654261    0.983304      0.457144  0.901755   0.443147
 0.404672    0.171471    0.735651      0.2607    0.644765   0.358372
 0.0465253   0.0385684   0.0290915     0.359137  0.352027   0.299264
 0.41703     0.750281    0.262274      0.908039  0.991868   0.792859
 0.233106    0.348446    0.359622   …  0.433735  0.0504895  0.933677
 0.260753    0.990929    0.882082      0.280586  0.457071   0.203239
 0.362754    0.585338    0.165051      0.355599  0.484482   0.956111
 0.832655    0.0803322   0.109812      0.220103  0.101719   0.94846
 0.982362    0.00378605  0.0350508     0.508623  0.692363   0.00388105
 ⋮                                  ⋱                       ⋮
 0.101199    0.198407    0.0349042     0.41007   0.950857   0.140985
 0.129417    0.963972    0.57683       0.104811  0.643553   0.917997
 0.994738    0.143453    0.335371      0.929024  0.34614    0.127911
 0.205302    0.231426    0.273763      0.214067  0.911433   0.00804951
 0.08724     0.313376    0.738153   …  0.464586  0.766788   0.554506
 0.855904    0.10522     0.77979       0.541346  0.621518   0.114377
 0.842088    0.234734    0.237107      0.68299   0.361913   0.170344
 0.0131141   0.433266    0.694657      0.742115  0.448451   0.477161
 0.83097     0.916517    0.431026      0.503254  0.0289623  0.350191
 0.268161    0.127445    0.621656   …  0.347098  0.579827   0.731732
 0.904751    0.970566    0.657812      0.26672   0.864982   0.199579
 0.896121    0.59722     0.595378      0.398617  0.638768   0.121907
 0.123954    0.26273     0.845212      0.81751   0.0507404  0.580197
 0.592213    0.421117    0.186021      0.802073  0.24506    0.00536394
 0.744174    0.153742    0.269324   …  0.619734  0.327764   0.050728

julia> (itp,)
(1001×1001 extrapolate(scale(interpolate(::Matrix{Float64}, BSpline(Linear())), (0.0:0.1:100.0, 0.0:0.1:100.0)), Throw()) with element type Float64:
 0.168526    0.549699    0.0326513  …  0.689658  0.868495   0.704479
 0.412381    0.797748    0.937137      0.747912  0.245714   0.840844
 0.274522    0.960224    0.0925576     0.221326  0.395387   0.772199
 0.296631    0.659681    0.184955      0.772198  0.783902   0.399211
 0.790719    0.381456    0.433416      0.817596  0.253842   0.345235
 0.00314871  0.0108288   0.823216   …  0.946155  0.245693   0.51076
 0.420072    0.654261    0.983304      0.457144  0.901755   0.443147
 0.404672    0.171471    0.735651      0.2607    0.644765   0.358372
 0.0465253   0.0385684   0.0290915     0.359137  0.352027   0.299264
 0.41703     0.750281    0.262274      0.908039  0.991868   0.792859
 0.233106    0.348446    0.359622   …  0.433735  0.0504895  0.933677
 0.260753    0.990929    0.882082      0.280586  0.457071   0.203239
 0.362754    0.585338    0.165051      0.355599  0.484482   0.956111
 0.832655    0.0803322   0.109812      0.220103  0.101719   0.94846
 0.982362    0.00378605  0.0350508     0.508623  0.692363   0.00388105
 ⋮                                  ⋱                       ⋮
 0.101199    0.198407    0.0349042     0.41007   0.950857   0.140985
 0.129417    0.963972    0.57683       0.104811  0.643553   0.917997
 0.994738    0.143453    0.335371      0.929024  0.34614    0.127911
 0.205302    0.231426    0.273763      0.214067  0.911433   0.00804951
 0.08724     0.313376    0.738153   …  0.464586  0.766788   0.554506
 0.855904    0.10522     0.77979       0.541346  0.621518   0.114377
 0.842088    0.234734    0.237107      0.68299   0.361913   0.170344
 0.0131141   0.433266    0.694657      0.742115  0.448451   0.477161
 0.83097     0.916517    0.431026      0.503254  0.0289623  0.350191
 0.268161    0.127445    0.621656   …  0.347098  0.579827   0.731732
 0.904751    0.970566    0.657812      0.26672   0.864982   0.199579
 0.896121    0.59722     0.595378      0.398617  0.638768   0.121907
 0.123954    0.26273     0.845212      0.81751   0.0507404  0.580197
 0.592213    0.421117    0.186021      0.802073  0.24506    0.00536394
 0.744174    0.153742    0.269324   …  0.619734  0.327764   0.050728,)

When you're working with structs that might have multiple interpolators inside them, the printing can fill up the console pretty quickly.

jonniediegelman commented 5 months ago

I'd go as far as to argue that the abbreviated printing doesn't need to show any of the inner array.