Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_to_int(self):
locs = [0, 10]
lengths = [4, 6]
exp_inds = [0, 1, 2, 3, 10, 11, 12, 13, 14, 15]
block = BlockIndex(20, locs, lengths)
dense = block.to_int()
assert_equal(dense.indices, exp_inds)
def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
xindex = BlockIndex(TEST_LENGTH, xloc, xlen)
yindex = BlockIndex(TEST_LENGTH, yloc, ylen)
result = xindex.intersect(yindex)
self.assert_(isinstance(result, BlockIndex))
assert_equal(result.blocs, eloc)
assert_equal(result.blengths, elen)
def test_check_integrity(self):
locs = []
lengths = []
# 0-length OK
index = BlockIndex(0, locs, lengths)
# also OK even though empty
index = BlockIndex(1, locs, lengths)
# block extend beyond end
self.assertRaises(Exception, BlockIndex, 10, [5], [10])
# block overlap
self.assertRaises(Exception, BlockIndex, 10, [2, 5], [5, 3])
def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
xindex = BlockIndex(TEST_LENGTH, xloc, xlen).to_int()
yindex = BlockIndex(TEST_LENGTH, yloc, ylen).to_int()
expected = BlockIndex(TEST_LENGTH, eloc, elen).to_int()
result = xindex.intersect(yindex)
self.assert_(isinstance(result, IntIndex))
assert_equal(result.indices, expected.indices)
def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
xindex = BlockIndex(TEST_LENGTH, xloc, xlen).to_int()
yindex = BlockIndex(TEST_LENGTH, yloc, ylen).to_int()
expected = BlockIndex(TEST_LENGTH, eloc, elen).to_int()
result = xindex.intersect(yindex)
self.assert_(isinstance(result, IntIndex))
assert_equal(result.indices, expected.indices)
def _check_case(xloc, xlen, yloc, ylen):
xindex = BlockIndex(TEST_LENGTH, xloc, xlen)
yindex = BlockIndex(TEST_LENGTH, yloc, ylen)
xdindex = xindex.to_int()
ydindex = yindex.to_int()
xvals = np.arange(xindex.npoints) * 10 + 1
yvals = np.arange(yindex.npoints) * 100 + 1
x = SparseVector(xvals, xindex)
y = SparseVector(yvals, yindex)
xd = SparseVector(xvals, xdindex)
yd = SparseVector(yvals, ydindex)
result_block = op(x, y)
result_dense = op(xd, yd)
assert_equal(result_block.values, result_dense.values)
def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
xindex = BlockIndex(TEST_LENGTH, xloc, xlen)
yindex = BlockIndex(TEST_LENGTH, yloc, ylen)
result = xindex.intersect(yindex)
self.assert_(isinstance(result, BlockIndex))
assert_equal(result.blocs, eloc)
assert_equal(result.blengths, elen)
def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
xindex = BlockIndex(TEST_LENGTH, xloc, xlen)
yindex = BlockIndex(TEST_LENGTH, yloc, ylen)
result = xindex.intersect(yindex)
self.assert_(isinstance(result, BlockIndex))
assert_equal(result.blocs, eloc)
assert_equal(result.blengths, elen)