Opened 13 years ago

Closed 12 years ago

#4182 closed defect (fixed)

[with patch, positive review] plot3d fails with 'IndexError: list index out of range'

Reported by: jhpalmieri Owned by: was
Priority: minor Milestone: sage-3.2
Component: graphics Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

sage: def g(x,y): 
...            if y <= 0 or y >= x**2: 
...                return 0 
...           else: 
...               return 1 
sage: plot3d(g, (-3, 3), (-3, 3), adaptive=True) 

fails, returning

Traceback (most recent call last): 
  File "<stdin>", line 1, in <module> 
  File "/home/palmieri/.sage/sage_notebook/worksheets/admin/37/code/ 
7.py", line 6, in <module> 
    plot3d(g, (-Integer(3), Integer(3)), (-Integer(3), Integer(3)), 
adaptive=True) 
  File "/usr/local/share/sage/local/lib/python2.5/site-packages/ 
SQLAlchemy-0.4.6-py2.5.egg/", line 1, in <module> 
  File "/home/palmieri/Documents/sage-3.1.2/local/lib/python2.5/site- 
packages/sage/plot/plot3d/plot3d.py", line 157, in plot3d 
    P = plot3d_adaptive(f, urange, vrange, **kwds) 
  File "/home/palmieri/Documents/sage-3.1.2/local/lib/python2.5/site- 
packages/sage/plot/plot3d/plot3d.py", line 255, in plot3d_adaptive 
    G.set_texture(texture[k], opacity=opacity) 
IndexError: list index out of range

Attachments (1)

4182.patch (836 bytes) - added by jhpalmieri 13 years ago.

Download all attachments as: .zip

Change History (4)

Changed 13 years ago by jhpalmieri

comment:1 Changed 13 years ago by jhpalmieri

  • Summary changed from plot3d fails with 'IndexError: list index out of range' to [with patch, needs review] plot3d fails with 'IndexError: list index out of range'

Here's a patch. I was getting an index error in the last line in this code snippet:

                span = len(texture) / (max_z - min_z)    # max to avoid dividing by 0
            parts = P.partition(lambda x,y,z: int((z-min_z)*span))
        all = []
        for k, G in parts.iteritems():
            G.set_texture(texture[k], opacity=opacity)

The function g(x,y) described above is discontinuous at various places, and I think this was making the k in the last line of this snippet equal to 128 while len(texture) was also 128. Changing the definition of span in the first line, as this patch does, I hope should make k always strictly less than len(texture).

comment:2 Changed 12 years ago by anakha

  • Summary changed from [with patch, needs review] plot3d fails with 'IndexError: list index out of range' to [with patch, positive review] plot3d fails with 'IndexError: list index out of range'

This does fix the problem and looks ok.

comment:3 Changed 12 years ago by mabshoff

  • Resolution set to fixed
  • Status changed from new to closed

Merged in Sage 3.2.alpha1

Note: See TracTickets for help on using tickets.