Esempio n. 1
0
    def test_sum_overlapping_v_chunked(self, its=50):
        for it in range(its):
            num_contribs = random.choice([0, 1, randint(10), randint(100)])
            step = random.choice([1, randint(2), randint(10)])
            width = step + random.choice([0, 1, randint(10)])
            overlap = width - step
            vec_size = num_contribs * step + overlap

            contribs = randn(num_contribs, width)
            contribs_chunks = chunk_randomly(contribs)
            target = randn(vec_size)
            target_orig = target.copy()

            bmo.sum_overlapping_v_chunked(
                contribs_chunks, width, target, step=step
            )
            vec_good = bmo.sum_overlapping_v(contribs, step=step)
            assert_allclose(target, target_orig + vec_good)
Esempio n. 2
0
    def test_sum_overlapping_v_chunked(self, its=50):
        for it in range(its):
            num_contribs = random.choice([0, 1, randint(10), randint(100)])
            step = random.choice([1, randint(2), randint(10)])
            width = step + random.choice([0, 1, randint(10)])
            overlap = width - step
            vec_size = num_contribs * step + overlap

            contribs = randn(num_contribs, width)
            contribs_chunks = chunk_randomly(contribs)
            target = randn(vec_size)
            target_orig = target.copy()

            bmo.sum_overlapping_v_chunked(contribs_chunks,
                                          width,
                                          target,
                                          step=step)
            vec_good = bmo.sum_overlapping_v(contribs, step=step)
            assert_allclose(target, target_orig + vec_good)
Esempio n. 3
0
    def test_sum_overlapping_v(self, its=50):
        for it in range(its):
            num_contribs = random.choice([0, 1, randint(10), randint(100)])
            step = random.choice([1, randint(2), randint(10)])
            width = step + random.choice([0, 1, randint(10)])
            overlap = width - step
            vec_size = num_contribs * step + overlap

            contribs = randn(num_contribs, width)
            target = randn(vec_size)
            target_orig = target.copy()

            vec = bmo.sum_overlapping_v(contribs, step=step)
            assert vec.shape == (vec_size,)

            # check target-based version adds to target correctly
            bmo.sum_overlapping_v(contribs, step=step, target=target)
            assert_allclose(target, target_orig + vec)

            if num_contribs == 0:
                # check action for no contributions
                assert_allequal(vec, np.zeros((overlap,)))
            elif num_contribs == 1:
                # check action for a single contribution
                assert_allequal(vec, contribs[0])
            else:
                # check action under splitting list of contributions in two
                split_pos = randint(num_contribs + 1)
                vec_again = np.zeros((vec_size,))
                bmo.sum_overlapping_v(
                    contribs[:split_pos],
                    step=step,
                    target=vec_again[0:(split_pos * step + overlap)]
                )
                bmo.sum_overlapping_v(
                    contribs[split_pos:],
                    step=step,
                    target=vec_again[(split_pos * step):vec_size]
                )
                assert_allclose(vec, vec_again)
Esempio n. 4
0
    def test_sum_overlapping_v(self, its=50):
        for it in range(its):
            num_contribs = random.choice([0, 1, randint(10), randint(100)])
            step = random.choice([1, randint(2), randint(10)])
            width = step + random.choice([0, 1, randint(10)])
            overlap = width - step
            vec_size = num_contribs * step + overlap

            contribs = randn(num_contribs, width)
            target = randn(vec_size)
            target_orig = target.copy()

            vec = bmo.sum_overlapping_v(contribs, step=step)
            assert vec.shape == (vec_size, )

            # check target-based version adds to target correctly
            bmo.sum_overlapping_v(contribs, step=step, target=target)
            assert_allclose(target, target_orig + vec)

            if num_contribs == 0:
                # check action for no contributions
                assert_allequal(vec, np.zeros((overlap, )))
            elif num_contribs == 1:
                # check action for a single contribution
                assert_allequal(vec, contribs[0])
            else:
                # check action under splitting list of contributions in two
                split_pos = randint(num_contribs + 1)
                vec_again = np.zeros((vec_size, ))
                bmo.sum_overlapping_v(contribs[:split_pos],
                                      step=step,
                                      target=vec_again[0:(split_pos * step +
                                                          overlap)])
                bmo.sum_overlapping_v(contribs[split_pos:],
                                      step=step,
                                      target=vec_again[(split_pos *
                                                        step):vec_size])
                assert_allclose(vec, vec_again)