def test_lix(si=si): "Unit tests of larry's indexing by label method, lix" for shape, index in si: original = larry(np.arange(np.prod(shape)).reshape(shape)) aindex = [] for ax, idx in enumerate(index): if type(idx) == slice: start = idx.start if type(start) == list: start = start[0] stop = idx.stop if type(stop) == list: stop = stop[0] idx = slice(start, stop, idx.step) aindex.append(np.arange(*idx.indices(original.shape[ax]))) elif isscalar(idx): aindex.append([idx]) else: aindex.append([np.array(i) for i in idx]) desired = np.squeeze(original.x[np.ix_(*aindex)]) if len(index) == 1: actual = original.lix[index[0]] elif len(index) == 2: actual = original.lix[index[0], index[1]] elif len(index) == 3: actual = original.lix[index[0], index[1], index[2]] elif len(index) == 4: actual = original.lix[index[0], index[1], index[2], index[3]] if isinstance(actual, larry): actual = actual.x msg = '\nlix fail on shape %s and index %s\n' yield assert_equal, actual, desired, msg % (str(shape), str(index))
def test_isa(): "util.misc.isint, isfloat, isscalar" t = {} # The keys are tuples otherwise #1 and #6, for example, would have # the same key # int float t[(1, 1)] = (True, False) t[(1.1, 2)] = (False, True) t[('a', 3)] = (False, False) t[(True, 4)] = (False, False) t[(False, 5)] = (False, False) t[(np.array(1)[()], 6)] = (True, False) t[(np.array(1.1)[()], 7)] = (False, True) t[(1j, 8)] = (False, False) for key, value in t.iteritems(): key = key[0] msg = '\nisint(' + str(key) + ')' yield assert_equal, isint(key), value[0], msg msg = '\nisfloat(' + str(key) + ')' yield assert_equal, isfloat(key), value[1], msg msg = '\nisscalar(' + str(key) + ')' yield assert_equal, isscalar(key), (value[0] or value[1]), msg
def test_isa(): "util.misc.isint, isfloat, isscalar" t = {} # The keys are tuples otherwise #1 and #6, for example, would have # the same key # int float t[(1, 1)] = (True, False) t[(1.1, 2)] = (False, True) t[('a', 3)] = (False, False) t[(True, 4)] = (False, False) t[(False, 5)] = (False, False) t[(np.array(1)[()], 6)] = (True, False) t[(np.array(1.1)[()], 7)] = (False, True) t[(1j, 8)] = (False, False) for key, value in t.items(): key = key[0] msg = '\nisint(' + str(key) + ')' yield assert_equal, isint(key), value[0], msg msg = '\nisfloat(' + str(key) + ')' yield assert_equal, isfloat(key), value[1], msg msg = '\nisscalar(' + str(key) + ')' yield assert_equal, isscalar(key), (value[0] or value[1]), msg