• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pyrsistent.pvector函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyrsistent.pvector函数的典型用法代码示例。如果您正苦于以下问题:Python pvector函数的具体用法?Python pvector怎么用?Python pvector使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pvector函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:scollison,项目名称:flocker,代码行数:27,代码来源:acceptance.py


示例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)
开发者ID:RichardFreeman,项目名称:pyrsistent,代码行数:7,代码来源:vector_test.py


示例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)))
开发者ID:phizaz,项目名称:seeding-strategy-ssl,代码行数:7,代码来源:pipe.py


示例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))
开发者ID:ClusterHQ,项目名称:pyrsistent,代码行数:32,代码来源:performance_run.py


示例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)])
开发者ID:BenjaminSchiborr,项目名称:flocker,代码行数:35,代码来源:_diffing.py


示例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"))
开发者ID:tobgu,项目名称:pyrsistent,代码行数:7,代码来源:vector_test.py


示例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)
开发者ID:tobgu,项目名称:pyrsistent,代码行数:7,代码来源:vector_test.py


示例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
开发者ID:uedzen,项目名称:flocker,代码行数:30,代码来源:acceptance.py


示例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])
开发者ID:RichardFreeman,项目名称:pyrsistent,代码行数:8,代码来源:vector_test.py


示例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])
开发者ID:ClusterHQ,项目名称:pyrsistent,代码行数:9,代码来源:vector_test.py


示例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,
     )
开发者ID:tjb1019,项目名称:flocker,代码行数:11,代码来源:cluster_setup.py


示例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)
开发者ID:vputz,项目名称:marion-biblio,代码行数:11,代码来源:bibliomatrix.py


示例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()
开发者ID:ClusterHQ,项目名称:pyrsistent,代码行数:13,代码来源:vector_test.py


示例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()
开发者ID:RichardFreeman,项目名称:pyrsistent,代码行数:7,代码来源:vector_test.py


示例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
     )
开发者ID:ClusterHQ,项目名称:flocker,代码行数:15,代码来源:cluster_setup.py


示例16: test_command_line

    def test_command_line(self):
        """
        A container with custom command line is run with those arguments.
        """
        external_port = find_free_port()[1]
        name = random_name(self)
        d = self.start_container(
            name, image_name=u"busybox",
            # Pass in pvector since this likely to be what caller actually
            # passes in:
            command_line=pvector([u"sh", u"-c", u"""\
echo -n '#!/bin/sh
echo -n "HTTP/1.1 200 OK\r\n\r\nhi"
' > /tmp/script.sh;
chmod +x /tmp/script.sh;
nc -ll -p 8080 -e /tmp/script.sh
"""]),
            ports=[PortMap(internal_port=8080,
                           external_port=external_port)])

        d.addCallback(
            lambda ignored: self.request_until_response(external_port))

        def started(response):
            d = content(response)
            d.addCallback(lambda body: self.assertEqual(b"hi", body))
            return d
        d.addCallback(started)
        return d
开发者ID:Kaffa-MY,项目名称:flocker,代码行数:29,代码来源:test_docker.py


示例17: test_empty_initialization

def test_empty_initialization(pvector):
    seq = pvector()
    assert len(seq) == 0

    with pytest.raises(IndexError) as error:
        x = seq[0]
    assert str(error.value) == 'Index out of range: 0'
开发者ID:RichardFreeman,项目名称:pyrsistent,代码行数:7,代码来源:vector_test.py


示例18: decode

def decode(obj):
    if isinstance(obj, ExtType):
        if obj.code == TYPE_PSET:
            unpacked_data = unpackb(obj.data,
                                    use_list=False,
                                    encoding='utf-8')
            return pset(decode(item) for item in unpacked_data)
        if obj.code == TYPE_PLIST:
            unpacked_data = unpackb(obj.data,
                                    use_list=False,
                                    encoding='utf-8')
            return plist(decode(item) for item in unpacked_data)
        if obj.code == TYPE_PBAG:
            unpacked_data = unpackb(obj.data,
                                    use_list=False,
                                    encoding='utf-8')
            return pbag(decode(item) for item in unpacked_data)
        module_name, class_name, *data = unpackb(obj.data,
                                                 use_list=False,
                                                 encoding='utf-8')
        cls = getattr(sys.modules[module_name],
                      class_name)
        return cls(*(decode(item) for item in data))
    if isinstance(obj, tuple):
        return pvector(decode(item) for item in obj)
    if isinstance(obj, dict):
        new_dict = dict()
        for key in obj.keys():
            new_dict[decode(key)] = decode(obj[key])
        return pmap(new_dict)
    return obj
开发者ID:tlvu,项目名称:mochi,代码行数:31,代码来源:actor.py


示例19: _create_diffs_for_sets

def _create_diffs_for_sets(current_path, set_a, set_b):
    """
    Computes a series of ``_IDiffChange`` s to turn ``set_a`` into ``set_b``
    assuming that these sets 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 set_a: The desired input set.

    :param set_b: The desired output set.

    :returns: An iterable of ``_IDiffChange`` s that will turn ``set_a`` into
        ``set_b``.
    """
    resulting_diffs = pvector([]).evolver()
    for item in set_a.difference(set_b):
        resulting_diffs.append(
            _Remove(path=current_path, item=item)
        )
    for item in set_b.difference(set_a):
        resulting_diffs.append(
            _Add(path=current_path, item=item)
        )
    return resulting_diffs.persistent()
开发者ID:332054781,项目名称:flocker,代码行数:27,代码来源:_diffing.py


示例20: traverse

def traverse(structure, leave=Move, flat=pyrsistent.pvector()):
    for item in structure:
        if isinstance(item, leave):
            flat = flat.append(item)
        else:
            flat = traverse(item, leave, flat)
    return flat
开发者ID:czosel,项目名称:code-ballet,代码行数:7,代码来源:tower-of-hanio.py



注:本文中的pyrsistent.pvector函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pyrsistent.s函数代码示例发布时间:2022-05-27
下一篇:
Python pyrsistent.pset函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap