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
# 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 sage: rays.set() frozenset([N(1, 0, 0), N(-1, 0, 0), N(0, 1, 0), N(0, 0, 1), N(0, -1, 0)]) sage: rays.matrix() [ 0  0  0  1 -1] [ 0  1 -1  0  0] [ 1  0  0  0  0] [ 0  0  1] [ 0  1  0] [ 0 -1  0] [ 1  0  0] [-1  0  0] sage: rays(3) [1] [0] sage: halfspace.ray(3) N(1, 0, 0) Note that while we output rays by default as a matrix, the method :meth:~ConvexRationalPolyhedralCone.rays returns a :class:~sage.geometry.point_collection.PointCollection with the i-th element being the i-th point, i.e. the i-th column of the shown matrix, while after explicit conversion to a matrix indexing refers to rows. In the above example requesting the third row will lead to an error:: sage: halfspace.rays().matrix()[3] Traceback (most recent call last): ... IndexError: matrix index out of range Note that while we output rays by default as a matrix with each *column* being a ray generator, the method :meth:~ConvexRationalPolyhedralCone.rays returns a :class:~sage.geometry.point_collection.PointCollection with the i-th element being the i-th point corresponding to the i-th row of the matrix obtained by explicit conversion. If you want to do something with each ray of a cone, you can write :: [ 1  0  0] """ deprecation("ray_matrix(...) is deprecated, " "please use rays().matrix() instead!", "please use rays().matrix().tranpose() instead!", "Sage Version 5.0") return self._rays.matrix() return self._rays.matrix().transpose() def ray_set(self): r""" [ 1  1  1  1] """ deprecation("ray_basis_matrix(...) is deprecated, " "please use rays().basis().matrix() instead!", "please use rays().basis().matrix().transpose() instead!", "Sage Version 5.0") basis = self.ray_basis() m = self._lattice.degree() """ if not self.is_simplicial(): return False return self.rays().matrix().transpose().elementary_divisors() == \ [1] * self.nrays() return self.rays().matrix().elementary_divisors() == [1] * self.nrays() def is_trivial(self): """ [ 0  0] """ if "_lattice_polytope" not in self.__dict__: m = self.rays().matrix() if self.is_strictly_convex(): m = m.augment(matrix(ZZ, self.lattice().degree(), 1)) # origin self._lattice_polytope = LatticePolytope(m, compute_vertices=False, copy_vertices=False) self._lattice_polytope = LatticePolytope( tuple(self.rays()) + (self.lattice().zero(),), compute_vertices=not self.is_strictly_convex()) return self._lattice_polytope def line_set(self): sage: trivial_cone._orthogonal_sublattice_complement Sublattice <> """ Nsigma = self.rays().basis().matrix() Nsigma = self.rays().basis().matrix().transpose() r = Nsigma.ncols() D, U, V = Nsigma.smith_form()  # D = U*N*V <=> N = Uinv*D*Vinv Uinv = U.inverse() # recursively N = self.lattice() if not self.is_simplicial(): from sage.geometry.triangulation.point_configuration import PointConfiguration from sage.geometry.triangulation.point_configuration \ import PointConfiguration origin = self.nrays() # last one in pc pc = PointConfiguration(tuple(self.rays()) + (N(0),), star=origin) triangulation = pc.triangulate()
• sage/geometry/fan.py

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

diff --git a/sage/geometry/integral_points.pyx b/sage/geometry/integral_points.pyx
 a #                  http://www.gnu.org/licenses/ #***************************************************************************** from sage.geometry.point_collection import is_PointCollection from sage.matrix.constructor import matrix, column_matrix, vector, diagonal_matrix from sage.rings.all import QQ, RR, ZZ, gcd, lcm from sage.combinat.permutation import Permutation sage: len(parallelotope_points(rays, ZZ^4)) 967 """ if is_PointCollection(spanning_points): R = spanning_points.matrix() else: R = matrix(spanning_points).transpose() R = matrix(spanning_points).transpose() e, d, VDinv = ray_matrix_normal_form(R) points = loop_over_parallelotope_points(e, d, VDinv, R, lattice) for p in points:
• sage/geometry/lattice_polytope.py

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

diff --git a/sage/geometry/point_collection.pyx b/sage/geometry/point_collection.pyx
 a from sage.structure.sage_object cimport SageObject from sage.matrix.all import column_matrix from sage.matrix.all import matrix from sage.misc.all import latex 1 & 1 & 1 & 1 \end{array}\right)_{N} """ return r"%s_{%s}" % (latex(self.matrix()), latex(self.module())) return r"%s_{%s}" % (latex(self.matrix().transpose()), latex(self.module())) def _matrix_(self, ring=None): r""" Return a matrix whose rows are points of self. INPUT: - ring -- a base ring for the returned matrix (default: \ZZ). OUTPUT: - a :class:matrix . EXAMPLES:: sage: c = Cone([(0,0,1), (1,0,1), (0,1,1), (1,1,1)]).rays() sage: matrix(c) [0 0 1] [1 0 1] [0 1 1] [1 1 1] """ if ring is None: return self.matrix() else: return self.matrix().base_extend(ring) def _repr_(self): r""" [1 1 1 1] in 3-d lattice N """ return "%s\nin %s" % (self.matrix(), self.module()) return "%s\nin %s" % (self.matrix().transpose(), self.module()) def basis(self): r""" True """ if self._basis is None: self._basis = self(self.matrix().pivots()) self._basis = self(self.matrix().pivot_rows()) return self._basis def cardinality(self): def matrix(self): r""" Return a matrix whose columns are points of self. Return a matrix whose rows are points of self. OUTPUT: sage: c = Cone([(0,0,1), (1,0,1), (0,1,1), (1,1,1)]).rays() sage: c.matrix() [0 1 0 1] [0 0 1 1] [1 1 1 1] [0 0 1] [1 0 1] [0 1 1] [1 1 1] """ if self._matrix is None: M = column_matrix(self._module.base_ring(), len(self._points), self._module.degree(), self._points) M = matrix(self._module.base_ring(), len(self._points), self._module.degree(), self._points) M.set_immutable() self._matrix = M 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 exponent = monomial.exponents()[0] exponent = [ exponent[i] for i in cone.ambient_ray_indices() ] exponent = vector(ZZ,exponent) m = n_rho_matrix.solve_left(exponent) m = n_rho_matrix.solve_right(exponent) assert all(x in ZZ for x in m), \ 'The polynomial '+str(p)+' does not define a ZZ-divisor!' 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 assert cone.ambient() is fan b = vector(self.coefficient(i) for i in cone.ambient_ray_indices()) A = cone.rays().matrix() A = cone.rays().matrix().transpose() try: if cone.dim() == X.dimension(): # 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 for rho, x in zip(phi.domain_fan(1), R.gens()): ray = rho.ray(0) sigma = phi.image_cone(rho) degrees = sigma.rays().matrix().solve_right(phi(ray)) degrees = sigma.rays().matrix().solve_left(phi(ray)) for i, d in zip(sigma.ambient_ray_indices(), degrees): try: 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 fan = self.fan() from sage.modules.free_module import FreeModule degrees_group = FreeModule(ZZ, fan.nrays()).quotient( fan.rays().matrix().rows()) fan.rays().matrix().columns()) self._homogeneous_degrees_group = degrees_group degrees_group = self._homogeneous_degrees_group S = self.coordinate_ring() basis = dual.Hilbert_basis() N = len(basis) names = normalize_names(names, N, DEFAULT_PREFIX) A = basis.matrix() A = basis.matrix().transpose() IA = ToricIdeal(A, names, base_ring=self.base_ring()) return (IA.ring(), IA, dual) elif is_Cone(x): cone = fan.embed(x) assert cone.ambient() is fan mult = cone.rays().matrix().index_in_saturation() mult = cone.rays().matrix().transpose().index_in_saturation() x = prod((self.cover_ring().gen(i) for i in cone.ambient_ray_indices()), z=self.cover_ring().one()) * mult else: