Ticket #10028: trac_10028_error_messages.patch

File trac_10028_error_messages.patch, 81.9 KB (added by aapitzsch, 10 years ago)
  • sage/matrix/matrix0.pyx

    # HG changeset patch
    # User André Apitzsch <andre.apitzsch@st.ovgu.de>
    # Date 1296219305 -3600
    # Node ID c9cd63c29cf8cea89a2ee21411a67394d31fb9a0
    # Parent  063ffd2a1aa7c0aaf2f7548513dc8ee546a0a108
    trac 10028: error messages matrices
    
    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix0.pyx
    a b  
    389389        raised.
    390390        """
    391391        if i<0 or i >= self._nrows or j<0 or j >= self._ncols:
    392             raise IndexError, "matrix index out of range"
     392            raise IndexError("matrix index out of range")
    393393
    394394    cdef check_mutability(self):
    395395        """
     
    401401        If self is mutable, the cache of results about self is deleted.
    402402        """
    403403        if self._mutability._is_immutable:
    404             raise ValueError, "matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M)."
     404            raise ValueError("matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).")
    405405        else:
    406406            self._cache = {}           
    407407
     
    417417        If self is mutable, the cache of results about self is deleted.
    418418        """
    419419        if self._mutability._is_immutable:
    420             raise ValueError, "matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M)."
     420            raise ValueError("matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).")
    421421        else:
    422422            self._cache = {}
    423423           
    424424        if i<0 or i >= self._nrows or j<0 or j >= self._ncols:
    425             raise IndexError, "matrix index out of range"           
    426 
     425            raise IndexError("matrix index out of range")
    427426
    428427    def set_immutable(self):
    429428        r"""
     
    527526        This is fast since it is a cdef function and there is no bounds
    528527        checking.
    529528        """
    530         raise NotImplementedError, "this must be defined in the derived class (type=%s)"%type(self)
     529        raise NotImplementedError("this must be defined in the derived class (type=%s)"%type(self))
    531530   
    532531    cdef get_unsafe(self, Py_ssize_t i, Py_ssize_t j):
    533532        """
     
    536535        This is fast since it is a cdef function and there is no bounds
    537536        checking.
    538537        """
    539         raise NotImplementedError, "this must be defined in the derived type."
     538        raise NotImplementedError("this must be defined in the derived type.")
    540539
    541540##     def _get_very_unsafe(self, i, j):
    542541##         r"""
     
    821820            key_tuple = <tuple>key
    822821            #if PyTuple_Size(key_tuple) != 2:
    823822            if len(key_tuple) != 2:
    824                 raise IndexError, "index must be an integer or pair of integers"
     823                raise IndexError("index must be an integer or pair of integers")
    825824
    826825            row_index = <object>PyTuple_GET_ITEM(key_tuple, 0)
    827826            col_index = <object>PyTuple_GET_ITEM(key_tuple, 1)
     
    839838                        row_list[i] = ind
    840839                       
    841840                    if ind < 0 or ind >= nrows:
    842                         raise IndexError, "matrix index out of range"
     841                        raise IndexError("matrix index out of range")
    843842            elif PySlice_Check(<PyObject *>row_index):
    844843                row_list = range(*row_index.indices(nrows))
    845844            else:
    846845                if not PyIndex_Check(row_index):
    847                     raise TypeError, "index must be an integer"
     846                    raise TypeError("index must be an integer")
    848847                row = row_index
    849848                if row < 0:
    850849                    row += nrows
    851850                if row < 0 or row >= nrows:
    852                     raise IndexError, "matrix index out of range"
     851                    raise IndexError("matrix index out of range")
    853852                single_row = 1
    854853
    855854            if PyList_CheckExact(col_index) or PyTuple_CheckExact(col_index):
     
    865864                        col_list[i] = ind
    866865                       
    867866                    if ind < 0 or ind >= ncols:
    868                         raise IndexError, "matrix index out of range"
     867                        raise IndexError("matrix index out of range")
    869868            elif PySlice_Check(<PyObject *>col_index):
    870869                col_list =  range(*col_index.indices(ncols))
    871870            else:
    872871                if not PyIndex_Check(col_index):
    873                     raise TypeError, "index must be an integer"
     872                    raise TypeError("index must be an integer")
    874873                col = col_index
    875874                if col < 0:
    876875                    col += ncols
    877876                if col < 0 or col >= ncols:
    878                     raise IndexError, "matrix index out of range"
     877                    raise IndexError("matrix index out of range")
    879878                single_col = 1
    880879
    881880            # if we had a single row entry and a single column entry,
     
    910909                    row_list[i] = ind
    911910
    912911                if ind < 0 or ind >= nrows:
    913                     raise IndexError, "matrix index out of range"
     912                    raise IndexError("matrix index out of range")
    914913            r = self.matrix_from_rows(row_list)
    915914        elif PySlice_Check(<PyObject *>row_index):
    916915            row_list = range(*row_index.indices(nrows))
    917916            r = self.matrix_from_rows(row_list)
    918917        else:
    919918            if not PyIndex_Check(row_index):
    920                 raise TypeError, "index must be an integer"
     919                raise TypeError("index must be an integer")
    921920            row = row_index
    922921            if row < 0:
    923922                row += nrows
    924923            if row < 0 or row >= nrows:
    925                 raise IndexError, "matrix index out of range"
     924                raise IndexError("matrix index out of range")
    926925            r = self.row(row)
    927926
    928927        r.set_immutable()
     
    12851284            key_tuple = <tuple>key
    12861285            #if PyTuple_Size(key_tuple) != 2:
    12871286            if len(key_tuple) != 2:
    1288                 raise IndexError, "index can't have more than two components"
     1287                raise IndexError("index can't have more than two components")
    12891288
    12901289            row_index = <object>PyTuple_GET_ITEM(key_tuple, 0)
    12911290            col_index = <object>PyTuple_GET_ITEM(key_tuple, 1)
     
    12961295                if col < 0:
    12971296                    col += ncols
    12981297                if col < 0 or col >= ncols:
    1299                     raise IndexError, "index out of range"
     1298                    raise IndexError("index out of range")
    13001299                single_col = 1
    13011300                col_list_len = 1
    13021301            else:
     
    13181317            if row < 0:
    13191318                row += nrows
    13201319            if row < 0 or row >= nrows:
    1321                 raise IndexError, "index out of range"
     1320                raise IndexError("index out of range")
    13221321            single_row = 1
    13231322            row_list_len = 1
    13241323        else:
     
    13501349                value_list_one_dimensional = 1
    13511350                value_list = list(value)
    13521351            else:
    1353                 raise IndexError, "value does not have the right dimensions"
     1352                raise IndexError("value does not have the right dimensions")
    13541353        else:
    13551354            # If value is not a list, tuple, matrix, or vector, try
    13561355            # broadcasting the element to all positions.
     
    13791378        if value_list_one_dimensional:
    13801379            # This will break when assigning a vector to a column
    13811380            if single_row and col_list_len != len(value_list):
    1382                 raise IndexError, "value does not have the right number of columns"
     1381                raise IndexError("value does not have the right number of columns")
    13831382            elif single_col and row_list_len != len(value_list):
    1384                 raise IndexError, "value does not have the right number of rows"
     1383                raise IndexError("value does not have the right number of rows")
    13851384        else:
    13861385            if row_list_len != len(value_list):
    1387                 raise IndexError, "value does not have the right number of rows"
     1386                raise IndexError("value does not have the right number of rows")
    13881387            for value_row in value_list:
    13891388                if col_list_len != len(value_row):
    1390                     raise IndexError, "value does not have the right number of columns"
     1389                    raise IndexError("value does not have the right number of columns")
    13911390
    13921391
    13931392        if single_row:
     
    15071506            [2 4]
    15081507        """
    15091508        if not is_Ring(ring):
    1510             raise TypeError, "ring must be a ring"
     1509            raise TypeError("ring must be a ring")
    15111510       
    15121511        if ring is self._base_ring:
    15131512            if self._mutability._is_immutable:
     
    19091908        cdef Py_ssize_t i, j, n
    19101909
    19111910        if self._nrows != self._ncols:
    1912             raise ArithmeticError, "self must be a square matrix"
     1911            raise ArithmeticError("self must be a square matrix")
    19131912
    19141913        F = f.base_ring()
    19151914        vars = f.parent().gens()
     
    19781977    ###################################################
    19791978    cdef check_row_bounds_and_mutability(self, Py_ssize_t r1, Py_ssize_t r2):
    19801979        if self._mutability._is_immutable:
    1981             raise ValueError, "matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M)."
     1980            raise ValueError("matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).")
    19821981        else:
    19831982            self._cache = {}
    19841983        if r1<0 or r1 >= self._nrows or r2<0 or r2 >= self._nrows:
    1985             raise IndexError, "matrix row index out of range"   
     1984            raise IndexError("matrix row index out of range")
    19861985
    19871986    cdef check_column_bounds_and_mutability(self, Py_ssize_t c1, Py_ssize_t c2):       
    19881987        if self._mutability._is_immutable:
    1989             raise ValueError, "matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M)."
     1988            raise ValueError("matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).")
    19901989        else:
    19911990            self._cache = {}
    19921991        if c1<0 or c1 >= self._ncols or c2<0 or c2 >= self._ncols:
    1993             raise IndexError, "matrix column index out of range"   
     1992            raise IndexError("matrix column index out of range")
    19941993
    19951994    def swap_columns(self, Py_ssize_t c1, Py_ssize_t c2):
    19961995        """
     
    20912090            s = self._coerce_element(s)
    20922091            self.add_multiple_of_row_c(i, j, s, start_col)
    20932092        except TypeError:
    2094             raise TypeError, 'Multiplying row by %s element cannot be done over %s, use change_ring or with_added_multiple_of_row instead.' % (s.parent(), self.base_ring())
     2093            raise TypeError('Multiplying row by %s element cannot be done over %s, use change_ring or with_added_multiple_of_row instead.' % (s.parent(), self.base_ring()))
    20952094
    20962095    cdef add_multiple_of_row_c(self, Py_ssize_t i, Py_ssize_t j,    s,   Py_ssize_t start_col):
    20972096        cdef Py_ssize_t c
     
    21752174            s = self._coerce_element(s)
    21762175            self.add_multiple_of_column_c(i, j, s, start_row)
    21772176        except TypeError:
    2178             raise TypeError, 'Multiplying column by %s element cannot be done over %s, use change_ring or with_added_multiple_of_column instead.' % (s.parent(), self.base_ring())
     2177            raise TypeError('Multiplying column by %s element cannot be done over %s, use change_ring or with_added_multiple_of_column instead.' % (s.parent(), self.base_ring()))
    21792178
    21802179    cdef add_multiple_of_column_c(self, Py_ssize_t i, Py_ssize_t j, s, Py_ssize_t start_row):
    21812180        cdef Py_ssize_t r
     
    22892288            s = self._coerce_element(s)
    22902289            self.rescale_row_c(i, s, start_col)
    22912290        except TypeError:
    2292             raise TypeError, 'Rescaling row by %s element cannot be done over %s, use change_ring or with_rescaled_row instead.' % (s.parent(), self.base_ring())
     2291            raise TypeError('Rescaling row by %s element cannot be done over %s, use change_ring or with_rescaled_row instead.' % (s.parent(), self.base_ring()))
    22932292
    22942293    cdef rescale_row_c(self, Py_ssize_t i, s, Py_ssize_t start_col):
    22952294        cdef Py_ssize_t j
     
    24032402            s = self._coerce_element(s)
    24042403            self.rescale_col_c(i, s, start_row)
    24052404        except TypeError:
    2406             raise TypeError, 'Rescaling column by %s element cannot be done over %s, use change_ring or with_rescaled_col instead.' % (s.parent(), self.base_ring())
     2405            raise TypeError('Rescaling column by %s element cannot be done over %s, use change_ring or with_rescaled_col instead.' % (s.parent(), self.base_ring()))
    24072406
    24082407    cdef rescale_col_c(self, Py_ssize_t i, s, Py_ssize_t start_row):
    24092408        cdef Py_ssize_t j       
     
    24822481            for n from 0 <= n < self._ncols:
    24832482                self.set_unsafe(i, n, s * self.get_unsafe(j, n))  # self[i] = s*self[j]
    24842483        except TypeError:
    2485             raise TypeError, 'Multiplying row by %s element cannot be done over %s, use change_ring or with_row_set_to_multiple_of_row instead.' % (s.parent(), self.base_ring())
     2484            raise TypeError('Multiplying row by %s element cannot be done over %s, use change_ring or with_row_set_to_multiple_of_row instead.' % (s.parent(), self.base_ring()))
    24862485
    24872486    def with_row_set_to_multiple_of_row(self, Py_ssize_t i, Py_ssize_t j, s):
    24882487        """
     
    25622561        # If scaling factor cannot be coerced, change the base ring to
    25632562        # one acceptable to both the original base ring and the scaling factor.
    25642563        except TypeError:
    2565             raise TypeError, 'Multiplying column by %s element cannot be done over %s, use change_ring or with_col_set_to_multiple_of_col instead.' % (s.parent(), self.base_ring())
     2564            raise TypeError('Multiplying column by %s element cannot be done over %s, use change_ring or with_col_set_to_multiple_of_col instead.' % (s.parent(), self.base_ring()))
    25662565
    25672566    def with_col_set_to_multiple_of_col(self, Py_ssize_t i, Py_ssize_t j, s):
    25682567        """
     
    26452644        """
    26462645        self.check_row_bounds_and_mutability(i,i)
    26472646        if r < 0 or r >= A.nrows():
    2648             raise IndexError, "invalid row"
     2647            raise IndexError("invalid row")
    26492648        # this function exists just because it is useful for modular symbols presentations.
    26502649        cdef Py_ssize_t l
    26512650        l = 0
     
    26952694            ValueError: length of v must be at most the number of rows of self
    26962695        """
    26972696        if len(v) > self._nrows:
    2698             raise ValueError, "length of v must be at most the number of rows of self"
     2697            raise ValueError("length of v must be at most the number of rows of self")
    26992698        if self._nrows == 0:
    27002699            return self.parent().row_space().zero_vector()
    27012700        from constructor import matrix
     
    27412740            ValueError: length of v must be at most the number of columns of self
    27422741        """
    27432742        if len(v) > self._ncols:
    2744             raise ValueError, "length of v must be at most the number of columns of self"
     2743            raise ValueError("length of v must be at most the number of columns of self")
    27452744        if self._ncols == 0:
    27462745            return self.parent().column_space().zero_vector()
    27472746        from constructor import matrix
     
    29172916            print self
    29182917            print self.nrows()
    29192918            print self.dict()
    2920             raise RuntimeError, "BUG: matrix pivots should have been set but weren't, matrix parent = '%s'"%self.parent()
     2919            raise RuntimeError("BUG: matrix pivots should have been set but weren't, matrix parent = '%s'"%self.parent())
    29212920        return x
    29222921
    29232922    def rank(self):
     
    31023101        tmp = []
    31033102
    31043103        if i<0 or i >= self._ncols:
    3105             raise IndexError, "matrix column index out of range"
     3104            raise IndexError("matrix column index out of range")
    31063105        for j from 0 <= j < self._nrows:
    31073106            if self.get_unsafe(j,i) != z:
    31083107                tmp.append(j)
     
    31373136        cdef Py_ssize_t j
    31383137
    31393138        if i<0 or i >= self._nrows:
    3140             raise IndexError, "matrix row index out of range"
     3139            raise IndexError("matrix row index out of range")
    31413140
    31423141        z = self._base_ring(0)
    31433142        tmp = []
     
    31943193
    31953194        """
    31963195        if not self.is_invertible():
    3197             raise ArithmeticError,"self must be invertible to have a multiplicative order"
     3196            raise ArithmeticError("self must be invertible to have a multiplicative order")
    31983197        K = self.base_ring()
    31993198        if not (K.is_field() and K.is_finite()):
    3200             raise NotImplementedError,"multiplicative order is only implemented for matrices over finite fields"
     3199            raise NotImplementedError("multiplicative order is only implemented for matrices over finite fields")
    32013200        from sage.rings.integer import Integer
    32023201        from sage.groups.generic import order_from_multiple
    32033202        P = self.minimal_polynomial()
     
    32613260        """
    32623261        M = sage.modules.free_module.FreeModule(self._base_ring, self.ncols(), sparse=self.is_sparse())
    32633262        if self.nrows() != v.degree():
    3264             raise ArithmeticError, "number of rows of matrix must equal degree of vector"
     3263            raise ArithmeticError("number of rows of matrix must equal degree of vector")
    32653264        s = M(0)
    32663265        zero = self.base_ring()(0)
    32673266        cdef Py_ssize_t i
     
    32893288        if not PY_TYPE_CHECK(v, sage.modules.free_module_element.FreeModuleElement):
    32903289            v = M(v)
    32913290        if self.ncols() != v.degree():
    3292             raise ArithmeticError, "number of columns of matrix must equal degree of vector"
     3291            raise ArithmeticError("number of columns of matrix must equal degree of vector")
    32933292        s = M(0)
    32943293        for i in xrange(self.ncols()):
    32953294            if v[i] != 0:
     
    33013300        Let `A` be this matrix and `v` be a free module
    33023301        element. If rows is True, return a matrix whose rows are the
    33033302        entries of the following vectors:
    3304        
     3303
    33053304        .. math::
    3306        
    3307                        v, v A, v A^2, \ldots, v A^{n-1}.         
    3308        
    3309        
    3310        
     3305
     3306                       v, v A, v A^2, \ldots, v A^{n-1}.
     3307
    33113308        If rows is False, return a matrix whose columns are the entries of
    33123309        the following vectors:
    3313        
     3310
    33143311        .. math::
    3315        
    3316                        v, Av, A^2 v, \ldots, A^{n-1} v.         
    3317        
    3318        
    3319        
     3312
     3313                       v, Av, A^2 v, \ldots, A^{n-1} v.
     3314
    33203315        INPUT:
    3321        
    3322        
    3323         -  ``v`` - free module element
    3324        
    3325         -  ``n`` - nonnegative integer
    3326        
    3327        
     3316
     3317        - ``v`` - free module element
     3318       
     3319        - ``n`` - nonnegative integer
     3320
    33283321        EXAMPLES::
    3329        
     3322
    33303323            sage: A = matrix(ZZ,2, [1,1,3,5]); A
    33313324            [1 1]
    33323325            [3 5]
     
    33593352        """
    33603353        n = int(n)
    33613354        if n >= 2 and self.nrows() != self.ncols():
    3362             raise ArithmeticError, "matrix must be square if n >= 2."
     3355            raise ArithmeticError("matrix must be square if n >= 2.")
    33633356        if n == 0:
    33643357            return self.matrix_space(n, self.ncols())(0)
    33653358        m = self.nrows()
     
    38243817            sage: ~m
    38253818            Traceback (most recent call last):
    38263819            ...
    3827             ZeroDivisionError: self is not invertible
     3820            ZeroDivisionError: input matrix must be nonsingular
    38283821
    38293822        Check to make sure that trac #2256 is still fixed::
    38303823
     
    38463839                    try:
    38473840                        return (~self.lift()).change_ring(self.base_ring())
    38483841                    except (TypeError, ZeroDivisionError):
    3849                         raise ZeroDivisionError, "self is not invertible"
     3842                        raise ZeroDivisionError("input matrix must be nonsingular")
    38503843                raise
    38513844               
    38523845        if not self.is_square():
    3853             raise ArithmeticError, "self must be a square matrix"
     3846            raise ArithmeticError("self must be a square matrix")
    38543847        if self.nrows()==0:
    38553848            return self
    38563849
     
    38783871
    38793872        if self.base_ring().is_exact():
    38803873            if B[self._nrows-1, self._ncols-1] != 1:
    3881                 raise ZeroDivisionError, "self is not invertible"
     3874                raise ZeroDivisionError("input matrix must be nonsingular")
    38823875        else:
    38833876            if not B[self._nrows-1, self._ncols-1]:
    3884                 raise ZeroDivisionError, "self is not invertible"
     3877                raise ZeroDivisionError("input matrix must be nonsingular")
    38853878       
    38863879        return B.matrix_from_columns(range(self._ncols, 2*self._ncols))
    38873880
     
    39193912            [    -13/121   1436/1331 -8015/14641]
    39203913        """
    39213914        if not self.is_square():
    3922             raise ArithmeticError, "self must be a square matrix"
     3915            raise ArithmeticError("self must be a square matrix")
    39233916
    39243917        return RingElement.__pow__(self, n, ignored)
    39253918
  • sage/matrix/matrix_domain_dense.pyx

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix_domain_dense.pyx
    a b  
    106106            x0*x1^2 - x0^2*x1
    107107        """
    108108        if self.nrows() != self.ncols():
    109             raise ArithmeticError, "Matrix must be square, but is %sx%s"%(
    110                 self.nrows(), self.ncols())
     109            raise ArithmeticError("Matrix must be square, but is %sx%s"%(
     110                self.nrows(), self.ncols()))
    111111        # Use stupid slow but completely general method. 
    112112        d = (-1)**self.nrows() * self.charpoly('x')[0]
    113113        return self.base_ring()(d)
     
    206206        try:
    207207            self.base_ring()._singular_(singular)
    208208        except (NotImplementedError, AttributeError):
    209             raise TypeError, "Cannot coerce to Singular"
     209            raise TypeError("Cannot coerce to Singular")
    210210
    211211        return singular.matrix(self.nrows(),self.ncols(),singular(self.list()))
    212212
  • sage/matrix/matrix_double_dense.pyx

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix_double_dense.pyx
    a b  
    211211        dims[1] = self._ncols
    212212        if isinstance(entries,(tuple, list)):
    213213            if len(entries)!=self._nrows*self._ncols:
    214                     raise TypeError, "entries has wrong length"
     214                    raise TypeError("entries has wrong length")
    215215
    216216            if coerce:
    217217                for i from 0<=i<self._nrows:
     
    231231                try:
    232232                    z = self._python_dtype(entries)
    233233                except TypeError:
    234                     raise TypeError, "entries must be coercible to a list or float"
     234                    raise TypeError("entries must be coercible to a list or float")
    235235            if z != 0:
    236236                if self._nrows != self._ncols:
    237                     raise TypeError, "scalar matrix must be square"
     237                    raise TypeError("scalar matrix must be square")
    238238                for i from 0<=i<self._ncols:
    239239                    self.set_unsafe(i,i,z)
    240240
     
    384384            [128.0 152.0 176.0 200.0]
    385385        """
    386386        if self._ncols!=right._nrows:
    387             raise IndexError, "Number of columns of self must equal number of rows of right"
     387            raise IndexError("Number of columns of self must equal number of rows of right")
    388388       
    389389        if self._nrows == 0 or self._ncols == 0 or right._nrows == 0 or right._ncols == 0:
    390390            return self.matrix_space(self._nrows, right._ncols).zero_matrix()
     
    466466#            ZeroDivisionError: singular matrix
    467467#
    468468        if self._nrows != self._ncols:
    469             raise ArithmeticError, "self must be a square matrix"
     469            raise ArithmeticError("self must be a square matrix")
    470470        if self._nrows == 0 and self._ncols == 0:
    471471            return self.__copy__()
    472472
     
    481481        try: ##  Standard error reporting for Sage.
    482482            M._matrix_numpy = scipy.linalg.inv(self._matrix_numpy)
    483483        except LinAlgError:
    484             raise ZeroDivisionError, "singular matrix"
     484            raise ZeroDivisionError("input matrix must be nonsingular")
    485485        return M
    486486
    487487    def __copy__(self):
     
    585585        cdef Matrix_double_dense P, L, U
    586586   
    587587        if self._ncols!=self._nrows:
    588             raise TypeError,"LU decomposition only works for square matrix"
     588            raise TypeError("LU decomposition only works for square matrix")
    589589       
    590590        if self._ncols == 0:
    591591            return self.__copy__(), self.__copy__(), self.__copy__()
     
    665665        # For numerical values we leave decisions about
    666666        # multiplicity to the calling routine
    667667        if algebraic_multiplicity:
    668             raise ValueError, "algebraic_multiplicity must be set to False for double precision matrices"
     668            raise ValueError("algebraic_multiplicity must be set to False for double precision matrices")
    669669        spectrum = self.left_eigenvectors()
    670670        pairs = []
    671671        for evalue,evectors,_ in spectrum:
     
    734734        # For numerical values we leave decisions about
    735735        # multiplicity to the calling routine
    736736        if algebraic_multiplicity:
    737             raise ValueError, "algebraic_multiplicity must be set to False for double precision matrices"
     737            raise ValueError("algebraic_multiplicity must be set to False for double precision matrices")
    738738        spectrum = self.right_eigenvectors()
    739739        pairs = []
    740740        for evalue,evectors,_ in spectrum:
     
    769769            []
    770770        """
    771771        if not self.is_square():
    772             raise ArithmeticError, "self must be a square matrix"
     772            raise ArithmeticError("self must be a square matrix")
    773773        if self._nrows == 0:
    774774            return []
    775775        global scipy
     
    824824            (-1.0, [(1.0, 1.0, 2.0, 2.0)], 1)
    825825        """
    826826        if not self.is_square():
    827             raise ArithmeticError, "self must be a square matrix"
     827            raise ArithmeticError("self must be a square matrix")
    828828        if self._nrows == 0:
    829829            return [], self.__copy__()
    830830        global scipy
     
    884884            (-1.0, [(1.0, -0.5, 2.0, 0.5)], 1)
    885885        """
    886886        if not self.is_square():
    887             raise ArithmeticError, "self must be a square matrix"
     887            raise ArithmeticError("self must be a square matrix")
    888888        if self._nrows == 0:
    889889            return [], self.__copy__()
    890890        global scipy
     
    939939       
    940940        """
    941941        if self._nrows != b.degree():
    942             raise ValueError, "number of rows of self must equal degree of b"
     942            raise ValueError("number of rows of self must equal degree of b")
    943943        if self._nrows == 0 or self._ncols == 0:
    944944            return self._row_ambient_module().zero_vector()
    945945
    946         raise NotImplementedError, "this function is not finished (see trac 4932)"
     946        raise NotImplementedError("this function is not finished (see trac 4932)")
    947947        self._c_compute_LU()  # so self._L_M and self._U_M are defined below.
    948948        cdef Matrix_double_dense M = self._new()
    949949        lu = self._L_M*self._U_M
     
    10041004            ValueError: self must be a square matrix
    10051005        """
    10061006        if not self.is_square():
    1007             raise ValueError, "self must be a square matrix"
     1007            raise ValueError("self must be a square matrix")
    10081008        if self._nrows == 0 or self._ncols == 0:
    10091009            return self._sage_dtype(1)
    10101010        global scipy
     
    10541054            return sage.rings.real_double.RDF(0)
    10551055
    10561056        if not self.is_square():
    1057             raise ArithmeticError, "self must be a square matrix"
     1057            raise ArithmeticError("self must be a square matrix")
    10581058
    10591059        P, L, U = self.LU()
    10601060        if numpy is None:
     
    14571457            [3.0 4.0]
    14581458        """
    14591459        if (<object>self._matrix_numpy).shape != (<object>numpy_matrix).shape:
    1460             raise ValueError, "matrix shapes are not the same"
     1460            raise ValueError("matrix shapes are not the same")
    14611461        self._matrix_numpy = numpy_matrix.astype(self._numpy_dtype)
    14621462
    14631463
     
    15581558            [-32.3835771246 + 21.8842351994*I  2.26963458304 + 44.9013203415*I]
    15591559        """
    15601560        if algorithm not in ('pade', 'eig', 'taylor'):
    1561             raise ValueError, "algorithm must be 'pade', 'eig', or 'taylor'"
     1561            raise ValueError("algorithm must be 'pade', 'eig', or 'taylor'")
    15621562           
    15631563        if scipy is None:
    15641564            import scipy
  • sage/matrix/matrix_integer_2x2.pyx

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix_integer_2x2.pyx
    a b  
    156156                        entries = list(entries)
    157157                        is_list = 1
    158158                    except TypeError:
    159                         raise TypeError, "entries must be coercible to a list or the base ring"
     159                        raise TypeError("entries must be coercible to a list or the base ring")
    160160                   
    161161        else:
    162162            is_list = 1
     
    164164        if is_list:
    165165       
    166166            if len(entries) != self._nrows * self._ncols:
    167                 raise TypeError, "entries has the wrong length"
     167                raise TypeError("entries has the wrong length")
    168168       
    169169            if coerce:
    170170                mpz_set(self.a, (<Integer>ZZ(entries[0])).value)
     
    223223            mpz_set(self.c, (<Integer>ZZ(data[2])).value)
    224224            mpz_set(self.d, (<Integer>ZZ(data[3])).value)
    225225        else:
    226             raise RuntimeError, "unknown matrix version"
     226            raise RuntimeError("unknown matrix version")
    227227
    228228    def __richcmp__(matrix.Matrix self, right, int op):
    229229        """
     
    433433            return A
    434434           
    435435        else:
    436             raise ZeroDivisionError, "Not a unit!"
     436            raise ZeroDivisionError("Not a unit!")
    437437    _invert_unit = __invert__unit
    438438           
    439439    def _multiply_classical(left, matrix.Matrix _right):
  • sage/matrix/matrix_integer_dense.pyx

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix_integer_dense.pyx
    a b  
    214214        self._entries = <mpz_t *>sage_malloc(sizeof(mpz_t) * (self._nrows * self._ncols))
    215215        sig_off()
    216216        if self._entries == NULL:
    217             raise MemoryError, "out of memory allocating a matrix"
     217            raise MemoryError("out of memory allocating a matrix")
    218218
    219219        # Allocate an array of pointers to the rows, which is useful for
    220220        # certain algorithms.
     
    227227        if self._matrix == NULL:
    228228            sage_free(self._entries)
    229229            self._entries = NULL
    230             raise MemoryError, "out of memory allocating a matrix"
     230            raise MemoryError("out of memory allocating a matrix")
    231231
    232232        # Set each of the pointers in the array self._matrix to point
    233233        # at the memory for the corresponding row.
     
    392392                x = ZZ(entries)
    393393            except TypeError:
    394394                self._initialized = False
    395                 raise TypeError, "unable to coerce entry to an integer"
     395                raise TypeError("unable to coerce entry to an integer")
    396396            is_list = 0
    397397        else:
    398398            entries = list(entries)
     
    405405                sage_free(self._entries)
    406406                sage_free(self._matrix)
    407407                self._entries = NULL
    408                 raise TypeError, "entries has the wrong length"
     408                raise TypeError("entries has the wrong length")
    409409            if coerce:
    410410                for i from 0 <= i < self._nrows * self._ncols:
    411411                    x = ZZ(entries[i])
     
    429429                sage_free(self._entries)
    430430                sage_free(self._matrix)
    431431                self._entries = NULL
    432                 raise TypeError, "nonzero scalar matrix must be square"
     432                raise TypeError("nonzero scalar matrix must be square")
    433433           
    434434            # Now we set all the diagonal entries to x and all other entries to 0.
    435435            self._zero_out_matrix()
     
    578578        if version == 0:
    579579            self._unpickle_version0(data)
    580580        else:
    581             raise RuntimeError, "unknown matrix version (=%s)"%version
     581            raise RuntimeError("unknown matrix version (=%s)"%version)
    582582
    583583    cdef _unpickle_version0(self, data):
    584584        cdef Py_ssize_t i, n
    585585        data = data.split()
    586586        n = self._nrows * self._ncols
    587587        if len(data) != n:
    588             raise RuntimeError, "invalid pickle data."
     588            raise RuntimeError("invalid pickle data.")
    589589        for i from 0 <= i < n:
    590590            s = data[i]
    591591            if mpz_init_set_str(self._entries[i], s, 32):
    592                 raise RuntimeError, "invalid pickle data"
     592                raise RuntimeError("invalid pickle data")
    593593        self._initialized = True                               
    594594
    595595
     
    724724            [ 90 111 132]
    725725        """
    726726        if self._ncols != right._nrows:
    727             raise IndexError, "Number of columns of self must equal number of rows of right."
     727            raise IndexError("Number of columns of self must equal number of rows of right.")
    728728
    729729        cdef Py_ssize_t i, j, k, l, nr, nc, snc
    730730        cdef mpz_t *v
     
    10141014        elif algorithm == 'generic':
    10151015            g = matrix_dense.Matrix_dense.charpoly(self, var)
    10161016        else:
    1017             raise ValueError, "no algorithm '%s'"%algorithm
     1017            raise ValueError("no algorithm '%s'"%algorithm)
    10181018
    10191019        self.cache(key, g)
    10201020        return g
     
    10551055        elif algorithm == 'generic':
    10561056            g = matrix_dense.Matrix_dense.minpoly(self, var)
    10571057        else:
    1058             raise ValueError, "no algorithm '%s'"%algorithm
     1058            raise ValueError("no algorithm '%s'"%algorithm)
    10591059       
    10601060        self.cache(key, g)
    10611061        return g
     
    10801080        """
    10811081        time = verbose('computing %s of %s x %s matrix using linbox'%(typ, self._nrows, self._ncols))
    10821082        if self._nrows != self._ncols:
    1083             raise ArithmeticError, "self must be a square matrix"
     1083            raise ArithmeticError("self must be a square matrix")
    10841084        if self._nrows <= 1:
    10851085            return matrix_dense.Matrix_dense.charpoly(self, var)
    10861086        self._init_linbox()
     
    12601260        cdef mod_int **row_list
    12611261        row_list = <mod_int**>sage_malloc(sizeof(mod_int*) * n)
    12621262        if row_list == NULL:
    1263             raise MemoryError, "out of memory allocating multi-modular coefficient list"
     1263            raise MemoryError("out of memory allocating multi-modular coefficient list")
    12641264
    12651265        sig_on()
    12661266        for i from 0 <= i < nr:
     
    13141314            [2L, 10L, 11L, 1L]
    13151315        """
    13161316        if n > 67108879:   # doesn't work for bigger primes -- experimental observation
    1317             raise NotImplementedError, "modulus to big"
     1317            raise NotImplementedError("modulus to big")
    13181318        cdef mod_int** matrix = <mod_int**>sage_malloc(sizeof(mod_int*) * self._nrows)
    13191319        if matrix == NULL:
    1320             raise MemoryError, "out of memory allocating multi-modular coefficient list"
     1320            raise MemoryError("out of memory allocating multi-modular coefficient list")
    13211321       
    13221322        cdef Py_ssize_t i, j
    13231323        for i from 0 <= i < self._nrows:
    13241324            matrix[i] = <mod_int *>sage_malloc(sizeof(mod_int) * self._ncols)
    13251325            if matrix[i] == NULL:
    1326                 raise MemoryError, "out of memory allocating multi-modular coefficient list"
     1326                raise MemoryError("out of memory allocating multi-modular coefficient list")
    13271327            for j from 0 <= j < self._ncols:
    13281328                matrix[i][j] = mpz_fdiv_ui(self._matrix[i][j], n)
    13291329
     
    16771677           
    16781678        elif algorithm == 'pari0':
    16791679            if transformation:
    1680                 raise ValueError, "transformation matrix only available with p-adic algorithm"
     1680                raise ValueError("transformation matrix only available with p-adic algorithm")
    16811681            if pari_big:
    16821682                H_m = self._hnf_pari_big(0, include_zero_rows=include_zero_rows)
    16831683            else:
     
    16851685
    16861686        elif algorithm == 'pari':
    16871687            if transformation:
    1688                 raise ValueError, "transformation matrix only available with p-adic algorithm"
     1688                raise ValueError("transformation matrix only available with p-adic algorithm")
    16891689            if pari_big:
    16901690                H_m = self._hnf_pari_big(1, include_zero_rows=include_zero_rows)
    16911691            else:
     
    16931693
    16941694        elif algorithm == 'pari4':
    16951695            if transformation:
    1696                 raise ValueError, "transformation matrix only available with p-adic algorithm"
     1696                raise ValueError("transformation matrix only available with p-adic algorithm")
    16971697            if pari_big:
    16981698                H_m = self._hnf_pari_big(4, include_zero_rows=include_zero_rows)
    16991699            else:
     
    17011701           
    17021702        elif algorithm == 'ntl':
    17031703            if transformation:
    1704                 raise ValueError, "transformation matrix only available with p-adic algorithm"
     1704                raise ValueError("transformation matrix only available with p-adic algorithm")
    17051705
    17061706            if nr != nc:
    1707                 raise ValueError, "ntl only computes HNF for square matrices of full rank."
     1707                raise ValueError("ntl only computes HNF for square matrices of full rank.")
    17081708
    17091709            import sage.libs.ntl.ntl_mat_ZZ
    17101710            v =  sage.libs.ntl.ntl_mat_ZZ.ntl_mat_ZZ(self._nrows,self._ncols)
     
    17151715            try:
    17161716                w = v.HNF(D=D)
    17171717            except RuntimeError: # HNF may fail if a nxm matrix has rank < m
    1718                 raise ValueError, "ntl only computes HNF for square matrices of full rank."
     1718                raise ValueError("ntl only computes HNF for square matrices of full rank.")
    17191719
    17201720            rank = w.nrows()
    17211721           
     
    17321732                    H_m[i,j] = w[nr-i-1,nc-j-1]
    17331733
    17341734        else:
    1735             raise TypeError, "algorithm '%s' not understood"%(algorithm)
     1735            raise TypeError("algorithm '%s' not understood"%(algorithm))
    17361736           
    17371737        H_m.set_immutable()
    17381738        if pivots is None:
     
    20072007            d = []
    20082008        else:
    20092009            if algorithm == 'linbox':
    2010                 raise ValueError, "linbox too broken -- currently Linbox SNF is disabled."
     2010                raise ValueError("linbox too broken -- currently Linbox SNF is disabled.")
    20112011                # This fails in linbox: a = matrix(ZZ,2,[1, 1, -1, 0, 0, 0, 0, 1])
    20122012                try:
    20132013                    d = self._elementary_divisors_linbox()
     
    20222022                if i > 0:
    20232023                    d = d[i:] + [d[0]]*i
    20242024            elif not (algorithm in ['pari', 'linbox']):
    2025                 raise ValueError, "algorithm (='%s') unknown"%algorithm
     2025                raise ValueError("algorithm (='%s') unknown"%algorithm)
    20262026        self.cache('elementary_divisors', d)
    20272027        return d[:]
    20282028
     
    21872187        Sage polynomials.
    21882188        """
    21892189        if not self.is_square():
    2190             raise ArithmeticError, "frobenius matrix of non-square matrix not defined."
     2190            raise ArithmeticError("frobenius matrix of non-square matrix not defined.")
    21912191       
    21922192        v = self._pari_().matfrobenius(flag)
    21932193        if flag==0:
     
    23872387            else:
    23882388                return A
    23892389        else:
    2390             raise ValueError, "unknown algorithm '%s'"%algorithm
     2390            raise ValueError("unknown algorithm '%s'"%algorithm)
    23912391
    23922392    def right_kernel(self, algorithm='default', LLL=False, proof=None, echelonize=True):
    23932393        r"""
     
    25762576       
    25772577        """
    25782578        if self._nrows != self._ncols:
    2579             raise ArithmeticError, "self must be a square matrix"
     2579            raise ArithmeticError("self must be a square matrix")
    25802580   
    25812581        n = self.nrows()
    25822582        # maybe should be /unimodular/ matrices ?
     
    25842584        try:
    25852585            U = P.lllgramint()
    25862586        except (RuntimeError, ArithmeticError), msg:
    2587             raise ValueError, "not a definite matrix"
     2587            raise ValueError("not a definite matrix")
    25882588        MS = matrix_space.MatrixSpace(ZZ,n)
    25892589        U = MS(U.python())
    25902590        # Fix last column so that det = +1
     
    26642664        if delta is None:
    26652665            delta = 0.99
    26662666        elif delta <= 0.25:
    2667             raise TypeError, "delta must be > 0.25"
     2667            raise TypeError("delta must be > 0.25")
    26682668        elif delta > 1:
    2669             raise TypeError, "delta must be <= 1"
     2669            raise TypeError("delta must be <= 1")
    26702670        delta = float(delta)
    26712671
    26722672        if fp is None:
     
    26832683        elif fp == "rr":
    26842684            algorithm = "BKZ_RR"
    26852685        else:
    2686             raise TypeError, "fp parameter not understood."
     2686            raise TypeError("fp parameter not understood.")
    26872687
    26882688        block_size = int(block_size)
    26892689
    26902690        if prune < 0:
    2691             raise TypeError, "prune must be >= 0"
     2691            raise TypeError("prune must be >= 0")
    26922692        prune = int(prune)
    26932693       
    26942694        if get_verbose() >= 2:
     
    28752875                algorithn = 'NTL:LLL_RR'
    28762876        elif algorithm == 'fpLLL:heuristic':
    28772877            if fp == None:
    2878                 raise TypeError, "if 'fpLLL:heuristic' is chosen, a floating point number implementation must be chosen"
     2878                raise TypeError("if 'fpLLL:heuristic' is chosen, a floating point number implementation must be chosen")
    28792879            elif fp == 'fp':
    28802880                fp = 'double'
    28812881            elif fp == 'qd':
    2882                 raise TypeError, "fpLLL does not support quad doubles."
     2882                raise TypeError("fpLLL does not support quad doubles.")
    28832883            elif fp == 'xd':
    28842884                fp = 'dpe'
    28852885            elif fp == 'rr':
     
    28892889            if delta is None:
    28902890                delta = ZZ(3)/ZZ(4)
    28912891            elif delta <= ZZ(1)/ZZ(4):
    2892                 raise TypeError, "delta must be > 1/4"
     2892                raise TypeError("delta must be > 1/4")
    28932893            elif delta > 1:
    2894                 raise TypeError, "delta must be <= 1"
     2894                raise TypeError("delta must be <= 1")
    28952895            delta = QQ(delta)
    28962896            a = delta.numer()
    28972897            b = delta.denom()
     
    29002900            if delta is None:
    29012901                delta = 0.99
    29022902            elif delta <= 0.25:
    2903                 raise TypeError, "delta must be > 0.25"
     2903                raise TypeError("delta must be > 0.25")
    29042904            elif delta > 1:
    2905                 raise TypeError, "delta must be <= 1"
     2905                raise TypeError("delta must be <= 1")
    29062906            delta = float(delta)
    29072907
    29082908            if eta is None:
    29092909                eta = 0.501
    29102910            elif eta < 0.5:
    2911                 raise TypeError, "eta must be >= 0.5"
     2911                raise TypeError("eta must be >= 0.5")
    29122912
    29132913        if prec < 0:
    2914             raise TypeError, "precision prec must be >= 0"
     2914            raise TypeError("precision prec must be >= 0")
    29152915        int(prec)
    29162916
    29172917        if algorithm.startswith('NTL:'):
     
    29462946                else:
    29472947                    r = A.LLL_XD(delta, verbose=verb)
    29482948            else:
    2949                 raise TypeError, "algorithm %s not supported"%algorithm
     2949                raise TypeError("algorithm %s not supported"%algorithm)
    29502950
    29512951            r = ZZ(r)
    29522952
     
    29712971            elif algorithm == 'fpLLL:proved':
    29722972                A.proved(prec,eta,delta)
    29732973            else:
    2974                 raise TypeError, "algorithm %s not supported"%algorithm
     2974                raise TypeError("algorithm %s not supported"%algorithm)
    29752975            R = A._sage_()
    29762976        else:
    2977             raise TypeError, "algorithm %s not supported"%algorithm
     2977            raise TypeError("algorithm %s not supported"%algorithm)
    29782978
    29792979        verbose("LLL finished", tm)
    29802980        return R
     
    30103010            delta = ZZ(3)/ZZ(4)
    30113011           
    30123012        if delta <= ZZ(1)/ZZ(4):
    3013             raise TypeError, "delta must be > 1/4"
     3013            raise TypeError("delta must be > 1/4")
    30143014        elif delta > 1:
    3015             raise TypeError, "delta must be <= 1"
     3015            raise TypeError("delta must be <= 1")
    30163016
    30173017        if eta < 0.5:
    3018             raise TypeError, "eta must be >= 0.5"
     3018            raise TypeError("eta must be >= 0.5")
    30193019
    30203020        # this is pretty slow
    30213021        G, mu = self.gram_schmidt()
     
    30683068            mpz_set_si(s, 0)
    30693069            for c in cols:
    30703070                if c<0 or c >= self._ncols:
    3071                     raise IndexError, "matrix column index out of range"
     3071                    raise IndexError("matrix column index out of range")
    30723072                mpz_add(s, s, self._matrix[row][c])
    30733073            mpz_mul(pr, pr, s)
    30743074        cdef Integer z
     
    34113411        if not d is None:
    34123412            return d
    34133413        if not self.is_square():
    3414             raise ValueError, "self must be a square matrix"
     3414            raise ValueError("self must be a square matrix")
    34153415        n = self.nrows()
    34163416
    34173417        if n <= 3:
     
    34333433            return matrix_integer_dense_hnf.det_padic(self, proof=proof, stabilize=stabilize)
    34343434        elif algorithm == 'linbox':
    34353435            if proof:
    3436                 raise RuntimeError, "you must pass the proof=False option to the determinant command to use LinBox's det algorithm"
     3436                raise RuntimeError("you must pass the proof=False option to the determinant command to use LinBox's det algorithm")
    34373437            d = self._det_linbox()
    34383438        elif algorithm == 'pari':
    34393439            d = self._det_pari()
    34403440        elif algorithm == 'ntl':
    34413441            d = self._det_ntl()
    34423442        else:
    3443             raise TypeError, "algorithm '%s' not known"%(algorithm)
     3443            raise TypeError("algorithm '%s' not known"%(algorithm))
    34443444       
    34453445        self.cache('det', d)
    34463446        return d
     
    35633563        - William Stein
    35643564        """
    35653565        if self._nrows != self._ncols:
    3566             raise TypeError, "self must be a square matrix."
     3566            raise TypeError("self must be a square matrix.")
    35673567       
    35683568        P = self.parent()
    35693569        time = verbose('computing inverse of %s x %s matrix using IML'%(self._nrows, self._ncols))
     
    35723572            K = A._rational_kernel_iml()
    35733573            d = -K[self._nrows,0]
    35743574            if K.ncols() != self._ncols or d == 0:
    3575                 raise ZeroDivisionError, "input matrix must be nonsingular"
     3575                raise ZeroDivisionError("input matrix must be nonsingular")
    35763576            B = K[:self._nrows]
    35773577            verbose("finished computing inverse using IML", time)
    35783578            return B, d
    35793579        else:
    35803580            if check_invertible and self.rank() != self._nrows:
    3581                 raise ZeroDivisionError, "input matrix must be nonsingular"
     3581                raise ZeroDivisionError("input matrix must be nonsingular")
    35823582            return self._solve_iml(P.identity_matrix(), right=True)
    35833583
    35843584    def _solve_right_nonsingular_square(self, B, check_rank=True):
     
    36753675        # in the non-full rank case.  In any case, we do this for now,
    36763676        # since rank is very fast and infinite loops are evil.
    36773677        if check_rank and self.rank() < self.nrows():
    3678             raise ValueError, "self must be of full rank."
     3678            raise ValueError("self must be of full rank.")
    36793679
    36803680        if not self.is_square():
    3681             raise NotImplementedError, "the input matrix must be square."
     3681            raise NotImplementedError("the input matrix must be square.")
    36823682
    36833683        if is_Vector(B):
    36843684            if self.nrows() != B.degree():
    3685                 raise ValueError, "number of rows of self must equal degree of B."
     3685                raise ValueError("number of rows of self must equal degree of B.")
    36863686        elif self.nrows() != B.nrows():
    3687                 raise ValueError, "number of rows of self must equal number of rows of B."
     3687                raise ValueError("number of rows of self must equal number of rows of B.")
    36883688
    36893689        if self.nrows() == 0:
    36903690            return B
     
    37803780           
    37813781        if self._nrows != self._ncols:
    37823782            # This is *required* by the IML function we call below.
    3783             raise ArithmeticError, "self must be a square matrix"
     3783            raise ArithmeticError("self must be a square matrix")
    37843784
    37853785        if self.nrows() == 1:
    37863786            return B, self[0,0]
     
    37883788
    37893789        if right:
    37903790            if self._ncols != B._nrows:
    3791                 raise ArithmeticError, "B's number of rows must match self's number of columns"
     3791                raise ArithmeticError("B's number of rows must match self's number of columns")
    37923792
    37933793            n = self._ncols
    37943794            m = B._ncols
     
    38083808
    38093809        else: # left
    38103810            if self._nrows != B._ncols:
    3811                 raise ArithmeticError, "B's number of columns must match self's number of rows"
     3811                raise ArithmeticError("B's number of columns must match self's number of rows")
    38123812
    38133813            n = self._ncols
    38143814            m = B._nrows
     
    39703970                else:
    39713971                    i += 1
    39723972                    if i == 50:
    3973                         raise RuntimeError, "Bug in _rational_echelon_via_solve in finding linearly independent rows."
     3973                        raise RuntimeError("Bug in _rational_echelon_via_solve in finding linearly independent rows.")
    39743974
    39753975        _i = 0
    39763976        while True:
    39773977            _i += 1
    39783978            if _i == 50:
    3979                 raise RuntimeError, "Bug in _rational_echelon_via_solve -- pivot columns keep being wrong."
     3979                raise RuntimeError("Bug in _rational_echelon_via_solve -- pivot columns keep being wrong.")
    39803980           
    39813981            # Step 4: Now we instead worry about computing the reduced row echelon form of B.
    39823982            i = 0
     
    39883988                else:
    39893989                    i += 1
    39903990                    if i == 50:
    3991                         raise RuntimeError, "Bug in _rational_echelon_via_solve in finding pivot columns."
     3991                        raise RuntimeError("Bug in _rational_echelon_via_solve in finding pivot columns.")
    39923992
    39933993            # Step 5: Apply p-adic solver
    39943994            C = B.matrix_from_columns(pivots)
     
    41644164            # no bounds checking!
    41654165            a = A[i,p]
    41664166            if not a:
    4167                 raise ZeroDivisionError, "claimed pivot is not a pivot"
     4167                raise ZeroDivisionError("claimed pivot is not a pivot")
    41684168            if b % a == 0:
    41694169                # (b) Subtract a multiple of row i from row n.
    41704170                c = b // a
     
    41794179                # position.
    41804180                g, s, t = a.xgcd(b)
    41814181                if not g:
    4182                     raise ZeroDivisionError, "claimed pivot is not a pivot (got a 0 gcd)"
     4182                    raise ZeroDivisionError("claimed pivot is not a pivot (got a 0 gcd)")
    41834183
    41844184                row_i = A.row(i)
    41854185                row_n = A.row(n)
     
    42284228        try:
    42294229            _clear_columns(A, new_pivots, A.nrows())
    42304230        except RuntimeError:
    4231             raise ZeroDivisionError, "mistake in claimed pivots"
     4231            raise ZeroDivisionError("mistake in claimed pivots")
    42324232        if A.row(A.nrows() - 1) == 0:
    42334233            A = A.matrix_from_rows(range(A.nrows()-1))
    42344234        return A, new_pivots
     
    42944294        # allocate memory for result matrix
    42954295        res = <long long*> sage_malloc(sizeof(long long)*ncols*nrows)
    42964296        if res == NULL:
    4297             raise MemoryError, "out of memory allocating a matrix"
     4297            raise MemoryError("out of memory allocating a matrix")
    42984298        res_rows = <long long**> sage_malloc(sizeof(long long*)*nrows)
    42994299        if res_rows == NULL:
    43004300            sage_free(res)
    4301             raise MemoryError, "out of memory allocating a matrix"
     4301            raise MemoryError("out of memory allocating a matrix")
    43024302
    43034303        # allocate memory for temporary matrix
    43044304        T_ent = <long long*> sage_malloc(sizeof(long long)*ncols*nrows)
    43054305        if T_ent == NULL:
    43064306            sage_free(res)
    43074307            sage_free(res_rows)
    4308             raise MemoryError, "out of memory allocating a matrix"
     4308            raise MemoryError("out of memory allocating a matrix")
    43094309        T_rows = <long long**> sage_malloc(sizeof(long long*)*nrows)
    43104310        if T_rows == NULL:
    43114311            sage_free(res)
    43124312            sage_free(res_rows)
    43134313            sage_free(T_ent)
    4314             raise MemoryError, "out of memory allocating a matrix"
     4314            raise MemoryError("out of memory allocating a matrix")
    43154315
    43164316        # allocate memory for temporary row vector
    43174317        B = <long long*>sage_malloc(sizeof(long long)*nrows)
     
    43204320            sage_free(res_rows)
    43214321            sage_free(T_ent)
    43224322            sage_free(T_rows)
    4323             raise MemoryError, "out of memory allocating a matrix"
     4323            raise MemoryError("out of memory allocating a matrix")
    43244324
    43254325        # initialize the row pointers
    43264326        k = 0
     
    44204420            [10 11 12]
    44214421        """
    44224422        if self._ncols != other.ncols():
    4423             raise TypeError, "number of columns must be the same"
     4423            raise TypeError("number of columns must be the same")
    44244424        if not (self._base_ring is other.base_ring()):
    44254425            other = other.change_ring(self._base_ring)
    44264426        cdef Matrix_integer_dense A = other
     
    44394439        Create a new matrix from self with.
    44404440       
    44414441        INPUT:
    4442        
    4443        
    4444         -  ``index`` - integer
    4445        
    4446         -  ``row`` - a vector
    4447        
    4448        
     4442
     4443        - ``index`` - integer
     4444       
     4445        - ``row`` - a vector
     4446
    44494447        EXAMPLES::
    4450        
     4448
    44514449            sage: X = matrix(ZZ,3,range(9)); X
    44524450            [0 1 2]
    44534451            [3 4 5]
     
    44724470        cdef Py_ssize_t j, k
    44734471        cdef Integer z
    44744472        if index < 0:
    4475             raise ValueError, "index must be nonnegative"
     4473            raise ValueError("index must be nonnegative")
    44764474        if index > self._nrows:
    4477             raise ValueError, "index must be less than number of rows"
     4475            raise ValueError("index must be less than number of rows")
    44784476        for j from 0 <= j < self._ncols * index:
    44794477            mpz_init_set(res._entries[j], self._entries[j])
    44804478
     
    45204518        the columns with positions specified in cols are all 0.
    45214519       
    45224520        INPUT:
    4523        
    4524        
     4521
    45254522        -  ``cols`` - list of nonnegative integers
    4526        
    4527        
     4523
    45284524        OUTPUT: matrix
    45294525       
    45304526        EXAMPLES::
     
    50355031        moduli = MultiModularBasis([m.base_ring().order() for m in residues])
    50365032    else:
    50375033        if len(residues) != len(moduli):
    5038             raise IndexError, "Number of residues (%s) does not match number of moduli (%s)"%(len(residues), len(moduli))
     5034            raise IndexError("Number of residues (%s) does not match number of moduli (%s)"%(len(residues), len(moduli)))
    50395035           
    50405036    cdef MultiModularBasis mm
    50415037    mm = moduli
    50425038   
    50435039    for b in residues:
    50445040        if not PY_TYPE_CHECK(b, Matrix_modn_dense):
    5045             raise TypeError, "Can only perform CRT on list of type Matrix_modn_dense."
     5041            raise TypeError("Can only perform CRT on list of type Matrix_modn_dense.")
    50465042
    50475043    cdef mod_int **row_list
    50485044    row_list = <mod_int**>sage_malloc(sizeof(mod_int*) * n)
    50495045    if row_list == NULL:
    5050         raise MemoryError, "out of memory allocating multi-modular coefficient list"
     5046        raise MemoryError("out of memory allocating multi-modular coefficient list")
    50515047   
    50525048    sig_on()
    50535049    for i from 0 <= i < nr:
     
    50705066    Compare various multiplication algorithms.
    50715067   
    50725068    INPUT:
    5073    
    5074    
    5075     -  ``k`` - integer; affects numbers of trials
    5076    
    5077     -  ``nmin`` - integer; smallest matrix to use
    5078    
    5079     -  ``nmax`` - integer; largest matrix to use
    5080    
    5081     -  ``bitmin`` - integer; smallest bitsize
    5082    
    5083     -  ``bitmax`` - integer; largest bitsize
    5084    
    5085    
     5069
     5070    - ``k`` - integer; affects numbers of trials
     5071
     5072    - ``nmin`` - integer; smallest matrix to use
     5073
     5074    - ``nmax`` - integer; largest matrix to use
     5075
     5076    - ``bitmin`` - integer; smallest bitsize
     5077
     5078    - ``bitmax`` - integer; largest bitsize
     5079
    50865080    OUTPUT:
    5087    
    5088    
     5081
    50895082    -  ``prints what doing then who wins`` - multimodular
    50905083       or classical
    5091    
    5092    
     5084
    50935085    EXAMPLES::
    50945086   
    50955087        sage: from sage.matrix.matrix_integer_dense import tune_multiplication
  • sage/matrix/matrix_integer_dense_hnf.py

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix_integer_dense_hnf.py
    a b  
    195195        -3669
    196196    """
    197197    if not A.is_square():
    198         raise ValueError, "A must be a square matrix"
     198        raise ValueError("A must be a square matrix")
    199199    r = A.rank()
    200200    if r < A.nrows():
    201201        return ZZ(0)
     
    512512    n = A.nrows()
    513513    m = A.ncols()
    514514    if n != m:
    515         raise ValueError, "A must be square."
     515        raise ValueError("A must be square.")
    516516
    517517    # Small cases -- don't use this algorithm
    518518    if n <= 3:
    519519        return A.echelon_form(algorithm="pari")
    520520
    521521    if A.rank() < A.nrows():
    522         raise ValueError, "matrix must have full rank"
     522        raise ValueError("matrix must have full rank")
    523523                           
    524524   
    525525
     
    566566            # weird cases where the det is large.
    567567            # E.g., matrix all of whose rows but 1 are multiplied by some
    568568            # fixed scalar n.
    569             raise NotImplementedError, "fallback to PARI!"
     569            raise NotImplementedError("fallback to PARI!")
    570570            #H = W.hermite_form(algorithm='pari')
    571571    else:
    572572        H = W._hnf_mod(2*g)
  • sage/matrix/matrix_integer_sparse.pyx

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix_integer_sparse.pyx
    a b  
    5858       
    5959        self._matrix = <mpz_vector*> sage_malloc(parent.nrows()*sizeof(mpz_vector))
    6060        if self._matrix == NULL:
    61             raise MemoryError, "error allocating sparse matrix"
     61            raise MemoryError("error allocating sparse matrix")
    6262
    6363        # initialize the rows
    6464        for i from 0 <= i < parent.nrows():
     
    9999                if z != 0:
    100100                    i, j = ij  # nothing better to do since this is user input, which may be bogus.
    101101                    if i < 0 or j < 0 or i >= self._nrows or j >= self._ncols:
    102                         raise IndexError, "invalid entries list"
     102                        raise IndexError("invalid entries list")
    103103                    mpz_vector_set_entry(&self._matrix[i], j, z.value)
    104104                   
    105105        elif isinstance(entries, list):
    106106           
    107107            # Dense input format -- fill in entries
    108108            if len(entries) != self._nrows * self._ncols:
    109                 raise TypeError, "list of entries must be a dictionary of (i,j):x or a dense list of n * m elements"
     109                raise TypeError("list of entries must be a dictionary of (i,j):x or a dense list of n * m elements")
    110110            seq = PySequence_Fast(entries,"expected a list")
    111111            X = PySequence_Fast_ITEMS(seq)
    112112            k = 0
     
    126126            if z == 0:
    127127                return
    128128            if self._nrows != self._ncols:
    129                 raise TypeError, "matrix must be square to initialize with a scalar."
     129                raise TypeError("matrix must be square to initialize with a scalar.")
    130130            for i from 0 <= i < self._nrows:
    131131                mpz_vector_set_entry(&self._matrix[i], i, z.value)
    132132           
  • sage/matrix/matrix_mod2_dense.pyx

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix_mod2_dense.pyx
    a b  
    249249
    250250        # all entries are given as a long list
    251251        if len(entries) != self._nrows * self._ncols:
    252             raise IndexError, "The vector of entries has the wrong length."
     252            raise IndexError("The vector of entries has the wrong length.")
    253253       
    254254        k = 0
    255255
     
    333333           
    334334        """
    335335        if not self._mutability._is_immutable:
    336             raise TypeError, "mutable matrices are unhashable"
     336            raise TypeError("mutable matrices are unhashable")
    337337           
    338338        x = self.fetch('hash')
    339339        if not x is None:
     
    725725                     2006.
    726726        """
    727727        if self._ncols != right._nrows:
    728             raise ArithmeticError, "left ncols must match right nrows"
     728            raise ArithmeticError("left ncols must match right nrows")
    729729
    730730        if get_verbose() >= 2:
    731731            verbose('m4rm multiply of %s x %s matrix by %s x %s matrix'%(
     
    867867                   multiplication algorithm. arXiv:0707.2347v1, 2008.
    868868        """
    869869        if self._ncols != right._nrows:
    870             raise ArithmeticError, "left ncols must match right nrows"
     870            raise ArithmeticError("left ncols must match right nrows")
    871871
    872872        cdef Matrix_mod2_dense ans
    873873        ans = self.new_matrix(nrows = self.nrows(), ncols = right.ncols())
     
    922922        cdef Matrix_mod2_dense A
    923923
    924924        if self._nrows != self._ncols:
    925             raise ArithmeticError, "self must be a square matrix"
     925            raise ArithmeticError("self must be a square matrix")
    926926
    927927        if self._ncols == 0:
    928928            return self.__copy__()
     
    937937        mzd_free(I)
    938938
    939939        if A._entries==NULL:
    940             raise ZeroDivisionError, "self is not invertible"
     940            raise ZeroDivisionError("input matrix must be nonsingular")
    941941        else:
    942942            return A
    943943
     
    10921092                k = int(kwds['k'])
    10931093
    10941094                if k<1 or k>16:
    1095                     raise RuntimeError,"k must be between 1 and 16"
     1095                    raise RuntimeError("k must be between 1 and 16")
    10961096                k = round(k)
    10971097            else:
    10981098                k = 0
     
    11291129            # for debugging purposes only, it is slow
    11301130            self._echelon_in_place_classical()
    11311131        else:
    1132             raise ValueError, "no algorithm '%s'"%algorithm
     1132            raise ValueError("no algorithm '%s'"%algorithm)
    11331133
    11341134    def _pivots(self):
    11351135        """
     
    11501150            [1, 2, 3, 4]
    11511151        """
    11521152        if not self.fetch('in_echelon_form'):
    1153             raise RuntimeError, "self must be in reduced row echelon form first."
     1153            raise RuntimeError("self must be in reduced row echelon form first.")
    11541154        pivots = []
    11551155        cdef Py_ssize_t i, j, nc
    11561156        nc = self._ncols
     
    13891389            0
    13901390        """
    13911391        if not self.is_square():
    1392             raise ValueError, "self must be a square matrix"
     1392            raise ValueError("self must be a square matrix")
    13931393        return self.base_ring()(1 if self.rank() == self.nrows() else 0)
    13941394
    13951395    def transpose(self):
     
    14851485        cdef Matrix_mod2_dense A
    14861486
    14871487        if self._nrows != right._nrows:
    1488             raise TypeError, "Both numbers of rows must match."
     1488            raise TypeError("Both numbers of rows must match.")
    14891489
    14901490        if self._ncols == 0:
    14911491            return right.__copy__()
     
    15421542            []
    15431543        """
    15441544        if self._ncols != other._ncols:
    1545             raise TypeError, "Both numbers of columns must match."
     1545            raise TypeError("Both numbers of columns must match.")
    15461546
    15471547        if self._nrows == 0:
    15481548            return other.__copy__()
     
    15921592        highc = lowc + ncols
    15931593
    15941594        if nrows <= 0 or ncols <= 0:
    1595             raise TypeError, "Expected nrows, ncols to be > 0, but got %d,%d instead."%(nrows, ncols)
     1595            raise TypeError("Expected nrows, ncols to be > 0, but got %d,%d instead."%(nrows, ncols))
    15961596 
    15971597        if highc > self._entries.ncols:
    1598             raise TypeError, "Expected highc <= self.ncols(), but got %d > %d instead."%(highc, self._entries.ncols)
     1598            raise TypeError("Expected highc <= self.ncols(), but got %d > %d instead."%(highc, self._entries.ncols))
    15991599
    16001600        if highr > self._entries.nrows:
    1601             raise TypeError, "Expected highr <= self.nrows(), but got %d > %d instead."%(highr, self._entries.nrows)
     1601            raise TypeError("Expected highr <= self.nrows(), but got %d > %d instead."%(highr, self._entries.nrows))
    16021602
    16031603        if lowr < 0:
    1604             raise TypeError, "Expected lowr >= 0, but got %d instead."%lowr
     1604            raise TypeError("Expected lowr >= 0, but got %d instead."%lowr)
    16051605
    16061606        if lowc < 0:
    1607             raise TypeError, "Expected lowc >= 0, but got %d instead."%lowc
     1607            raise TypeError("Expected lowc >= 0, but got %d instead."%lowc)
    16081608
    16091609        A = self.new_matrix(nrows = nrows, ncols = ncols)
    16101610        if self._ncols == 0 or self._nrows == 0:
     
    19291929    sage_free(buf)
    19301930       
    19311931    if gdImageSX(im) != c or gdImageSY(im) != r:
    1932         raise TypeError, "Pickled data dimension doesn't match."
     1932        raise TypeError("Pickled data dimension doesn't match.")
    19331933
    19341934
    19351935    for i from 0 <= i < r:
     
    20042004    cdef int i,j, r,c
    20052005    r, c = A.nrows(), A.ncols()
    20062006    if r == 0 or c == 0:
    2007         raise TypeError, "Cannot write image with dimensions %d x %d"%(c,r)
     2007        raise TypeError("Cannot write image with dimensions %d x %d"%(c,r))
    20082008    fn = open(filename,"w") # check filename
    20092009    fn.close()
    20102010    cdef gdImagePtr im = gdImageCreate(c, r)
  • sage/matrix/matrix_rational_dense.pyx

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix_rational_dense.pyx
    a b  
    146146        self._entries = <mpq_t *> sage_malloc(sizeof(mpq_t)*(self._nrows * self._ncols))
    147147        sig_off()
    148148        if self._entries == NULL:
    149             raise MemoryError, "out of memory allocating a matrix"
     149            raise MemoryError("out of memory allocating a matrix")
    150150
    151151        self._matrix =  <mpq_t **> sage_malloc(sizeof(mpq_t*) * self._nrows)
    152152        if self._matrix == NULL:
    153153            sage_free(self._entries)
    154154            self._entries = NULL
    155             raise MemoryError, "out of memory allocating a matrix"
     155            raise MemoryError("out of memory allocating a matrix")
    156156
    157157        # store pointers to the starts of the rows
    158158        sig_on()
     
    181181
    182182        if isinstance(entries, (list, tuple)):
    183183            if len(entries) != self._nrows * self._ncols:
    184                 raise TypeError, "entries has the wrong length"
     184                raise TypeError("entries has the wrong length")
    185185
    186186            sig_on()
    187187            if coerce:
     
    202202                z = Rational(entries)
    203203                is_list = False
    204204            except TypeError:
    205                 raise TypeError, "entries must be coercible to a list or integer"
     205                raise TypeError("entries must be coercible to a list or integer")
    206206
    207207            if not z.is_zero():
    208208                if self._nrows != self._ncols:
    209                     raise TypeError, "nonzero scalar matrix must be square"
     209                    raise TypeError("nonzero scalar matrix must be square")
    210210                for i from 0 <= i < self._nrows:
    211211                    mpq_set(self._entries[i*self._ncols+i], z.value)
    212212
     
    242242        if version == 0:
    243243            self._unpickle_version0(data)
    244244        else:
    245             raise RuntimeError, "unknown matrix version (=%s)"%version
     245            raise RuntimeError("unknown matrix version (=%s)"%version)
    246246       
    247247    cdef _pickle_version0(self):
    248248        return self._export_as_string(32)
     
    305305        data = data.split()
    306306        n = self._nrows * self._ncols
    307307        if len(data) != n:
    308             raise RuntimeError, "invalid pickle data."
     308            raise RuntimeError("invalid pickle data.")
    309309        for i from 0 <= i < n:
    310310            s = data[i]
    311311            if mpq_set_str(self._entries[i], s, 32):
    312                 raise RuntimeError, "invalid pickle data"
     312                raise RuntimeError("invalid pickle data")
    313313       
    314314    def __richcmp__(Matrix self, right, int op):
    315315        return self._richcmp(right, op)
     
    545545            [   6 37/5 44/5]
    546546        """
    547547        if self._ncols != right._nrows:
    548             raise IndexError, "Number of columns of self must equal number of rows of right."
     548            raise IndexError("Number of columns of self must equal number of rows of right.")
    549549
    550550        cdef Py_ssize_t i, j, k, l, nr, nc, snc
    551551        cdef mpq_t *v
     
    709709        cdef int i
    710710       
    711711        if self._nrows != self._ncols:
    712             raise ArithmeticError, "self must be a square matrix"
     712            raise ArithmeticError("self must be a square matrix")
    713713        if self._nrows == 0:
    714714            return self
    715715        if self._nrows <= 2:
    716716            A = Matrix_rational_dense.__new__(Matrix_rational_dense, self._parent, None, None, None)
    717717            if self._nrows == 1:
    718718                if mpq_cmp_si(self._entries[0], 0, 1) == 0:
    719                     raise ZeroDivisionError
     719                    raise ZeroDivisionError("input matrix must be nonsingular" )
    720720                sig_on()
    721721                mpq_inv(A._entries[0], self._entries[0])
    722722                sig_off()
     
    731731                sig_off()
    732732                if i == 0:
    733733                    mpq_clear(det); mpq_clear(t1)
    734                     raise ZeroDivisionError
     734                    raise ZeroDivisionError("input matrix must be nonsingular" )
    735735                sig_on()
    736736                # d/det
    737737                mpq_div(A._entries[0], self._entries[3], det)   
     
    760760            B, d = AZ._invert_iml(check_invertible=check_invertible)
    761761            return (denom/d)*B
    762762        else:
    763             raise ValueError, "unknown algorithm '%s'"%algorithm
     763            raise ValueError("unknown algorithm '%s'"%algorithm)
    764764       
    765765    def determinant(self, algorithm="default", proof=None):
    766766        """
     
    816816            if denom != 1:
    817817                det = det / (denom**self.nrows())
    818818        else:
    819             raise ValueError, "unknown algorithm '%s'"%algorithm
     819            raise ValueError("unknown algorithm '%s'"%algorithm)
    820820               
    821821        self.cache('det', det)
    822822        return det
     
    939939        elif algorithm == 'generic':
    940940            g = matrix_dense.Matrix_dense.charpoly(self, var)
    941941        else:
    942             raise ValueError, "no algorithm '%s'"%algorithm
     942            raise ValueError("no algorithm '%s'"%algorithm)
    943943
    944944        self.cache(key, g)
    945945        return g
     
    998998        elif algorithm == 'generic':
    999999            g = matrix_dense.Matrix_dense.minpoly(self, var)
    10001000        else:
    1001             raise ValueError, "no algorithm '%s'"%algorithm
     1001            raise ValueError("no algorithm '%s'"%algorithm)
    10021002
    10031003        self.cache(key, g)
    10041004        return g
     
    10751075        elif algorithm == 'multimodular':
    10761076            AB = A._multiply_multi_modular(B)
    10771077        else:
    1078             raise ValueError, "unknown algorithm '%s'"%algorithm
     1078            raise ValueError("unknown algorithm '%s'"%algorithm)
    10791079        D = A_denom * B_denom
    10801080        if self._nrows == right._nrows:
    10811081            # self acts on the space of right
     
    11961196            mpq_set_si(s, 0, 1)
    11971197            for c in cols:
    11981198                if c<0 or c >= self._ncols:
    1199                     raise IndexError, "matrix column index out of range"
     1199                    raise IndexError("matrix column index out of range")
    12001200                mpq_add(s, s, self._matrix[row][c])
    12011201            mpq_mul(pr, pr, s)
    12021202        cdef Rational _pr
     
    13081308            [0|1 2]
    13091309        """
    13101310        if not is_Ring(R):
    1311             raise TypeError, "R must be a ring"
     1311            raise TypeError("R must be a ring")
    13121312        from matrix_modn_dense import MAX_MODULUS
    13131313        if R == self._base_ring:
    13141314            if self._mutability._is_immutable:
     
    13171317        elif is_IntegerRing(R):
    13181318            A, d = self._clear_denom()
    13191319            if d != 1:
    1320                 raise TypeError, "matrix has denominators so can't change to ZZ."
     1320                raise TypeError("matrix has denominators so can't change to ZZ.")
    13211321            A.subdivide(self.get_subdivisions())
    13221322            return A
    13231323        elif is_IntegerModRing(R) and R.order() < MAX_MODULUS:
    13241324            b = R.order()
    13251325            A, d = self._clear_denom()
    13261326            if gcd(b,d) != 1:
    1327                 raise TypeError, "matrix denominator not coprime to modulus"
     1327                raise TypeError("matrix denominator not coprime to modulus")
    13281328            B = A._mod_int(b)
    13291329            C = (1/(B.base_ring()(d))) * B
    13301330            C.subdivide(self.get_subdivisions())
     
    14141414        elif algorithm == 'multimodular':
    14151415            pivots = self._echelonize_multimodular(height_guess, proof, **kwds)
    14161416        else:
    1417             raise ValueError, "no algorithm '%s'"%algorithm
     1417            raise ValueError("no algorithm '%s'"%algorithm)
    14181418        self.cache('in_echelon_form', True)
    14191419
    1420         if pivots is None: raise RuntimeError, "BUG: pivots must get set"
     1420        if pivots is None:
     1421            raise RuntimeError("BUG: pivots must get set")
    14211422        self.cache('pivots', pivots)
    14221423       
    14231424
     
    14841485        elif algorithm == 'multimodular':
    14851486            E = self._echelon_form_multimodular(height_guess, proof=proof)
    14861487        else:
    1487             raise ValueError, "no algorithm '%s'"%algorithm
     1488            raise ValueError("no algorithm '%s'"%algorithm)
    14881489        self.cache(label, E)
    14891490        self.cache('pivots', E.pivots())
    14901491        return E
     
    18381839        cdef Py_ssize_t k
    18391840       
    18401841        if not self.is_square():
    1841             raise ArithmeticError, "self must be a square matrix"
     1842            raise ArithmeticError("self must be a square matrix")
    18421843
    18431844        if self.nrows() == 0:
    18441845            return decomp_seq([])
     
    19211922                        W.rank(), m*g.degree()), level=2, caller_name='rational decomp')
    19221923                    tries += 1
    19231924                    if tries > 5*m:
    1924                         raise RuntimeError, "likely bug in decomposition"
     1925                        raise RuntimeError("likely bug in decomposition")
    19251926                # end if
    19261927            #end while
    19271928        #end for
     
    24572458        cdef Matrix_rational_dense _A
    24582459        self.check_row_bounds_and_mutability(i,i)
    24592460        if r < 0 or r >= A.nrows():
    2460             raise IndexError, "invalid row"
     2461            raise IndexError("invalid row")
    24612462        # this function exists just because it is useful for modular symbols presentations.
    24622463        cdef Py_ssize_t l
    24632464        l = 0
     
    24882489        Does not check mutability.
    24892490        """
    24902491        if A._nrows != self._nrows:
    2491             raise TypeError, "nrows of self and A must be the same"
     2492            raise TypeError("nrows of self and A must be the same")
    24922493        cdef Py_ssize_t r
    24932494        for r from 0 <= r < self._nrows:
    24942495            mpq_add(self._matrix[r][i], self._matrix[r][i], A._matrix[r][j])
     
    25072508            3
    25082509        """
    25092510        if self._nrows != self._ncols:
    2510             raise ValueError, "incompatible matrix dimensions"
     2511            raise ValueError("incompatible matrix dimensions")
    25112512        cdef PariInstance P = sage.libs.pari.gen.pari
    25122513        sig_on()
    25132514        cdef GEN d = det0(pari_GEN(self), flag)
     
    25532554            []
    25542555        """
    25552556        if self._ncols != right._nrows:
    2556             raise ArithmeticError, "self must be a square matrix"
     2557            raise ArithmeticError("self must be a square matrix")
    25572558        if not self._ncols*self._nrows or not right._ncols*right._nrows:
    25582559            # pari doesn't work in case of 0 rows or columns
    25592560            # This case is easy, since the answer must be the 0 matrix.
     
    25772578            [ 3/2 -1/2]
    25782579        """
    25792580        if self._nrows != self._ncols:
    2580             raise ValueError, "self must be a square matrix"
     2581            raise ValueError("self must be a square matrix")
    25812582        cdef PariInstance P = sage.libs.pari.gen.pari
    25822583        cdef GEN M, d
    25832584
     
    25912592        # time... (!) :-(
    25922593        if rank(M) < self._nrows:
    25932594            P.clear_stack()
    2594             raise ZeroDivisionError, "input matrix must be nonsingular"
     2595            raise ZeroDivisionError("input matrix must be nonsingular")
    25952596        sig_on()
    25962597        d = ginv(M)
    25972598        sig_off()
     
    26302631            (1/5, -2/3)
    26312632        """
    26322633        if self._nrows == 0:
    2633             raise IndexError, "matrix has no rows"
     2634            raise IndexError("matrix has no rows")
    26342635        if i >= self._nrows or i < -self._nrows:
    2635             raise IndexError, "row index out of range"
     2636            raise IndexError("row index out of range")
    26362637        i = i % self._nrows
    26372638        if i < 0:
    26382639            i = i + self._nrows
     
    26642665            (1/5, 3/4)
    26652666        """
    26662667        if self._ncols == 0:
    2667             raise IndexError, "matrix has no columns"
     2668            raise IndexError("matrix has no columns")
    26682669        if i >= self._ncols or i < -self._ncols:
    2669             raise IndexError, "row index out of range"
     2670            raise IndexError("row index out of range")
    26702671        i %= self._ncols
    26712672        if i < 0: i += self._ncols
    26722673        cdef Py_ssize_t j
  • sage/matrix/matrix_space.py

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/matrix_space.py
    a b  
    178178        True
    179179    """
    180180    if not base_ring in Rings():
    181         raise TypeError, "base_ring (=%s) must be a ring"%base_ring
     181        raise TypeError("base_ring (=%s) must be a ring"%base_ring)
    182182   
    183183    if ncols is None: ncols = nrows
    184184    nrows = int(nrows); ncols = int(ncols); sparse=bool(sparse)
     
    234234        sage.structure.category_object.CategoryObject._init_category_(self, category)
    235235
    236236        if not base_ring in Rings():
    237             raise TypeError, "base_ring must be a ring"
     237            raise TypeError("base_ring must be a ring")
    238238        nrows = int(nrows)
    239239        ncols = int(ncols)
    240240        if nrows < 0:
    241             raise ArithmeticError, "nrows must be nonnegative"
     241            raise ArithmeticError("nrows must be nonnegative")
    242242        if ncols < 0:
    243             raise ArithmeticError, "ncols must be nonnegative"
     243            raise ArithmeticError("ncols must be nonnegative")
    244244
    245245        if nrows >= 2**63 or ncols >= 2**63:
    246             raise ValueError, "number of rows and columns must be less than 2^63"
     246            raise ValueError("number of rows and columns must be less than 2^63")
    247247        elif (nrows >= 2**31 or ncols >= 2**31) and not sage.misc.misc.is_64_bit:
    248             raise ValueError, "number of rows and columns must be less than 2^31 (on a 32-bit computer -- use a 64-bit computer for matrices with up to 2^63-1 rows and columns)"
     248            raise ValueError("number of rows and columns must be less than 2^31 (on a 32-bit computer -- use a 64-bit computer for matrices with up to 2^63-1 rows and columns)")
    249249           
    250250        self.__nrows = nrows
    251251        self.__is_sparse = sparse
     
    371371                elif len(entries[0]) == self.__nrows:
    372372                    rows = False
    373373                else:
    374                     raise ValueError, "incorrect dimensions"
     374                    raise ValueError("incorrect dimensions")
    375375           
    376376            if self.__is_sparse:
    377377                e = {}
     
    436436        Return base extension of this matrix space to R.
    437437       
    438438        INPUT:
    439        
    440        
     439
    441440        -  ``R`` - ring
    442        
    443        
     441
    444442        OUTPUT: a matrix space
    445443       
    446444        EXAMPLES::
     
    454452        """
    455453        if R.has_coerce_map_from(self.base_ring()):
    456454            return self.change_ring(R)
    457         raise TypeError, "no base extension defined"
     455        raise TypeError("no base extension defined")
    458456       
    459457    def construction(self):
    460458        """
     
    514512        """
    515513        if isinstance(x, matrix.Matrix):
    516514            if self.is_sparse() and x.is_dense():
    517                 raise TypeError, "cannot coerce dense matrix into sparse space for arithmetic"
     515                raise TypeError("cannot coerce dense matrix into sparse space for arithmetic")
    518516            if x.nrows() == self.nrows() and x.ncols() == self.ncols():
    519517                if self.base_ring().has_coerce_map_from(x.base_ring()):
    520518                    return self(x)
    521                 raise TypeError, "no canonical coercion"
     519                raise TypeError("no canonical coercion")
    522520        return self._coerce_try(x, self.base_ring())
    523521
    524522    def __cmp__(self, other):
     
    962960            ValueError: matrix is immutable; please change a copy instead (i.e., use copy(M) to change a copy of M).
    963961        """
    964962        if self.__nrows != self.__ncols:
    965             raise TypeError, "self must be a space of square matrices"
     963            raise TypeError("self must be a space of square matrices")
    966964        A = self.zero_matrix().__copy__()
    967965        for i in xrange(self.__nrows):
    968966            A[i,i] = 1
  • sage/matrix/misc.pyx

    diff -r 063ffd2a1aa7 -r c9cd63c29cf8 sage/matrix/misc.pyx
    a b  
    379379        verbose("finished comparing pivots", level=2, t=t, caller_name="multimod echelon")
    380380        try:
    381381            if len(Y) == 0:
    382                 raise ValueError, "not enough primes"
     382                raise ValueError("not enough primes")
    383383            t = verbose("start crt linear combination", level=2, caller_name="multimod echelon")
    384384            a = CRT_basis([w[1] for w in Y])
    385385            t = verbose('got crt basis', level=2, t=t, caller_name="multimod echelon")
     
    497497        OverflowError: cannot convert float infinity to integer
    498498    """
    499499    if not is_RealField(A.base_ring()):
    500         raise TypeError, "A must have base field an mpfr real field."
     500        raise TypeError("A must have base field an mpfr real field.")
    501501
    502502    cdef RealNumber a, b
    503503    cdef mpfr_t s, d, pr