bugGNU Octave - Bugs: bug #66197, colorbar throws out-of-memory...

 
 

bug #66197: colorbar throws out-of-memory error with caxis([-Inf,Inf])

Submitter:  A.R. Burgers <arb>
Submitted:  Mon 09 Sep 2024 12:24:18 PM UTC
   
 
Category:  Plotting with OpenGL Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Unexpected Error or Warning
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * 9.1.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Fri 18 Oct 2024 12:14:45 AM UTC, comment #9: 

I've been away from Octave for a while and just now catching up.

Octave (on the development branch) does have a clim() function which is identical to the old caxis() function.  I added this in March of this year.

xlim is different from clim.  Matlab documents that using an infinite value for the limit means that Matlab will choose something "good" based on the data.  There is no such documentation for clim.  This is because, theoretically, you could choose an infinite value since it is just about mapping colors.  On the other hand, you could never display an infinite x-value since it would be, by definition, infinitely far to the right no screen could display it.

For ordinary values of clim, Octave and Matlab are equivalent.  Ordinary can be pretty large though.  I used


caxis ([-1e10, 1e10])


and checked the resulting color in both Matlab and Octave and it is the same.

You get different results for extreme values.  For example,


caxis ([-realmax, realmax])


maps everything to the first color in the colormap.  In Octave this throws an error in colorbar


error: set: "dataaspectratio" must be finite
error: called from
    colorbar at line 321 column 12


Finally, Matlab does seem to treat true Infinite values as a chance to do autoscaling, even though the "climmode" property remains set at "manual".

jwe is very firm that no program should crash on valid input.  Even invalid input should be handled gracefully.  Octave is failing on both counts here.


Rik <rik5>
Group administrator
Tue 10 Sep 2024 06:49:04 AM UTC, comment #8: 


comment #1:

> Since it's not possible to display a colormap axis with infinite limits (and the figure seems to change to black when setting caxis([-inf inf]) indicating something is off, what is your expectation when setting it to those values?


I think I was half expecting that in analogy to xlim([-Inf,Inf]) caxis([-Inf,Inf]) would result in automatic axis setting.

A.R. Burgers <arb>
Tue 10 Sep 2024 12:59:16 AM UTC, comment #7: 

just for some visualization, here's what matlab each produces for

+vebatim+

>> clf;

colormap('jet');
[x,y,z] = peaks(50);
contourf(x,y,z, -7:9);  % first figure
caxis([-Inf,Inf]);
h = colorbar;   % second figure

close all
colormap('jet');
contourf(x,y,z, -7:9);
caxis([-100, 100]);
h = colorbar;  % third figure
-verbatim-

see attached.  it appears octave is fine for picking a near zero value when clim exceeds the color depth. the issue is both what happens when calling caxis([-inf inf]), as that's when it blanks the figure, and the error on trynig to set the colorbar limits with that (supposedly legitimate) value present.

