Пример #1
0
 def test_recursive(self):
     inp = list('abc')
     out = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]
     self.assertEqual(
         out,
         accumulate(inp,
                    lambda x: accumulate(list('123'), lambda y: x + y)))
Пример #2
0
 def test_recursive(self):
     inp = ['a', 'b', 'c']
     out = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]
     self.assertEqual(
         accumulate(inp,
                    lambda x: accumulate(list('123'), lambda y: x + y)),
         out)
Пример #3
0
 def RealApply(self, x, y):
     with tm.TimeMonitor("Destriping Local Operations"):
         sig = np.repeat(x.array[0], self.BaselineLengths)
         self.tmap_local[:]=0
     with tm.TimeMonitor("Destriping Comm Operations"):
         bin_map(self.pix, sig, self.tmap_local, self.tmap_glob, self.hits_glob, self.comm, broadcast_locally=True)
     with tm.TimeMonitor("Destriping Local Operations"):
         signalremoveti(sig, self.tmap_local.array, self.pix)
         accumulate(sig, self.BaselineLengths, y.array[0])
     return 0
Пример #4
0
 def RealApply(self, x, y):
     # baseline to tod
     sig = {}
     with tm.TimeMonitor("Destriping Local Operations"):
         sig['Q'] = np.repeat(x.array[0][:self.NumBaselines], self.BaselineLengths)
         sig['U'] = np.repeat(x.array[0][self.NumBaselines:], self.BaselineLengths)
     self.SignalRemove(sig)
     # tod to baseline
     with tm.TimeMonitor("Destriping Local Operations"):
         accumulate(sig['Q'], self.BaselineLengths, y.array[0][:self.NumBaselines])
         accumulate(sig['U'], self.BaselineLengths, y.array[0][self.NumBaselines:])
     return 0
    def __call__(self, seq, init=None, func=None):
        if init: self.init = init

        def bi_op(a, b):
            if func:
                return self.bi_op(a, b, f=func)
            else:
                return self.bi_op(a, b)

        if self.save_state:
            self.init = accumulate(bi_op, self.init, seq)
            return self.init
        else:
            return accumulate(bi_op, self.init, seq)
Пример #6
0
 def test_composition(self):
     inp = [10, 17, 23]
     self.assertEqual(
         inp,
         accumulate(accumulate(inp, lambda x: divmod(x, 7)),
                    lambda x: 7 * x[0] + x[1]))
Пример #7
0
 def test_pow(self):
     self.assertEqual([1, 4, 9, 16, 25], accumulate([1, 2, 3, 4, 5],
                      lambda x: x * x))
Пример #8
0
 def test_recursive(self):
     inp = list('abc')
     out = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]
     self.assertEqual(out, accumulate(inp, lambda x: accumulate(list('123'),
                      lambda y: x + y)))
Пример #9
0
 def test_composition(self):
     inp = [10, 17, 23]
     self.assertEqual(inp, accumulate(accumulate(inp, lambda x: divmod(x, 7)),
                      lambda x: 7 * x[0] + x[1]))
Пример #10
0
 def test_divmod(self):
     self.assertEqual(accumulate([10, 17, 23], lambda x: divmod(x, 7)),
                      [(1, 3), (2, 3), (3, 2)])
Пример #11
0
 def test_divmod(self):
     self.assertEqual(
         accumulate([10, 17, 23], lambda x: divmod(x, 7)),
         [(1, 3), (2, 3), (3, 2)])
Пример #12
0
import numpy
import accumulate

if __name__ == "__main__":
    numpy_array = numpy.array([-1, -2])
    a = [1, 2, 4, 6]
    result = accumulate.accumulate(a)
    print(result)
Пример #13
0
 def test_composition(self):
     inp = [10, 17, 23]
     fn1 = lambda x: divmod(x, 7)
     fn2 = lambda x: 7 * x[0] + x[1]
     self.assertEqual(inp, accumulate(accumulate(inp, fn1), fn2))
Пример #14
0
def count_leaves(tree):
    return accu.accumulate(lambda x, y: 1 + y, 0,
                           list(map(lambda x: 1, enumerate_tree(tree))))
Пример #15
0
 def test_empty_sequence(self):
     self.assertEqual(accumulate([], lambda x: x / 2), [])
Пример #16
0
 def test_capitalize(self):
     self.assertEqual(
         accumulate(['hello', 'world'], str.upper), ['HELLO', 'WORLD'])
Пример #17
0
 class Test:
     x = accumulate([1, 2])
