本文整理汇总了Python中operator.pos方法的典型用法代码示例。如果您正苦于以下问题:Python operator.pos方法的具体用法?Python operator.pos怎么用?Python operator.pos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类operator
的用法示例。
在下文中一共展示了operator.pos方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _add_numeric_methods_unary
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def _add_numeric_methods_unary(cls):
"""
Add in numeric unary methods.
"""
def _make_evaluate_unary(op, opstr):
def _evaluate_numeric_unary(self):
self._validate_for_numeric_unaryop(op, opstr)
attrs = self._get_attributes_dict()
attrs = self._maybe_update_attributes(attrs)
return Index(op(self.values), **attrs)
_evaluate_numeric_unary.__name__ = opstr
return _evaluate_numeric_unary
cls.__neg__ = _make_evaluate_unary(operator.neg, '__neg__')
cls.__pos__ = _make_evaluate_unary(operator.pos, '__pos__')
cls.__abs__ = _make_evaluate_unary(np.abs, '__abs__')
cls.__inv__ = _make_evaluate_unary(lambda x: -x, '__inv__')
示例2: _add_numeric_methods_unary
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def _add_numeric_methods_unary(cls):
""" add in numeric unary methods """
def _make_evaluate_unary(op, opstr):
def _evaluate_numeric_unary(self):
self._validate_for_numeric_unaryop(op, opstr)
attrs = self._get_attributes_dict()
attrs = self._maybe_update_attributes(attrs)
return Index(op(self.values), **attrs)
return _evaluate_numeric_unary
cls.__neg__ = _make_evaluate_unary(operator.neg, '__neg__')
cls.__pos__ = _make_evaluate_unary(operator.pos, '__pos__')
cls.__abs__ = _make_evaluate_unary(np.abs, '__abs__')
cls.__inv__ = _make_evaluate_unary(lambda x: -x, '__inv__')
示例3: p_unary_operator
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def p_unary_operator(p):
'''unary_operator : '&'
| '*'
| '+'
| '-'
| '~'
| '!'
'''
# reduces to (op, op_str)
p[0] = ({
'+': operator.pos,
'-': operator.neg,
'~': operator.inv,
'!': operator.not_,
'&': 'AddressOfUnaryOperator',
'*': 'DereferenceUnaryOperator'}[p[1]], p[1])
示例4: delete_edge
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def delete_edge(G, edge, h):
"""
Given a graph G and one of its edges in tuple form, checks if the deletion
splits the graph.
"""
tup = G.es[edge].tuple
# logging.info("Deleted: %s", tup)
neighborhood = get_neighborhood_edge(G, tup, h)
# subtracts local betweennesses in the region, as discussed
# in the paper
do_local_betweenness(G, neighborhood, h, operator.neg)
G.delete_edges(edge)
fix_betweennesses(G)
# adds back in local betweennesses after the deletion
do_local_betweenness(G, neighborhood, h, operator.pos)
return check_for_split(G, tup)
示例5: split_vertex
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def split_vertex(G, vToSplit, instr, h):
"""
Splits the vertex v into two new vertices, each with
edges depending on s. Returns True if the split
divided the graph, else False.
"""
neighborhood = get_neighborhood_vertex(G, vToSplit, h)
do_local_betweenness(G, neighborhood, h, operator.neg)
new_index = G.vcount()
G.add_vertex()
G.vs[new_index]['CONGA_orig'] = G.vs[vToSplit]['CONGA_orig']
G.vs[new_index]['pb'] = {uw : 0 for uw in itertools.combinations(G.neighbors(vToSplit), 2)}
# adding all relevant edges to new vertex, deleting from old one.
toAdd = list(zip(itertools.repeat(new_index), instr[0]))
toDelete = list(zip(itertools.repeat(vToSplit), instr[0]))
G.add_edges(toAdd)
G.delete_edges(toDelete)
neighborhood.append(new_index)
fix_betweennesses(G)
# logging.info("split: %d, %s", vToSplit, instr)
do_local_betweenness(G, neighborhood, h, operator.pos)
# check if the two new vertices are disconnected.
return check_for_split(G, (vToSplit, new_index))
示例6: do_local_betweenness
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def do_local_betweenness(G, neighborhood, h, op=operator.pos):
"""
Given a neighborhood and depth h, recalculates all betweennesses
confined to the neighborhood. If op is operator.neg, it subtracts these
betweennesses from the current ones. Otherwise, it adds them.
"""
all_pairs_shortest_paths = []
pathCounts = Counter()
for i, v in enumerate(neighborhood):
s_s_shortest_paths = G.get_all_shortest_paths(v, to=neighborhood)#[i+1:])
all_pairs_shortest_paths += s_s_shortest_paths
neighSet = set(neighborhood)
neighSize = len(neighborhood)
apsp = []
for path in all_pairs_shortest_paths:
# path does not go out of region
if len(neighSet | set(path)) == neighSize:
pathCounts[(path[0], path[-1])] += 1 # can improve
apsp.append(path)
for path in apsp:
if len(path) <= h + 1:
update_betweenness(G, path, pathCounts[(path[0], path[-1])], op)
示例7: testNeg
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def testNeg(self):
self.unaryCheck(operator.pos)
示例8: test_unary_methods
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def test_unary_methods(self):
array = np.array([-1, 0, 1, 2])
array_like = ArrayLike(array)
for op in [operator.neg,
operator.pos,
abs,
operator.invert]:
_assert_equal_type_and_value(op(array_like), ArrayLike(op(array)))
示例9: test_positive_on_non_number
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def test_positive_on_non_number(self):
self.assert_deprecated(operator.pos, args=(np.array('foo'),))
示例10: _add_unary_ops
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def _add_unary_ops(cls):
cls.__pos__ = cls._create_unary_method(operator.pos)
cls.__neg__ = cls._create_unary_method(operator.neg)
cls.__invert__ = cls._create_unary_method(operator.invert)
示例11: _searchsorted_monotonic
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def _searchsorted_monotonic(self, label, side='left'):
if self.is_monotonic_increasing:
return self.searchsorted(label, side=side)
elif self.is_monotonic_decreasing:
# np.searchsorted expects ascending sort order, have to reverse
# everything for it to work (element ordering, search side and
# resulting value).
pos = self[::-1].searchsorted(label, side='right' if side == 'left'
else 'left')
return len(self) - pos
raise ValueError('index must be monotonic increasing or decreasing')
示例12: positive
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def positive(x, **_):
return operator.pos(x)
示例13: __pos__
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def __pos__(self):
return NonStandardInteger(operator.pos(self.val))
示例14: test_pos
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def test_pos(self):
self.assertRaises(TypeError, operator.pos)
self.assertRaises(TypeError, operator.pos, None)
self.assertTrue(operator.pos(5) == 5)
self.assertTrue(operator.pos(-5) == -5)
self.assertTrue(operator.pos(0) == 0)
self.assertTrue(operator.pos(-0) == 0)
示例15: test_starmap
# 需要导入模块: import operator [as 别名]
# 或者: from operator import pos [as 别名]
def test_starmap():
yield verify_same, starmap, itertools.starmap, None, pos
yield verify_same, starmap, itertools.starmap, None, pos, []
yield (verify_same, starmap, itertools.starmap, None, add,
[(5, 9), [4, 2]])
yield (verify_pickle, starmap, itertools.starmap, 2, 0, add,
[(5, 9), [4, 2]])
yield (verify_pickle, starmap, itertools.starmap, 2, 1, add,
[(5, 9), [4, 2]])