当前位置: 首页>>代码示例>>Python>>正文


Python pyrsistent.pmap函数代码示例

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


在下文中一共展示了pmap函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

  def __init__(self,agents=pvector([]),times=pset([]),forward=pmap({}),
               costs=pmap({}),requirements=pmap({}),backward=None,
               unsatisfied=None):
    self.cache = {}

    #### schedule bounds
    self.agents = agents  # vector of valid agents
    self.times = times  # set of valid times

    #### the schedule itself
    self.forward = forward  # agents -> times -> meeting ids

    # mids -> meeting (time, agents)
    if backward is None: self.backward = _backward_from_forward(self.forward)
    else: self.backward = backward

    #### schedule constraints
    self.requirements = requirements  # mids -> requirement type -> requirement

    # mids -> requirement type
    if unsatisfied is None:
      self.unsatisfied = pmap({mid: pset(self.requirements[mid].keys())
                               for mid in self.requirements.keys()})
    else: self.unsatisfied = unsatisfied

    self.costs = costs  # map from agents to meeting time costs functions
开发者ID:haberdashPI,项目名称:CSDscheduling,代码行数:26,代码来源:__init__.py

示例2: parse_file

def parse_file(excel_file):
  excel = pd.ExcelFile(excel_file)

  df = excel.parse('Schedule',index_col=0)
  df.columns = clean_up(df.columns)
  times,agents = parse_schedule(df)

  df = excel.parse('Meetings',index_col=None)
  df.columns = clean_up(df.columns)
  del df['area']
  df.name = clean_up(df.name)
  meetings = parse_student_meetings(df,3)

  offset = meetings[-1].mid+1
  df = excel.parse('Lab Meetings',index_col=None)
  df.columns = clean_up(df.columns)
  meetings += parse_lab_meetings(df,offset=offset)

  df = excel.parse('Schedule Preferences')
  df.columns = clean_up(df.columns)
  costs = parse_costs(df)

  final_meetings = {}
  for requirement in meetings:
    old = final_meetings.get(requirement.mid,pset())
    final_meetings[requirement.mid] = old.add(requirement)

  return Schedule(list(agents),pmap(),pmap(times),costs,
                  pmap(final_meetings),pmap())
开发者ID:haberdashPI,项目名称:CSDscheduling,代码行数:29,代码来源:parse.py

示例3: read_schedule_json

def read_schedule_json(obj):
    # reconstruct schedule information from json
    agents = pvector(obj['agents'])
    costs = pmap(obj['costs'])
    times = pset(map(as_timerange,obj['times']))
    forward = pmap({a: pmap({as_timerange(t): int(t['mid'])
                             for t in obj['meetings'][a] if t['mid'] != -1})
                    for a in agents})

    mids = pset([mid for ts in forward.values() for mid in ts.values()])

    # remove the mid 0, which marks an empty meeting (for unavailable times)
    if 0 in mids:
      mids = mids.remove(0)

    # update meetings and their requirements
    requirements = pmap({int(mid): pmap({r['type']: read_jsonable_requirement(r)
                                        for r in rs.values()})
                         for mid,rs in obj['requirements'].iteritems()})

    schedule = Schedule(agents=agents,times=times,forward=forward,
                        requirements=requirements,costs=costs)

    new_unsatisfied = schedule.unsatisfied
    for mid,rs in schedule.unsatisfied.iteritems():
      for rtype in rs:
        r = schedule.requirements[mid][rtype]
        if r.satisfied(schedule):
          new_unsatisfied = _mark_satisfied(new_unsatisfied,r)
        elif not r.satisfiable(schedule):
          raise RequirementException(r)
    schedule.unsatisfied = new_unsatisfied

    return schedule
开发者ID:haberdashPI,项目名称:CSDscheduling,代码行数:34,代码来源:__init__.py

示例4: test_dont_filter_out_non_recently_converged

 def test_dont_filter_out_non_recently_converged(self):
     """
     If a group was converged in the past but not recently, it will be
     cleaned from the ``recently_converged`` map, and it will be converged.
     """
     # g1: converged a while ago; divergent -> removed and converged
     # g2: converged recently; not divergent -> not converged
     # g3: converged a while ago; not divergent -> removed and not converged
     eff = self._converge_all_groups(['00_g1'])
     sequence = [
         (ReadReference(ref=self.currently_converging), lambda i: pset([])),
         (Log('converge-all-groups',
              dict(group_infos=[self.group_infos[0]],
                   currently_converging=[])),
          noop),
         (ReadReference(ref=self.recently_converged),
          lambda i: pmap({'g1': 4, 'g2': 10, 'g3': 0})),
         (Func(time.time), lambda i: 20),
         (ModifyReference(self.recently_converged,
                          match_func("literally anything",
                                     pmap({'g2': 10}))),
          noop),
         parallel_sequence([[self._expect_group_converged('00', 'g1')]])
     ]
     self.assertEqual(perform_sequence(sequence, eff), ['converged g1!'])
开发者ID:pratikmallya,项目名称:otter,代码行数:25,代码来源:test_service.py

示例5: setUp

 def setUp(self):
     self.format = mock.MagicMock(return_value=lambda x: str(x))
     self.label_1 = "a"
     self.label_2 = "b"
     self.true_positive = 8
     self.true_negative = 8
     self.false_positive = 8
     self.false_negative = 8
     self.confusion_table = ConfusionTable(
         self.label_1,
         self.true_positive,
         self.true_negative,
         self.false_positive,
         self.false_negative,
         self.format
     )
     self.predictions = pmap({
         self.label_1: pmap({
             self.label_1: self.true_positive,
             self.label_2: self.false_positive,
         }),
         self.label_2: pmap({
             self.label_1: self.false_negative,
             self.label_2: self.true_negative
         })
     })
