本文整理汇总了Python中sage.misc.misc.uniq函数的典型用法代码示例。如果您正苦于以下问题:Python uniq函数的具体用法?Python uniq怎么用?Python uniq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了uniq函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, s):
"""
TESTS::
sage: s = Subsets(Set([1]))
sage: e = s.first()
sage: isinstance(e, s.element_class)
True
In the following "_test_elements" is temporarily disabled
until :class:`sage.sets.set.Set_object_enumerated` objects
pass the category tests::
sage: S = Subsets([1,2,3])
sage: TestSuite(S).run(skip=["_test_elements"])
sage: S = sage.sets.set.Set_object_enumerated([1,2])
sage: TestSuite(S).run() # todo: not implemented
"""
Parent.__init__(self, category=EnumeratedSets().Finite())
if s not in EnumeratedSets():
from sage.misc.misc import uniq
from sage.sets.finite_enumerated_set import FiniteEnumeratedSet
s = list(s)
us = uniq(s)
if len(us) == len(s):
s = FiniteEnumeratedSet(s)
else:
s = FiniteEnumeratedSet(us)
self._s = s
开发者ID:Etn40ff,项目名称:sage,代码行数:30,代码来源:subset.py
示例2: _check_polynomials_P3
def _check_polynomials_P3(quadratic1, quadratic2, variables):
"""
Check that the polynomial is weighted homogeneous in standard variables.
INPUT:
- ``quadratic1``, ``quadratic2`` -- two quadratic polynomials in 4
homogeneous or 3 inhomogeneous variables.
- ``variables`` -- the variables or ``None`` (default).
OUTPUT:
This function returns ``variables``, potentially guessed from the
polynomial ring. A ``ValueError`` is raised if the polynomial is
not homogeneous.
EXAMPLES:
sage: from sage.schemes.toric.weierstrass_higher import _check_polynomials_P3
sage: R.<w,x,y,z> = QQ[]
sage: quadratic = w^2+x^2+y^2+z^2
sage: _check_polynomials_P3(w^2, quadratic, [w,x,y,z])
(w, x, y, z)
sage: _check_polynomials_P3(w^2, quadratic, None)
(w, x, y, z)
sage: _check_polynomials_P3(z^2, quadratic.subs(w=0), None)
(x, y, z, None)
sage: R.<w,x,y,z,t> = QQ[]
sage: quadratic = w^2+x^2+y^2+z^2 + t*(x*y+y*z+z*w+w*x)
sage: _check_polynomials_P3(w^2, quadratic, [w,x,y,z])
(w, x, y, z)
sage: _check_polynomials_P3(w^2, quadratic, [w,x,y,t])
Traceback (most recent call last):
...
ValueError: The polynomial is not homogeneous with weights (1, 1, 1, 1)
"""
if quadratic1.parent() is not quadratic2.parent():
raise ValueError('The two quadratics must be in the same polynomial ring.')
if variables is None:
from sage.misc.misc import uniq
variables = uniq(quadratic1.variables() + quadratic2.variables())
variables.reverse()
if len(variables) == 4:
w, x, y, z = variables
_check_homogeneity(quadratic1, [w, x, y, z], (1, 1, 1, 1), 2)
_check_homogeneity(quadratic2, [w, x, y, z], (1, 1, 1, 1), 2)
elif len(variables) == 3:
w, x, y = variables
z = None
else:
raise ValueError('Need three or four variables, got '+str(variables))
return (w, x, y, z)
开发者ID:DrXyzzy,项目名称:sage,代码行数:53,代码来源:weierstrass_higher.py
示例3: automorphism_group
def automorphism_group(self):
"""
EXAMPLES::
sage: p = PermutationGroupElement((2,3))
sage: S = species.SetSpecies()
sage: F = S * S
sage: a = F.structures([1,2,3,4]).random_element(); a
{1}*{2, 3, 4}
sage: a.automorphism_group()
Permutation Group with generators [(2,3), (2,3,4)]
::
sage: [a.transport(g) for g in a.automorphism_group()]
[{1}*{2, 3, 4},
{1}*{2, 3, 4},
{1}*{2, 3, 4},
{1}*{2, 3, 4},
{1}*{2, 3, 4},
{1}*{2, 3, 4}]
::
sage: a = F.structures([1,2,3,4]).random_element(); a
{2, 3}*{1, 4}
sage: [a.transport(g) for g in a.automorphism_group()]
[{2, 3}*{1, 4}, {2, 3}*{1, 4}, {2, 3}*{1, 4}, {2, 3}*{1, 4}]
"""
from sage.groups.all import PermutationGroupElement, PermutationGroup, SymmetricGroup
from sage.misc.misc import uniq
from sage.combinat.species.misc import change_support
left, right = self._list
n = len(self._labels)
#Get the supports for each of the sides
l_support = self._subset._list
r_support = self._subset.complement()._list
#Get the automorphism group for the left object and
#make it have the correct support. Do the same to the
#right side.
l_aut = change_support(left.automorphism_group(), l_support)
r_aut = change_support(right.automorphism_group(), r_support)
identity = PermutationGroupElement([])
gens = l_aut.gens() + r_aut.gens()
gens = [g for g in gens if g != identity]
gens = uniq(gens) if len(gens) > 0 else [[]]
return PermutationGroup(gens)
开发者ID:bgxcpku,项目名称:sagelib,代码行数:52,代码来源:product_species.py
示例4: __iter__
def __iter__(self):
"""
EXAMPLES::
sage: Combinations(['a','a','b'],2).list() # indirect doctest
[['a', 'a'], ['a', 'b']]
"""
items = map(self.mset.index, self.mset)
indices = uniq(sorted(items))
counts = [0] * len(indices)
for i in items:
counts[indices.index(i)] += 1
for iv in IntegerVectors(self.k, len(indices), outer=counts):
yield sum([[self.mset[indices[i]]]*iv[i] for i in range(len(indices))],[])
开发者ID:BlairArchibald,项目名称:sage,代码行数:14,代码来源:combination.py
示例5: to_chain
def to_chain(self):
"""
Returns the chain of partitions corresponding to the (semi)standard
skew tableau.
EXAMPLES::
sage: SkewTableau([[None,1],[2],[3]]).to_chain()
[[1], [2], [2, 1], [2, 1, 1]]
sage: SkewTableau([[None,1],[1],[2]]).to_chain()
[[1], [2, 1], [2, 1, 1]]
"""
weights = [0] + uniq(sorted(self.to_word()))
return [ self.restrict(x).shape()[0] for x in weights]
开发者ID:odellus,项目名称:sage,代码行数:14,代码来源:skew_tableau.py
示例6: order_filter
def order_filter(self,elements):
"""
Returns the order filter generated by a list of elements.
`I` is an order filter if, for any `x` in `I` and `y` such that
`y \ge x`, then `y` is in `I`.
EXAMPLES::
sage: H = Posets.BooleanLattice(4)._hasse_diagram
sage: H.order_filter([3,8])
[3, 7, 8, 9, 10, 11, 12, 13, 14, 15]
"""
of = []
for i in elements:
for j in self.breadth_first_search(i):
of.append(j)
return uniq(of)
开发者ID:dagss,项目名称:sage,代码行数:18,代码来源:hasse_diagram.py
示例7: __contains__
def __contains__(self, x):
"""
EXAMPLES::
sage: c = Combinations(range(4))
sage: all( i in c for i in c )
True
sage: [3,4] in c
False
sage: [0,0] in c
False
"""
try:
x = list(x)
except TypeError:
return False
return all(i in self.mset for i in x) and len(uniq(x)) == len(x)
开发者ID:BlairArchibald,项目名称:sage,代码行数:18,代码来源:combination.py
示例8: order_ideal
def order_ideal(self,elements):
"""
Returns the order ideal generated by a list of elements.
`I` is an order ideal if, for any `x` in `I` and `y` such that
`y \le x`, then `y` is in `I`.
EXAMPLES::
sage: H = Posets.BooleanLattice(4)._hasse_diagram
sage: H.order_ideal([7,10])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 10]
"""
H = copy(self).reverse()
oi = []
for i in elements:
for j in H.breadth_first_search(i):
oi.append(j)
return uniq(oi)
开发者ID:sageb0t,项目名称:testsage,代码行数:19,代码来源:hasse_diagram.py
示例9: __contains__
def __contains__(self, x):
"""
EXAMPLES::
sage: from sage.combinat.choose_nk import ChooseNK
sage: c52 = ChooseNK(5,2)
sage: [0,1] in c52
True
sage: [1,1] in c52
False
sage: [0,1,3] in c52
False
"""
try:
x = list(x)
except TypeError:
return False
r = range(len(x))
return all(i in r for i in x) and len(uniq(x)) == self._k
开发者ID:sageb0t,项目名称:testsage,代码行数:20,代码来源:choose_nk.py
示例10: __init__
def __init__(self, alphabet):
"""
Builds an ordered alphabet from an iterable. The order is that
given by the order the items appear in the iterable. There must be
no duplicates.
NOTE:
The alphabet is expanded in memory and stored as a list.
EXAMPLES::
sage: from sage.combinat.words.alphabet import OrderedAlphabet_Finite
sage: A = OrderedAlphabet_Finite([0,1,2])
sage: A == loads(dumps(A))
True
sage: A = OrderedAlphabet_Finite("abc")
sage: A == loads(dumps(A))
True
TESTS::
sage: from sage.combinat.words.alphabet import OrderedAlphabet_Finite
sage: OrderedAlphabet_Finite('aba')
Traceback (most recent call last):
...
ValueError: duplicate elements in alphabet
sage: OrderedAlphabet_Finite(33)
Traceback (most recent call last):
...
TypeError: cannot build an alphabet from 33
"""
try:
self._alphabet = list(alphabet)
except TypeError:
raise TypeError, "cannot build an alphabet from %s" % (alphabet)
if len(uniq(self._alphabet)) != len(self._alphabet):
raise ValueError, "duplicate elements in alphabet"
开发者ID:jtmurphy89,项目名称:sagelib,代码行数:37,代码来源:alphabet.py
示例11: __add__
#.........这里部分代码省略.........
|
|
|
sage: l3 + l5
|
||
||
||
|
sage: l5 + l3
|
||
||
||
|
sage: l5._baseline = 0
sage: l5 + l3
|
|
|
||
||
|
sage: l5._baseline = 4
sage: l5 + l3
|
||
||
|
|
|
sage: l3._baseline = 0
sage: l3 + l5
|
|
||
|
|
|
|
"""
new_matrix = []
new_h = self.__class__._compute_new_h(self, Nelt)
new_baseline = self.__class__._compute_new_baseline(self, Nelt)
if self._baseline is not None and Nelt._baseline is not None:
# left treatement
for line in self._matrix:
new_matrix.append(line + " " * (self._l - len(line)))
if new_h > self._h:
# | new_h > self._h
# | new_baseline > self._baseline
# ||<-- baseline number of white lines at the bottom
# | } :: Nelt._baseline - self._baseline
# | }
if new_baseline > self._baseline:
for k in range(new_baseline - self._baseline):
new_matrix.append(" " * self._l)
# | } new_h > self._h
# | } new_h - new_baseline > self._h - self._baseline
# ||<-- baseline number of white lines at the top
# || :: new_h - new_baseline - self._h + self._baseline
# ||
# |
# |
if new_h - new_baseline > self._h - self._baseline:
for _ in range((new_h - new_baseline) - (self._h - self._baseline)):
new_matrix.insert(0, " " * self._l)
# right treatement
i = 0
if new_h > Nelt._h:
# | } new_h > Nelt._h
# | } new_h - new_baseline > Nelt._h - self._baseline
# ||<-- baseline number of white lines at the top
# || :: new_h - new_baseline - Nelt._h + Nelt._baseline
# ||
# ||
# |
i = max(new_h - new_baseline - Nelt._h + Nelt._baseline, 0)
for j in range(Nelt._h):
new_matrix[i + j] += Nelt._matrix[j]
else:
for line in self._matrix:
new_matrix.append(line + " " * (self._l - len(line)))
for i, line_i in enumerate(Nelt._matrix):
if i == len(new_matrix):
new_matrix.append(" " * self._l + line_i)
else:
new_matrix[i] += line_i
# breakpoint
new_breakpoints = list(self._breakpoints)
new_breakpoints.append(self._l)
for bp in Nelt._breakpoints:
new_breakpoints.append(bp + self._l)
from sage.misc.misc import uniq
return self.__class__(lines=new_matrix, breakpoints=uniq(new_breakpoints), baseline=new_baseline)
开发者ID:sampadsaha5,项目名称:sage,代码行数:101,代码来源:character_art.py
示例12: __init__
def __init__(self, matrices, C, D, check=True):
"""
Create a morphism from a dictionary of matrices.
EXAMPLES::
sage: S = simplicial_complexes.Sphere(1)
sage: S
Minimal triangulation of the 1-sphere
sage: C = S.chain_complex()
sage: C.differential()
{0: [], 1: [-1 -1 0]
[ 1 0 -1]
[ 0 1 1], 2: []}
sage: f = {0:zero_matrix(ZZ,3,3),1:zero_matrix(ZZ,3,3)}
sage: G = Hom(C,C)
sage: x = G(f)
sage: x
Chain complex endomorphism of Chain complex with at most 2 nonzero terms over Integer Ring
sage: x._matrix_dictionary
{0: [0 0 0]
[0 0 0]
[0 0 0], 1: [0 0 0]
[0 0 0]
[0 0 0]}
Check that the bug in :trac:`13220` has been fixed::
sage: X = simplicial_complexes.Simplex(1)
sage: Y = simplicial_complexes.Simplex(0)
sage: g = Hom(X,Y)({0:0, 1:0})
sage: g.associated_chain_complex_morphism()
Chain complex morphism:
From: Chain complex with at most 2 nonzero terms over Integer Ring
To: Chain complex with at most 1 nonzero terms over Integer Ring
Check that an error is raised if the matrices are the wrong size::
sage: C = ChainComplex({0: zero_matrix(ZZ, 0, 1)})
sage: D = ChainComplex({0: zero_matrix(ZZ, 0, 2)})
sage: Hom(C,D)({0: matrix(1, 2, [1, 1])}) # 1x2 is the wrong size.
Traceback (most recent call last):
...
ValueError: matrix in degree 0 is not the right size
sage: Hom(C,D)({0: matrix(2, 1, [1, 1])}) # 2x1 is right.
Chain complex morphism:
From: Chain complex with at most 1 nonzero terms over Integer Ring
To: Chain complex with at most 1 nonzero terms over Integer Ring
"""
if not C.base_ring() == D.base_ring():
raise NotImplementedError('morphisms between chain complexes of different'
' base rings are not implemented')
d = C.degree_of_differential()
if d != D.degree_of_differential():
raise ValueError('degree of differential does not match')
from sage.misc.misc import uniq
degrees = uniq(list(C.differential()) + list(D.differential()))
initial_matrices = dict(matrices)
matrices = dict()
for i in degrees:
if i - d not in degrees:
if not (C.free_module_rank(i) == D.free_module_rank(i) == 0):
raise ValueError('{} and {} are not rank 0 in degree {}'.format(C, D, i))
continue
try:
matrices[i] = initial_matrices.pop(i)
except KeyError:
matrices[i] = zero_matrix(C.base_ring(),
D.differential(i).ncols(),
C.differential(i).ncols(), sparse=True)
if check:
# All remaining matrices given must be 0x0.
if not all(m.ncols() == m.nrows() == 0 for m in initial_matrices.values()):
raise ValueError('the remaining matrices are not empty')
# Check sizes of matrices.
for i in matrices:
if (matrices[i].nrows() != D.free_module_rank(i) or
matrices[i].ncols() != C.free_module_rank(i)):
raise ValueError('matrix in degree {} is not the right size'.format(i))
# Check commutativity.
for i in degrees:
if i - d not in degrees:
if not (C.free_module_rank(i) == D.free_module_rank(i) == 0):
raise ValueError('{} and {} are not rank 0 in degree {}'.format(C, D, i))
continue
if i + d not in degrees:
if not (C.free_module_rank(i+d) == D.free_module_rank(i+d) == 0):
raise ValueError('{} and {} are not rank 0 in degree {}'.format(C, D, i+d))
continue
Dm = D.differential(i) * matrices[i]
mC = matrices[i+d] * C.differential(i)
if mC != Dm:
raise ValueError('matrices must define a chain complex morphism')
self._matrix_dictionary = {}
for i in matrices:
m = matrices[i]
# Use immutable matrices because they're hashable.
m.set_immutable()
self._matrix_dictionary[i] = m
#.........这里部分代码省略.........
开发者ID:saraedum,项目名称:sage-renamed,代码行数:101,代码来源:chain_complex_morphism.py
示例13: __init__
def __init__(self, matrices, C, D, check=True):
"""
Create a morphism from a dictionary of matrices.
EXAMPLES::
from sage.matrix.constructor import zero_matrix
sage: S = simplicial_complexes.Sphere(1)
sage: S
Simplicial complex with vertex set (0, 1, 2) and facets {(1, 2), (0, 2), (0, 1)}
sage: C = S.chain_complex()
sage: C.differential()
{0: [], 1: [ 1 1 0]
[ 0 -1 -1]
[-1 0 1], 2: []}
sage: f = {0:zero_matrix(ZZ,3,3),1:zero_matrix(ZZ,3,3)}
sage: G = Hom(C,C)
sage: x = G(f)
sage: x
Chain complex morphism from Chain complex with at most 2 nonzero terms
over Integer Ring to Chain complex with at most 2 nonzero terms over
Integer Ring
sage: x._matrix_dictionary
{0: [0 0 0]
[0 0 0]
[0 0 0], 1: [0 0 0]
[0 0 0]
[0 0 0]}
Check that the bug in :trac:`13220` has been fixed::
sage: X = simplicial_complexes.Simplex(1)
sage: Y = simplicial_complexes.Simplex(0)
sage: g = Hom(X,Y)({0:0, 1:0})
sage: g.associated_chain_complex_morphism()
Chain complex morphism from Chain complex with at most 2 nonzero
terms over Integer Ring to Chain complex with at most 1 nonzero terms
over Integer Ring
"""
if not C.base_ring() == D.base_ring():
raise NotImplementedError('morphisms between chain complexes of different'
' base rings are not implemented')
d = C.degree_of_differential()
if d != D.degree_of_differential():
raise ValueError('degree of differential does not match')
from sage.misc.misc import uniq
degrees = uniq(C.differential().keys() + D.differential().keys())
initial_matrices = dict(matrices)
matrices = dict()
for i in degrees:
if i - d not in degrees:
if not (C.free_module_rank(i) == D.free_module_rank(i) == 0):
raise ValueError('{} and {} are not rank 0 in degree {}'.format(C, D, i))
continue
try:
matrices[i] = initial_matrices.pop(i)
except KeyError:
matrices[i] = matrix.zero_matrix(C.base_ring(),
D.differential(i).ncols(),
C.differential(i).ncols(), sparse=True)
if check:
# all remaining matrices given must be 0x0
if not all(m.ncols() == m.nrows() == 0 for m in initial_matrices.values()):
raise ValueError('the remaining matrices are not empty')
# check commutativity
for i in degrees:
if i - d not in degrees:
if not (C.free_module_rank(i) == D.free_module_rank(i) == 0):
raise ValueError('{} and {} are not rank 0 in degree {}'.format(C, D, i))
continue
if i + d not in degrees:
if not (C.free_module_rank(i+d) == D.free_module_rank(i+d) == 0):
raise ValueError('{} and {} are not rank 0 in degree {}'.format(C, D, i+d))
continue
Dm = D.differential(i) * matrices[i]
mC = matrices[i+d] * C.differential(i)
if mC != Dm:
raise ValueError('matrices must define a chain complex morphism')
self._matrix_dictionary = matrices
self._domain = C
self._codomain = D
开发者ID:BlairArchibald,项目名称:sage,代码行数:82,代码来源:chain_complex_morphism.py
注:本文中的sage.misc.misc.uniq函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论