Example #1
0
    def test_sum_overlapping_m(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 = max(step, 1) + random.choice([0, 1, randint(10)])
            depth = width - 1
            assert depth >= 0
            overlap = width - step
            mat_size = num_contribs * step + overlap

            contribs = randn(num_contribs, width, width)
            target_bm = gen_BandMat(mat_size, l=depth, u=depth)
            target_bm_orig = target_bm.copy()

            mat_bm = bmo.sum_overlapping_m(contribs, step=step)
            assert mat_bm.size == mat_size
            assert mat_bm.l == mat_bm.u == depth

            # check target-based version adds to target_bm correctly
            bmo.sum_overlapping_m(contribs, step=step, target_bm=target_bm)
            assert_allclose(*cc(target_bm, target_bm_orig + mat_bm))

            if num_contribs == 0:
                # check action for no contributions
                assert_allequal(mat_bm.full(), np.zeros((overlap, overlap)))
            elif num_contribs == 1:
                # check action for a single contribution
                assert_allequal(mat_bm.full(), contribs[0])
            else:
                # check action under splitting list of contributions in two
                split_pos = randint(num_contribs + 1)
                mat_bm_again = bm.zeros(depth, depth, mat_size)
                bmo.sum_overlapping_m(
                    contribs[:split_pos],
                    step=step,
                    target_bm=mat_bm_again.sub_matrix_view(
                        0, split_pos * step + overlap
                    )
                )
                bmo.sum_overlapping_m(
                    contribs[split_pos:],
                    step=step,
                    target_bm=mat_bm_again.sub_matrix_view(
                        split_pos * step, mat_size
                    )
                )
                assert_allclose(*cc(mat_bm, mat_bm_again))
Example #2
0
    def test_sum_overlapping_m_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 = max(step, 1) + random.choice([0, 1, randint(10)])
            depth = width - 1
            assert depth >= 0
            overlap = width - step
            mat_size = num_contribs * step + overlap

            contribs = randn(num_contribs, width, width)
            contribs_chunks = chunk_randomly(contribs)
            target_bm = gen_BandMat(mat_size, l=depth, u=depth)
            target_bm_orig = target_bm.copy()

            bmo.sum_overlapping_m_chunked(
                contribs_chunks, target_bm, step=step
            )
            mat_bm_good = bmo.sum_overlapping_m(contribs, step=step)
            assert_allclose(*cc(target_bm, target_bm_orig + mat_bm_good))
Example #3
0
    def test_sum_overlapping_m_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 = max(step, 1) + random.choice([0, 1, randint(10)])
            depth = width - 1
            assert depth >= 0
            overlap = width - step
            mat_size = num_contribs * step + overlap

            contribs = randn(num_contribs, width, width)
            contribs_chunks = chunk_randomly(contribs)
            target_bm = gen_BandMat(mat_size, l=depth, u=depth)
            target_bm_orig = target_bm.copy()

            bmo.sum_overlapping_m_chunked(contribs_chunks,
                                          target_bm,
                                          step=step)
            mat_bm_good = bmo.sum_overlapping_m(contribs, step=step)
            assert_allclose(*cc(target_bm, target_bm_orig + mat_bm_good))
Example #4
0
    def test_sum_overlapping_m(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 = max(step, 1) + random.choice([0, 1, randint(10)])
            depth = width - 1
            assert depth >= 0
            overlap = width - step
            mat_size = num_contribs * step + overlap

            contribs = randn(num_contribs, width, width)
            target_bm = gen_BandMat(mat_size, l=depth, u=depth)
            target_bm_orig = target_bm.copy()

            mat_bm = bmo.sum_overlapping_m(contribs, step=step)
            assert mat_bm.size == mat_size
            assert mat_bm.l == mat_bm.u == depth

            # check target-based version adds to target_bm correctly
            bmo.sum_overlapping_m(contribs, step=step, target_bm=target_bm)
            assert_allclose(*cc(target_bm, target_bm_orig + mat_bm))

            if num_contribs == 0:
                # check action for no contributions
                assert_allequal(mat_bm.full(), np.zeros((overlap, overlap)))
            elif num_contribs == 1:
                # check action for a single contribution
                assert_allequal(mat_bm.full(), contribs[0])
            else:
                # check action under splitting list of contributions in two
                split_pos = randint(num_contribs + 1)
                mat_bm_again = bm.zeros(depth, depth, mat_size)
                bmo.sum_overlapping_m(contribs[:split_pos],
                                      step=step,
                                      target_bm=mat_bm_again.sub_matrix_view(
                                          0, split_pos * step + overlap))
                bmo.sum_overlapping_m(contribs[split_pos:],
                                      step=step,
                                      target_bm=mat_bm_again.sub_matrix_view(
                                          split_pos * step, mat_size))
                assert_allclose(*cc(mat_bm, mat_bm_again))