Ticket #12544: trac_12544_flip_point_collection_matrix.patch

File trac_12544_flip_point_collection_matrix.patch, 12.3 KB (added by novoselt, 9 years ago)
  • sage/geometry/cone.py

    # HG changeset patch
    # User Andrey Novoseltsev <novoselt@gmail.com>
    # Date 1333579997 21600
    # Node ID 272a6d3e65aad1ca3457df6869789d0844b00884
    # Parent  74ed1801a8eea6a397dfefeb6fea7e624e225bce
    Transpose the matrix of PointCollection to make matrix(pc)==pc.matrix().
    
    diff --git a/sage/geometry/cone.py b/sage/geometry/cone.py
    a b  
    6161    sage: rays.set()
    6262    frozenset([N(1, 0, 0), N(-1, 0, 0), N(0, 1, 0), N(0, 0, 1), N(0, -1, 0)])
    6363    sage: rays.matrix()
    64     [ 0  0  0  1 -1]
    65     [ 0  1 -1  0  0]
    66     [ 1  0  0  0  0]
     64    [ 0  0  1]
     65    [ 0  1  0]
     66    [ 0 -1  0]
     67    [ 1  0  0]
     68    [-1  0  0]
    6769    sage: rays(3)
    6870    [1]
    6971    [0]
     
    7476    sage: halfspace.ray(3)
    7577    N(1, 0, 0)
    7678
    77 Note that while we output rays by default as a matrix, the method
    78 :meth:`~ConvexRationalPolyhedralCone.rays` returns a
    79 :class:`~sage.geometry.point_collection.PointCollection` with the `i`-th
    80 element being the `i`-th point, i.e. the `i`-th column of the shown matrix,
    81 while after explicit conversion to a matrix indexing refers to rows. In the
    82 above example requesting the third row will lead to an error::
    83 
    84     sage: halfspace.rays().matrix()[3]
    85     Traceback (most recent call last):
    86     ...
    87     IndexError: matrix index out of range
     79Note that while we output rays by default as a matrix with each *column* being
     80a ray generator, the method :meth:`~ConvexRationalPolyhedralCone.rays` returns
     81a :class:`~sage.geometry.point_collection.PointCollection` with the `i`-th
     82element being the `i`-th point corresponding to the `i`-th row of the matrix
     83obtained by explicit conversion.
    8884
    8985If you want to do something with each ray of a cone, you can write ::
    9086
     
    1001997            [ 1  0  0]
    1002998        """
    1003999        deprecation("ray_matrix(...) is deprecated, "
    1004                     "please use rays().matrix() instead!",
     1000                    "please use rays().matrix().tranpose() instead!",
    10051001                    "Sage Version 5.0")
    1006         return self._rays.matrix()
     1002        return self._rays.matrix().transpose()
    10071003
    10081004    def ray_set(self):
    10091005        r"""
     
    11191115            [ 1  1  1  1]
    11201116        """
    11211117        deprecation("ray_basis_matrix(...) is deprecated, "
    1122                     "please use rays().basis().matrix() instead!",
     1118                    "please use rays().basis().matrix().transpose() instead!",
    11231119                    "Sage Version 5.0")
    11241120        basis = self.ray_basis()
    11251121        m = self._lattice.degree()
     
    27602756        """
    27612757        if not self.is_simplicial():
    27622758            return False
    2763         return self.rays().matrix().transpose().elementary_divisors() == \
    2764                [1] * self.nrays()
     2759        return self.rays().matrix().elementary_divisors() == [1] * self.nrays()
    27652760
    27662761    def is_trivial(self):
    27672762        """
     
    28442839            [ 0  0]
    28452840        """
    28462841        if "_lattice_polytope" not in self.__dict__:
    2847             m = self.rays().matrix()
    2848             if self.is_strictly_convex():
    2849                 m = m.augment(matrix(ZZ, self.lattice().degree(), 1)) # origin
    2850             self._lattice_polytope = LatticePolytope(m,
    2851                                 compute_vertices=False, copy_vertices=False)
     2842            self._lattice_polytope = LatticePolytope(
     2843                                tuple(self.rays()) + (self.lattice().zero(),),
     2844                                compute_vertices=not self.is_strictly_convex())
    28522845        return self._lattice_polytope
    28532846
    28542847    def line_set(self):
     
    31143107            sage: trivial_cone._orthogonal_sublattice_complement
    31153108            Sublattice <>
    31163109        """
    3117         Nsigma = self.rays().basis().matrix()
     3110        Nsigma = self.rays().basis().matrix().transpose()
    31183111        r = Nsigma.ncols()
    31193112        D, U, V = Nsigma.smith_form()  # D = U*N*V <=> N = Uinv*D*Vinv
    31203113        Uinv = U.inverse()
     
    36683661        # recursively
    36693662        N = self.lattice()       
    36703663        if not self.is_simplicial():   
    3671             from sage.geometry.triangulation.point_configuration import PointConfiguration
     3664            from sage.geometry.triangulation.point_configuration \
     3665                    import PointConfiguration
    36723666            origin = self.nrays() # last one in pc
    36733667            pc = PointConfiguration(tuple(self.rays()) + (N(0),), star=origin)
    36743668            triangulation = pc.triangulate()
  • sage/geometry/fan.py

    diff --git a/sage/geometry/fan.py b/sage/geometry/fan.py
    a b  
    20452045            sage: _.base_ring()
    20462046            Integer Ring
    20472047        """
    2048         m = self.rays().matrix().augment(matrix(self.lattice_dim(), 1))
    2049         m = m.stack(matrix([1]*m.ncols()))
    2050         return matrix(ZZ, m.transpose().integer_kernel().matrix())
     2048        m = self.rays().matrix().stack(matrix(ZZ, 1, self.lattice_dim()))
     2049        m = m.augment(matrix(ZZ, m.nrows(), 1, [1]*m.nrows()))
     2050        return matrix(ZZ, m.integer_kernel().matrix())
    20512051
    20522052    def generating_cone(self, n):
    20532053        r"""
  • sage/geometry/integral_points.pyx

    diff --git a/sage/geometry/integral_points.pyx b/sage/geometry/integral_points.pyx
    a b  
    1010#                  http://www.gnu.org/licenses/
    1111#*****************************************************************************
    1212
    13 from sage.geometry.point_collection import is_PointCollection
    1413from sage.matrix.constructor import matrix, column_matrix, vector, diagonal_matrix
    1514from sage.rings.all import QQ, RR, ZZ, gcd, lcm
    1615from sage.combinat.permutation import Permutation
     
    128127        sage: len(parallelotope_points(rays, ZZ^4))
    129128        967
    130129    """
    131     if is_PointCollection(spanning_points):
    132         R = spanning_points.matrix()
    133     else:
    134         R = matrix(spanning_points).transpose()
     130    R = matrix(spanning_points).transpose()
    135131    e, d, VDinv = ray_matrix_normal_form(R)
    136132    points = loop_over_parallelotope_points(e, d, VDinv, R, lattice)
    137133    for p in points:
  • sage/geometry/lattice_polytope.py

    diff --git a/sage/geometry/lattice_polytope.py b/sage/geometry/lattice_polytope.py
    a b  
    283283    if isinstance(data, LatticePolytopeClass):
    284284        return data
    285285
    286     if is_PointCollection(data):
    287         data = data.matrix()
    288     elif not is_Matrix(data) and not isinstance(data,(file,basestring)):
     286    if not is_Matrix(data) and not isinstance(data,(file,basestring)):
    289287        try:
    290288            data = matrix(ZZ,data).transpose()
    291289        except ValueError:
  • sage/geometry/point_collection.pyx

    diff --git a/sage/geometry/point_collection.pyx b/sage/geometry/point_collection.pyx
    a b  
    7878
    7979from sage.structure.sage_object cimport SageObject
    8080
    81 from sage.matrix.all import column_matrix
     81from sage.matrix.all import matrix
    8282from sage.misc.all import latex
    8383
    8484
     
    379379            1 & 1 & 1 & 1
    380380            \end{array}\right)_{N}
    381381        """
    382         return r"%s_{%s}" % (latex(self.matrix()), latex(self.module()))
     382        return r"%s_{%s}" % (latex(self.matrix().transpose()),
     383                             latex(self.module()))
     384
     385    def _matrix_(self, ring=None):
     386        r"""
     387        Return a matrix whose rows are points of ``self``.
     388       
     389        INPUT:
     390       
     391        - ``ring`` -- a base ring for the returned matrix (default: `\ZZ`).
     392
     393        OUTPUT:
     394
     395        - a :class:`matrix <Matrix>`.
     396
     397        EXAMPLES::
     398
     399            sage: c = Cone([(0,0,1), (1,0,1), (0,1,1), (1,1,1)]).rays()
     400            sage: matrix(c)
     401            [0 0 1]
     402            [1 0 1]
     403            [0 1 1]
     404            [1 1 1]
     405        """
     406        if ring is None:
     407            return self.matrix()
     408        else:
     409            return self.matrix().base_extend(ring)
    383410
    384411    def _repr_(self):
    385412        r"""
     
    398425            [1 1 1 1]
    399426            in 3-d lattice N
    400427        """
    401         return "%s\nin %s" % (self.matrix(), self.module())
     428        return "%s\nin %s" % (self.matrix().transpose(), self.module())
    402429
    403430    def basis(self):
    404431        r"""
     
    426453            True
    427454        """
    428455        if self._basis is None:
    429             self._basis = self(self.matrix().pivots())
     456            self._basis = self(self.matrix().pivot_rows())
    430457        return self._basis
    431458           
    432459    def cardinality(self):
     
    570597
    571598    def matrix(self):
    572599        r"""
    573         Return a matrix whose columns are points of ``self``.
     600        Return a matrix whose rows are points of ``self``.
    574601
    575602        OUTPUT:
    576603
     
    580607
    581608            sage: c = Cone([(0,0,1), (1,0,1), (0,1,1), (1,1,1)]).rays()
    582609            sage: c.matrix()
    583             [0 1 0 1]
    584             [0 0 1 1]
    585             [1 1 1 1]
     610            [0 0 1]
     611            [1 0 1]
     612            [0 1 1]
     613            [1 1 1]
    586614        """
    587615        if self._matrix is None:
    588             M = column_matrix(self._module.base_ring(), len(self._points),
    589                               self._module.degree(), self._points)
     616            M = matrix(self._module.base_ring(), len(self._points),
     617                       self._module.degree(), self._points)
    590618            M.set_immutable()
    591619            self._matrix = M
    592620        return self._matrix
  • sage/schemes/generic/algebraic_scheme.py

    diff --git a/sage/schemes/generic/algebraic_scheme.py b/sage/schemes/generic/algebraic_scheme.py
    a b  
    22952295                exponent = monomial.exponents()[0]
    22962296                exponent = [ exponent[i] for i in cone.ambient_ray_indices() ]
    22972297                exponent = vector(ZZ,exponent)
    2298                 m = n_rho_matrix.solve_left(exponent)
     2298                m = n_rho_matrix.solve_right(exponent)
    22992299                assert all(x in ZZ for x in m), \
    23002300                    'The polynomial '+str(p)+' does not define a ZZ-divisor!'
    23012301                m_coeffs = dualcone.Hilbert_coefficients(m)
  • sage/schemes/generic/toric_divisor.py

    diff --git a/sage/schemes/generic/toric_divisor.py b/sage/schemes/generic/toric_divisor.py
    a b  
    828828
    829829        assert cone.ambient() is fan
    830830        b = vector(self.coefficient(i) for i in cone.ambient_ray_indices())
    831         A = cone.rays().matrix()
     831        A = cone.rays().matrix().transpose()
    832832        try:
    833833            if cone.dim() == X.dimension():
    834834                # either unique solution or ValueError (if not QQ-Cartier)
  • sage/schemes/generic/toric_morphism.py

    diff --git a/sage/schemes/generic/toric_morphism.py b/sage/schemes/generic/toric_morphism.py
    a b  
    506506        for rho, x in zip(phi.domain_fan(1), R.gens()):
    507507            ray = rho.ray(0)
    508508            sigma = phi.image_cone(rho)
    509             degrees = sigma.rays().matrix().solve_right(phi(ray))
     509            degrees = sigma.rays().matrix().solve_left(phi(ray))
    510510            for i, d in zip(sigma.ambient_ray_indices(), degrees):
    511511                try:
    512512                    d = ZZ(d)
  • sage/schemes/generic/toric_variety.py

    diff --git a/sage/schemes/generic/toric_variety.py b/sage/schemes/generic/toric_variety.py
    a b  
    12701270            fan = self.fan()
    12711271            from sage.modules.free_module import FreeModule
    12721272            degrees_group = FreeModule(ZZ, fan.nrays()).quotient(
    1273                                                     fan.rays().matrix().rows())
     1273                                                fan.rays().matrix().columns())
    12741274            self._homogeneous_degrees_group = degrees_group
    12751275        degrees_group = self._homogeneous_degrees_group
    12761276        S = self.coordinate_ring()
     
    24912491        basis = dual.Hilbert_basis()
    24922492        N = len(basis)
    24932493        names = normalize_names(names, N, DEFAULT_PREFIX)
    2494         A = basis.matrix()
     2494        A = basis.matrix().transpose()
    24952495        IA = ToricIdeal(A, names, base_ring=self.base_ring())
    24962496        return (IA.ring(), IA, dual)
    24972497
     
    31023102        elif is_Cone(x):
    31033103            cone = fan.embed(x)
    31043104            assert cone.ambient() is fan
    3105             mult = cone.rays().matrix().index_in_saturation()
     3105            mult = cone.rays().matrix().transpose().index_in_saturation()
    31063106            x = prod((self.cover_ring().gen(i) for i in cone.ambient_ray_indices()),
    31073107                     z=self.cover_ring().one()) * mult
    31083108        else: