Example #1
0
    def test_clip(self):

        v = BlockVector(3)
        v2 = BlockVector(3)
        a = np.zeros(5)
        b = np.ones(3)*5.0
        c = np.ones(3)*10.0

        v[0] = a
        v[1] = b
        v[2] = c

        v2[0] = np.ones(5) * 4.0
        v2[1] = np.ones(3) * 5.0
        v2[2] = np.ones(3) * 9.0

        vv = v.clip(4.0, 9.0)
        self.assertEqual(vv.nblocks, v.nblocks)
        for bid, blk in enumerate(vv):
            self.assertTrue(np.allclose(blk, v2[bid]))

        with self.assertRaises(NotImplementedError) as ctx:
            vv = v.clip(4.0, 9.0, out=v2)
Example #2
0
    def test_clip(self):

        v = BlockVector(3)
        v2 = BlockVector(3)
        a = np.zeros(5)
        b = np.ones(3) * 5.0
        c = np.ones(3) * 10.0

        v.set_block(0, a)
        v.set_block(1, b)
        v.set_block(2, c)

        v2.set_block(0, np.ones(5) * 4.0)
        v2.set_block(1, np.ones(3) * 5.0)
        v2.set_block(2, np.ones(3) * 9.0)

        vv = v.clip(4.0, 9.0)
        self.assertEqual(vv.nblocks, v.nblocks)
        for bid, blk in enumerate(vv):
            self.assertTrue(np.allclose(blk, v2.get_block(bid)))