Ticket #10835: trac_10834_etuple.patch

File trac_10834_etuple.patch, 1.5 KB (added by mario pernici, 12 years ago)
  • sage/rings/polynomial/polydict.pyx

    # HG changeset patch
    # User Mario Pernici <mario.pernici@gmail.com>
    # Date 1298476103 -3600
    # Node ID 98be85d1ad78ddcfa6cef6986ef2f5a8e645f885
    # Parent  120c07be6358d93bcff503363d379c26b8342f2b
    faster creation of an ETuple from a list or tuple
    
    diff -r 120c07be6358 -r 98be85d1ad78 sage/rings/polynomial/polydict.pyx
    a b  
    915915        if data is None:
    916916            return
    917917        cdef size_t ind
     918        cdef int v
    918919        if PY_TYPE_CHECK(data,ETuple):
    919920            self._length = (<ETuple>data)._length
    920921            self._nonzero = (<ETuple>data)._nonzero
     
    932933                ind += 1
    933934        elif PY_TYPE_CHECK(data,list) or PY_TYPE_CHECK(data,tuple):
    934935            self._length = len(data)
    935             tpl = zip(range(len(data)),data)
    936936            self._nonzero = 0
    937             for (i,v) in tpl:
     937            for v in data:
    938938                if v != 0:
    939939                    self._nonzero += 1
    940940            ind = 0
    941941            self._data = <int*>sage_malloc(sizeof(int)*self._nonzero*2)
    942             for (i,v) in tpl:
     942            for i from 0 <= i < self._length:
     943                v = data[i]
    943944                if v != 0:
    944                     self._data[2*ind] = i
    945                     self._data[2*ind+1] = v
    946                     ind += 1
     945                    self._data[ind] = i
     946                    self._data[ind+1] = v
     947                    ind += 2
    947948        else:
    948949            raise TypeError
    949950