本文整理汇总了Python中pyrsistent.pvector函数的典型用法代码示例。如果您正苦于以下问题:Python pvector函数的具体用法?Python pvector怎么用?Python pvector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pvector函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_cluster
def start_cluster(self, reactor):
# Destroy the box to begin, so that we are guaranteed
# a clean build.
yield run(reactor, ["vagrant", "destroy", "-f"], path=self.vagrant_path.path)
if self.package_source.version:
env = extend_environ(FLOCKER_BOX_VERSION=vagrant_version(self.package_source.version))
else:
env = os.environ
# Boot the VMs
yield run(reactor, ["vagrant", "up"], path=self.vagrant_path.path, env=env)
for node in self.NODE_ADDRESSES:
yield remove_known_host(reactor, node)
nodes = pvector(ManagedNode(address=address, distribution=self.distribution) for address in self.NODE_ADDRESSES)
certificates = Certificates(self.certificates_path)
cluster = Cluster(
all_nodes=pvector(nodes),
control_node=nodes[0],
agent_nodes=nodes,
dataset_backend=self.dataset_backend,
certificates=certificates,
)
returnValue(cluster)
示例2: test_is_hashable
def test_is_hashable(pvector):
from collections import Hashable
v = pvector([1, 2, 3])
v2 = pvector([1, 2, 3])
assert hash(v) == hash(v2)
assert isinstance(pvector(), Hashable)
示例3: multiplier
def multiplier(l, cnt):
if not isinstance(l, pvectorc.PVector):
results = list(map(lambda x: wrapper_fn(map_fn)(x[1], x[0], cnt),
enumerate([l] * cnt)))
return pvector(results)
else:
return pvector(list(map(lambda x: multiplier(x, cnt), l)))
示例4: run_vector_random_access_performance
def run_vector_random_access_performance():
def random_access(o):
result = 0
for x in range(10000):
for y in testdata:
result = o[y]
return result
testdata = [0, 4, 55, 10000, 98763, -2, 30000, 42004, 37289, 100, 2, 999999]
l = range(1000000)
before = time.time()
random_access(l)
print("Random access large list: " + str(time.time() - before))
v = pvector(l)
before = time.time()
random_access(v)
print("Random access large vector: " + str(time.time() - before))
testdata = [0, 4, 17, -2, 3, 7, 8, 11, 1, 13, 18, 10]
l = range(20)
before = time.time()
random_access(l)
print("Random access small list: " + str(time.time() - before))
v = pvector(l)
before = time.time()
random_access(v)
print("Random access small vector: " + str(time.time() - before))
示例5: _create_diffs_for
def _create_diffs_for(current_path, subobj_a, subobj_b):
"""
Computes a series of ``_IDiffChange`` s to turn ``subobj_a`` into
``subobj_b`` assuming that these subobjs are at ``current_path`` inside a
nested pyrsistent object.
:param current_path: An iterable of pyrsistent object describing the path
inside the root pyrsistent object where the other arguments are
located. See ``PMap.transform`` for the format of this sort of path.
:param subobj_a: The desired input sub object.
:param subobj_b: The desired output sub object.
:returns: An iterable of ``_IDiffChange`` s that will turn ``subobj_a``
into ``subobj_b``.
"""
if subobj_a == subobj_b:
return pvector([])
elif type(subobj_a) != type(subobj_b):
return pvector([_Set(path=current_path, value=subobj_b)])
elif isinstance(subobj_a, PClass) and isinstance(subobj_b, PClass):
a_dict = subobj_a._to_dict()
b_dict = subobj_b._to_dict()
return _create_diffs_for_mappings(current_path, a_dict, b_dict)
elif isinstance(subobj_a, PMap) and isinstance(subobj_b, PMap):
return _create_diffs_for_mappings(
current_path, subobj_a, subobj_b)
elif isinstance(subobj_a, PSet) and isinstance(subobj_b, PSet):
return _create_diffs_for_sets(
current_path, subobj_a, subobj_b)
# If the objects are not equal, and there is no intelligent way to recurse
# inside the objects to make a smaller diff, simply set the current path
# to the object in b.
return pvector([_Set(path=current_path, value=subobj_b)])
示例6: test_iterable
def test_iterable(pvector):
"""
PVectors can be created from iterables even though they can't be len()
hinted.
"""
assert pvector(iter("a")) == pvector(iter("a"))
示例7: test_is_hashable
def test_is_hashable(pvector):
from pyrsistent._compat import Hashable
v = pvector([1, 2, 3])
v2 = pvector([1, 2, 3])
assert hash(v) == hash(v2)
assert isinstance(pvector(), Hashable)
示例8: __init__
def __init__(self, node_addresses, package_source, distribution,
dataset_backend, dataset_backend_configuration):
"""
:param list: A ``list`` of public IP addresses or
``[private_address, public_address]`` lists.
See ``ManagedRunner`` and ``ManagedNode`` for other parameter
documentation.
"""
# Blow up if the list contains mixed types.
[address_type] = set(type(address) for address in node_addresses)
if address_type is list:
# A list of 2 item lists
self._nodes = pvector(
ManagedNode(
address=address,
private_address=private_address,
distribution=distribution
)
for (private_address, address) in node_addresses
)
else:
# A list of strings.
self._nodes = pvector(
ManagedNode(address=address, distribution=distribution)
for address in node_addresses
)
self.package_source = package_source
self.dataset_backend = dataset_backend
self.dataset_backend_configuration = dataset_backend_configuration
示例9: test_delete_slice
def test_delete_slice(pvector):
seq = pvector(range(5))
assert seq.delete(1, 4) == pvector([0, 4])
assert seq.delete(4, 1) == seq
assert seq.delete(0, 1) == pvector([1, 2, 3, 4])
assert seq.delete(6, 8) == seq
assert seq.delete(-1, 1) == seq
assert seq.delete(1, -1) == pvector([0, 4])
示例10: test_evolver_set_followed_by_delete
def test_evolver_set_followed_by_delete(pvector):
evolver = pvector([1, 2]).evolver()
evolver[1] = 3
assert [evolver[i] for i in range(len(evolver))] == [1, 3]
del evolver[0]
assert evolver.persistent() == pvector([3])
示例11: finalize_cluster
def finalize_cluster(cluster):
# Make node lists immutable.
return Cluster(
all_nodes=pvector(cluster.all_nodes),
control_node=cluster.node,
agent_nodes=pvector(cluster.agent_nodes),
dataset_backend=cluster.dataset_backend,
default_volume_size=cluster.default_volume_size,
certificates=cluster.certificates,
dataset_backend_config_file=cluster.dataset_backend_config_file,
)
示例12: __init__
def __init__(self, mat, rows, cols):
target_type = {numpy.dtype('int8'): numpy.dtype('int64'),
numpy.dtype('int16'): numpy.dtype('int64'),
numpy.dtype('int32'): numpy.dtype('int64'),
numpy.dtype('int64'): numpy.dtype('int64'),
numpy.dtype('float16'): numpy.dtype('float32'),
numpy.dtype('float32'): numpy.dtype('float32'),
numpy.dtype('float64'): numpy.dtype('float64')}
self._matrix = mat.astype(target_type[mat.dtype])
self._rows = pvector(rows)
self._columns = pvector(cols)
示例13: test_delete_of_non_existing_element
def test_delete_of_non_existing_element(pvector):
e = pvector([1, 2]).evolver()
with pytest.raises(IndexError):
del e[2]
del e[0]
del e[0]
with pytest.raises(IndexError):
del e[0]
assert e.persistent() == pvector()
示例14: test_repeat
def test_repeat(pvector):
v = pvector([1, 2])
assert 5 * pvector() is pvector()
assert v is 1 * v
assert 0 * v is pvector()
assert 2 * pvector([1, 2]) == pvector([1, 2, 1, 2])
assert -3 * pvector([1, 2]) is pvector()
示例15: finalize_cluster
def finalize_cluster(cluster):
"""
:param Cluster cluster: Description of the cluster.
:return: Cluster
"""
# Make node lists immutable.
return Cluster(
all_nodes=pvector(cluster.all_nodes),
control_node=cluster.node,
agent_nodes=pvector(cluster.agent_nodes),
dataset_backend=cluster.dataset_backend,
default_volume_size=cluster.default_volume_size,
certificates=cluster.certificates,
dataset_backend_config_file=cluster.dataset_backend_config_file
)