本文整理汇总了Python中sympy.core.compatibility.default_sort_key函数的典型用法代码示例。如果您正苦于以下问题:Python default_sort_key函数的具体用法?Python default_sort_key怎么用?Python default_sort_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default_sort_key函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __new__
def __new__(cls, expr1, expr2):
expr1 = sympify(expr1)
expr2 = sympify(expr2)
if default_sort_key(expr1) > default_sort_key(expr2):
return -Cross(expr2, expr1)
obj = Expr.__new__(cls, expr1, expr2)
obj._expr1 = expr1
obj._expr2 = expr2
return obj
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:9,代码来源:vector.py
示例2: sort_key
def sort_key(self, order=None):
"""Return a canonical key that can be used for sorting.
Ordering is based on the size and sorted elements of the partition
and ties are broken with the rank.
Examples
========
>>> from sympy.utilities.iterables import default_sort_key
>>> from sympy.combinatorics.partitions import Partition
>>> from sympy.abc import x
>>> a = Partition([1, 2])
>>> b = Partition([3, 4])
>>> c = Partition([1, x])
>>> d = Partition(list(range(4)))
>>> l = [d, b, a + 1, a, c]
>>> l.sort(key=default_sort_key); l
[{{1, 2}}, {{1}, {2}}, {{1, x}}, {{3, 4}}, {{0, 1, 2, 3}}]
"""
if order is None:
members = self.members
else:
members = tuple(sorted(self.members,
key=lambda w: default_sort_key(w, order)))
return list(map(default_sort_key, (self.size, members, self.rank)))
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:26,代码来源:partitions.py
示例3: as_expr_variables
def as_expr_variables(self, order_symbols):
if order_symbols is None:
order_symbols = self.args[1:]
else:
if not all(o[1] == order_symbols[0][1] for o in order_symbols) and \
not all(p == self.point[0] for p in self.point):
raise NotImplementedError('Order at points other than 0 '
'or oo not supported, got %s as a point.' % point)
if order_symbols[0][1] != self.point[0]:
raise NotImplementedError(
"Multiplying Order at different points is not supported.")
order_symbols = dict(order_symbols)
for s, p in dict(self.args[1:]).items():
if s not in order_symbols.keys():
order_symbols[s] = p
order_symbols = sorted(order_symbols.items(), key=lambda x: default_sort_key(x[0]))
return self.expr, tuple(order_symbols)
开发者ID:Amo10,项目名称:Computer-Science-2014-2015,代码行数:17,代码来源:order.py
示例4: sort_args_by_name
def sort_args_by_name(self):
"""
Sort arguments in the tensor product so that their order is lexicographical.
Examples
========
>>> from sympy import MatrixSymbol, MatrixExpr, Sum, Symbol
>>> from sympy.abc import i, j, k, l, N
>>> from sympy.codegen.array_utils import CodegenArrayContraction
>>> A = MatrixSymbol("A", N, N)
>>> B = MatrixSymbol("B", N, N)
>>> C = MatrixSymbol("C", N, N)
>>> D = MatrixSymbol("D", N, N)
>>> cg = CodegenArrayContraction.from_MatMul(C*D*A*B)
>>> cg
CodegenArrayContraction(CodegenArrayTensorProduct(C, D, A, B), (1, 2), (3, 4), (5, 6))
>>> cg.sort_args_by_name()
CodegenArrayContraction(CodegenArrayTensorProduct(A, B, C, D), (0, 7), (1, 2), (5, 6))
"""
expr = self.expr
if not isinstance(expr, CodegenArrayTensorProduct):
return self
args = expr.args
sorted_data = sorted(enumerate(args), key=lambda x: default_sort_key(x[1]))
pos_sorted, args_sorted = zip(*sorted_data)
reordering_map = {i: pos_sorted.index(i) for i, arg in enumerate(args)}
contraction_tuples = self._get_contraction_tuples()
contraction_tuples = [[(reordering_map[j], k) for j, k in i] for i in contraction_tuples]
c_tp = CodegenArrayTensorProduct(*args_sorted)
new_contr_indices = self._contraction_tuples_to_contraction_indices(
c_tp,
contraction_tuples
)
return CodegenArrayContraction(c_tp, *new_contr_indices)
开发者ID:cklb,项目名称:sympy,代码行数:36,代码来源:array_utils.py
示例5: _sort_key
def _sort_key(arg):
return default_sort_key(arg[0].as_independent(x)[1])
开发者ID:AALEKH,项目名称:sympy,代码行数:2,代码来源:heurisch.py
示例6: _sorted_args
def _sorted_args(self):
from sympy.core.compatibility import default_sort_key
return sorted(self.args, key=lambda w: default_sort_key(w))
开发者ID:Jeyatharsini,项目名称:sympy,代码行数:3,代码来源:add.py
示例7: recurse_expr
def recurse_expr(expr, index_ranges={}):
if expr.is_Mul:
nonmatargs = []
matargs = []
pos_arg = []
pos_ind = []
dlinks = {}
link_ind = []
counter = 0
for arg in expr.args:
arg_symbol, arg_indices = recurse_expr(arg, index_ranges)
if arg_indices is None:
nonmatargs.append(arg_symbol)
continue
i1, i2 = arg_indices
pos_arg.append(arg_symbol)
pos_ind.append(i1)
pos_ind.append(i2)
link_ind.extend([None, None])
if i1 in dlinks:
other_i1 = dlinks[i1]
link_ind[2*counter] = other_i1
link_ind[other_i1] = 2*counter
if i2 in dlinks:
other_i2 = dlinks[i2]
link_ind[2*counter + 1] = other_i2
link_ind[other_i2] = 2*counter + 1
dlinks[i1] = 2*counter
dlinks[i2] = 2*counter + 1
counter += 1
cur_ind_pos = link_ind.index(None)
first_index = pos_ind[cur_ind_pos]
while True:
d = cur_ind_pos // 2
r = cur_ind_pos % 2
if r == 1:
matargs.append(transpose(pos_arg[d]))
else:
matargs.append(pos_arg[d])
next_ind_pos = link_ind[2*d + 1 - r]
if next_ind_pos is None:
last_index = pos_ind[2*d + 1 - r]
break
cur_ind_pos = next_ind_pos
return Mul.fromiter(nonmatargs)*MatMul.fromiter(matargs), (first_index, last_index)
elif expr.is_Add:
res = [recurse_expr(i) for i in expr.args]
res = [
((transpose(i), (j[1], j[0]))
if default_sort_key(j[0]) > default_sort_key(j[1])
else (i, j))
for (i, j) in res
]
addends, last_indices = zip(*res)
last_indices = list(set(last_indices))
if len(last_indices) > 1:
print(last_indices)
raise ValueError("incompatible summation")
return MatAdd.fromiter(addends), last_indices[0]
elif isinstance(expr, KroneckerDelta):
i1, i2 = expr.args
return S.One, (i1, i2)
elif isinstance(expr, MatrixElement):
matrix_symbol, i1, i2 = expr.args
if i1 in index_ranges:
r1, r2 = index_ranges[i1]
if r1 != 0 or matrix_symbol.shape[0] != r2+1:
raise ValueError("index range mismatch: {0} vs. (0, {1})".format(
(r1, r2), matrix_symbol.shape[0]))
if i2 in index_ranges:
r1, r2 = index_ranges[i2]
if r1 != 0 or matrix_symbol.shape[1] != r2+1:
raise ValueError("index range mismatch: {0} vs. (0, {1})".format(
(r1, r2), matrix_symbol.shape[1]))
if (i1 == i2) and (i1 in index_ranges):
return trace(matrix_symbol), None
return matrix_symbol, (i1, i2)
elif isinstance(expr, Sum):
return recurse_expr(
expr.args[0],
index_ranges={i[0]: i[1:] for i in expr.args[1:]}
)
else:
return expr, None
开发者ID:certik,项目名称:sympy,代码行数:84,代码来源:matexpr.py
注:本文中的sympy.core.compatibility.default_sort_key函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论