开发者ID:RamonAranda,项目名称:ConfusionMatrix,代码行数:26,代码来源:confusion_table_generator_test.py

示例6: merge_results

def merge_results(results):
    """
    Given a list of dictionary results from episodes and the interesting keys, merge them into a single dictionary.
    Example: [{episode_id: 1, steps: 22}, {episode_id: 2, steps: 30}] -> {episode_id: [1, 2], steps: [22, 30]}
    """
    seed_dictionary = pmap({key: v() for key, _ in results[0].items()})
    return pmap(reduce(lambda result1, y: {key: value.append(y[key]) for key, value in result1.items()}, [seed_dictionary] + results))
开发者ID:xanderdunn,项目名称:options,代码行数:7,代码来源:results_writer.py

示例7: test_returns_new_pmap_given_pmap

 def test_returns_new_pmap_given_pmap(self):
     """
     If a PMap is passed in, a new PMap is returned, and even the new value
     that was passed in gets frozen.
     """
     self.assertEquals(set_in(pmap({1: 2}), (1,), {1: 3}),
                       pmap({1: pmap({1: 3})}))
开发者ID:rackerlabs,项目名称:otter,代码行数:7,代码来源:test_fp.py

示例8: test_filters_clb_types

 def test_filters_clb_types(self):
     """
     Only one CLB step is returned per CLB
     """
     steps = pbag([
         AddNodesToCLB(
             lb_id='5',
             address_configs=s(('1.1.1.1',
                                CLBDescription(lb_id='5', port=80)))),
         RemoveNodesFromCLB(lb_id='5', node_ids=s('1')),
         # Unoptimizable step
         CreateServer(server_config=pmap({})),
     ])
     # returned steps could be pbag of any of the 2 lists below depending
     # on how `one_clb_step` iterates over the steps. Since it is pbag the
     # order of elements is not guaranteed
     list1 = [
         AddNodesToCLB(
             lb_id='5',
             address_configs=s(
                 ('1.1.1.1', CLBDescription(lb_id='5', port=80)))),
         CreateServer(server_config=pmap({}))
     ]
     list2 = [
         RemoveNodesFromCLB(lb_id='5', node_ids=s('1')),
         CreateServer(server_config=pmap({}))
     ]
     self.assertEqual(
         matches(MatchesAny(Equals(pbag(list1)), Equals(pbag(list2)))),
         optimize_steps(steps)
     )
开发者ID:rackerlabs,项目名称:otter,代码行数:31,代码来源:test_transforming.py

示例9: test_returns_new_pmap_given_dict

 def test_returns_new_pmap_given_dict(self):
     """
     If a dictionary is passed in, a new PMap is returned and the old
     dictionary is unaffected.
     """
     a = {1: 2}
     self.assertEquals(set_in(a, (1,), {1: 3}), pmap({1: pmap({1: 3})}))
     self.assertEquals(a, {1: 2})
开发者ID:rackerlabs,项目名称:otter,代码行数:8,代码来源:test_fp.py

示例10: test_hash_parameters

 def test_hash_parameters(self):
     self.assertEqual(
         {
             http.MediaRange(type="a", parameters=pmap({"a": "b"})),
             http.MediaRange(type="a", parameters=pmap({"a": "b"})),
         },
         {http.MediaRange(type="a", parameters=pmap({"a": "b"}))},
     )
开发者ID:Julian,项目名称:Minion,代码行数:8,代码来源:test_http.py

示例11: test_set_with_relocation

def test_set_with_relocation():
    x = pmap({'a':1000}, pre_size=1)
    x = x.set('b', 3000)
    x = x.set('c', 4000)
    x = x.set('d', 5000)
    x = x.set('d', 6000)

    assert len(x) == 4
    assert x == pmap({'a': 1000, 'b': 3000, 'c': 4000, 'd': 6000})
开发者ID:alx-,项目名称:pyrsistent,代码行数:9,代码来源:map_test.py

示例12: test_equal_with_different_insertion_order

def test_equal_with_different_insertion_order():
    x = pmap([(i, i) for i in range(50)], 10)
    y = pmap([(i, i) for i in range(49, -1, -1)], 10)

    assert x == y
    assert not (x != y)

    assert y == x
    assert not (y != x)
开发者ID:tobgu,项目名称:pyrsistent,代码行数:9,代码来源:map_test.py

示例13: __init__

 def __init__(self, nodes=None, this_node_uuid=uuid4()):
     self._configured_datasets = pmap()
     self._configured_containers = pmap()
     self._leases = LeasesModel()
     if nodes is None:
         nodes = []
     self._nodes = nodes
     self._this_node_uuid = this_node_uuid
     self.synchronize_state()
开发者ID:Kaffa-MY,项目名称:flocker,代码行数:9,代码来源:_client.py

示例14: test_equal_with_different_bucket_sizes

def test_equal_with_different_bucket_sizes():
    x = pmap({'a': 1, 'b': 2}, 50)
    y = pmap({'a': 1, 'b': 2}, 10)

    assert x == y
    assert not (x != y)

    assert y == x
    assert not (y != x)
开发者ID:tobgu,项目名称:pyrsistent,代码行数:9,代码来源:map_test.py

示例15: test_same_hash_when_content_the_same_but_underlying_vector_size_differs

def test_same_hash_when_content_the_same_but_underlying_vector_size_differs():
    x = pmap(dict((x, x) for x in range(1000)))
    y = pmap({10: 10, 200: 200, 700: 700})

    for z in x:
        if z not in y:
            x = x.remove(z)

    assert x == y
    assert hash(x) == hash(y)
开发者ID:alx-,项目名称:pyrsistent,代码行数:10,代码来源:map_test.py


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