Пример #18
0
 def test_recursive(self):
     inp = ['a', 'b', 'c']
     out = [['a1', 'a2', 'a3'], ['b1', 'b2', 'b3'], ['c1', 'c2', 'c3']]
     self.assertEqual(
         accumulate(
             inp, lambda x: accumulate(list('123'), lambda y: x + y)), out)
Пример #19
0
 def test_capitalize(self):
     self.assertEqual(accumulate(['hello', 'world'], str.upper),
                      ['HELLO', 'WORLD'])
Пример #20
0
                                 data['q_channel_w']['U'],
                                 data['u_channel_w']['Q'],
                                 data['u_channel_w']['U'], pix)
                except exceptions.ValueError:  # byteswap in case input h5 has wrong endianness
                    signalremove(
                        signal_removed['Q'], signal_removed['U'],
                        data['Q'].byteswap().newbyteorder().astype(np.float32),
                        data['U'].byteswap().newbyteorder().astype(np.float32),
                        tmap_local.array, umap_local.array,
                        data['q_channel_w']['Q'], data['q_channel_w']['U'],
                        data['u_channel_w']['Q'], data['u_channel_w']['U'],
                        pix)

                assert len(baseline_lengths) == len(
                    RHS.array[0][:num_baselines])
                accumulate(signal_removed['Q'], baseline_lengths,
                           RHS.array[0][:num_baselines])
                assert len(baseline_lengths) == len(
                    RHS.array[0][num_baselines:])
                accumulate(signal_removed['U'], baseline_lengths,
                           RHS.array[0][num_baselines:])
            else:
                l.info("Bin maps")
                bin_map(pix,
                        data['T'],
                        tmap_local,
                        tmap_glob,
                        hits_glob,
                        comm,
                        broadcast_locally=True)
                tmap_glob[hits_glob == 0] = hp.UNSEEN
                l.info("Write maps")
Пример #21
0
 def test_divmod(self):
     inp = [10, 17, 23]
     out = [(1, 3), (2, 3), (3, 2)]
     self.assertEqual(out, accumulate(inp, lambda x: divmod(x, 7)))
Пример #22
0
def horner_eval(x, coefficient_sequence):
    return accu.accumulate(
        lambda this_coeff, higher_terms: this_coeff + op.mul(x, higher_terms),
        0, coefficient_sequence)
Пример #23
0
 def test_capitalize(self):
     inp = ['hello', 'world']
     out = ['HELLO', 'WORLD']
     self.assertEqual(out, accumulate(inp, str.upper))
Пример #24
0
def _append(seq1, seq2):
    # 这里的lambda x,y:op.add([x], y), 在lisp中只需cons
    return accu.accumulate(lambda x, y: op.add([x], y), seq2, seq1)
Пример #25
0
 def test_empty_sequence(self):
     self.assertEqual([], accumulate([], lambda x: x / 2))
Пример #26
0
def _length(seq):
    return accu.accumulate(lambda x, y: op.add(1, y), 0, seq)
Пример #27
0
 def test_divmod(self):
     inp = [10, 17, 23]
     out = [(1, 3), (2, 3), (3, 2)]
     self.assertEqual(out, accumulate(inp, lambda x: divmod(x, 7)))
Пример #28
0
def _map(proc, seq):
    return accu.accumulate(lambda x, y: op.add([proc(x)], y), [], seq)
Пример #29
0
 def test_capitalize(self):
     inp = ['hello', 'world']
     out = ['HELLO', 'WORLD']
     self.assertEqual(out, accumulate(inp, str.upper))
Пример #30
0
def dot_product(v, w):
    return ac.accumulate(op.add,
                         0,
                         list(map(op.mul, v, w)))
Пример #31
0
 def test_pow(self):
     self.assertEqual([1, 4, 9, 16, 25],
                      accumulate([1, 2, 3, 4, 5], lambda x: x * x))
 def test_composition(self):
     inp = [10, 17, 23]
     fn1 = lambda x: divmod(x, 7)
     fn2 = lambda x: 7*x[0]+x[1]
     self.assertEqual(inp, accumulate(accumulate(inp, fn1), fn2))
Пример #33
0
 def test_pow(self):
     self.assertEqual(accumulate([1, 2, 3, 4], lambda x: x * x),
                      [1, 4, 9, 16])
Пример #34
0
def accumulate_n(op, init, seqs):
    # 每个序列等长度,所以如果第一个处理完了,意味着都处理完了
    if len(seqs[0]) == 0: return []
    return funcs._append(
        [accu.accumulate(op, init, list(map(lambda seq: seq[0], seqs)))],
        accumulate_n(op, init, list(map(lambda seq: seq[1:], seqs))))