(file matlab-caxis-theefigs.PNG)
(


Nicholas Jankowski <nrjank>
Group Member
Mon 09 Sep 2024 09:24:12 PM UTC, comment #6: 

testing in matlab 2024a:

>> clf;
colormap('default');
[x,y,z] = peaks(50);
contourf(x,y,z, -7:9);
caxis([-Inf,Inf]);
>> caxis

ans =

  -Inf   Inf


(so it seems caxis wasn't removed internally.)

it accepts [-inf, inf], and the image just has a slightly shifted but seemingly normal color range, and the axes property for clim is set to "CLim: [-Inf Inf]"

so it seems it should accept Infs for clim.  the question is maybe more how Octave should handle that .

Nicholas Jankowski <nrjank>
Group Member
Mon 09 Sep 2024 09:14:32 PM UTC, comment #5: 

ok again i misread.  the finite values are fine.  the clamping occurs on other values relative to the clim values set.  the issue is the Inf values. curious how matlab handles clim([-inf inf])

Nicholas Jankowski <nrjank>
Group Member
Mon 09 Sep 2024 09:11:47 PM UTC, comment #4: 

i missed this part of the caxis help:


Data values outside this range are clamped to the first and last colormap entries.


checking compatibility, it seems in 2022 matlab removed caxis (well, renamed it clim. the function seems nearly identical).  Octave doesn't have a clim function. Could make a simple wrapper to add that compatibility.

from some older docs online:
"caxis([cmin cmax]) sets the color limits to specified minimum and maximum values. Data values less than cmin or greater than cmax map to cmin and cmax, respectively. Values between cmin and cmax linearly map to the current colormap."

so it seems caxis is just failing to perform this clamping operation.  i see that it's not just limited to inf:



>> size(colormap)
ans =

   64    3
>> caxis([-100, 9999999])
>> caxis
ans =

  -1.0000e+02   1.0000e+07


seems like those values should get clamped to something within bounds, and that number would get passed to colorbar.

Nicholas Jankowski <nrjank>
Group Member
Mon 09 Sep 2024 09:08:19 PM UTC, comment #3: 

@nrjank: looks like our posts crossed (and say the same thing :-))

Pantxo Diribarne <pantxo>
Group Member
Mon 09 Sep 2024 09:05:08 PM UTC, comment #2: 

I can confirm the bug(s). It doesn't look like the underlying clim property supports the inf value as a placeholder for "auto limits" as xlim property does. E.g. in the following example


clf
peaks (20)
get (gca, "xlim") ## -> [-3 3]
set (gca, "xlim", [-1 1])
get (gca, "xlim") ## -> [-1 1]
set (gca, "xlim", [-inf inf])
get (gca, "xlim") ## -> [-3 3]

get (gca, "clim") ## -> [-6.3605   7.5561]
set (gca, "clim", [-1 1])
get (gca, "clim") ## -> [-1 1]
set (gca, "clim", [-inf inf])
get (gca, "clim") ## -> [-inf inf]


We can see that instead of being replaced by and appropriate upper and lower color limit, the +/-inf values are stored. The first consequence is that the lines are all black, which is not expected for me (actually I don't know what I would expect for the middle between -inf and inf:-). Then only comes the second consequence with colorbar blindly using inf clim values for its computations. But note that if the underlying clim property was fixed, colorbar would work as well.




Pantxo Diribarne <pantxo>
Group Member
Mon 09 Sep 2024 08:54:06 PM UTC, comment #1: 

line 321 is a set call to the colorbar's axes object, setting position data.  in particular it sets


set (hcb, "xtick", [], "xlim", [-0.5, 1.5],"ytickmode", "auto", "ylim", cext,"yaxislocation", "right", "label", get (hcb, "ylabel"),"__vertical__", vertical,"layer", "top", args{:});


the  ""ylim", cext "where cext is the [-inf, inf] is causing the error.  changing that value to any valid pair of numbers will avoid the issue.

Since it's not possible to display a colormap axis with infinite limits (and the figure seems to change to black when setting caxis([-inf inf]) indicating something is off, what is your expectation when setting it to those values?

i would suggest this is an input validation failure on caxis for allowing [-inf, inf] to be passed through as valid caxis limits, unless there's a compatibility issue to meet here.


Nicholas Jankowski <nrjank>
Group Member
Mon 09 Sep 2024 12:24:18 PM UTC, original submission:  

The following script:


clf;
colormap('default');
[x,y,z] = peaks(50);
contourf(x,y,z, -7:9);
caxis([-Inf,Inf]);
h = colorbar;


produces a plot looking as expected in matlab, results in an out-of-memory error with octave:


error: out of memory or dimension too large for Octave's index type
error: called from
    colorbar at line 321 column 12
    bug_cb at line 6 column 3


version:


9.1.91 (hg id: 97b44c6e3e35)


A.R. Burgers <arb>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #56421:  matlab-caxis-theefigs.PNG added by nrjank (271KiB - image/png - octave/matlab figure comparison )
file #56422:  octave-caxis-theefigs.PNG added by nrjank (135KiB - image/png - octave/matlab figure comparison )

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by arb (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-09-10 nrjank Attached File- Added matlab-caxis-theefigs.PNG, #56421
        Attached File- Added octave-caxis-theefigs.PNG, #56422
    2024-09-09 nrjank CategoryOctave Function Plotting with OpenGL
    2024-09-09 nrjank CategoryPlotting with OpenGL Octave Function
    2024-09-09 pantxo CategoryOctave Function Plotting with OpenGL
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.14-f13d.
    Corresponding source code