def test_correct_raw_data_2_inputs(self): array1 = np.array([1, 2], dtype=np.dtype(np.int32)) array2 = np.array([3, 5], dtype=np.dtype(np.int32)) result = npw.cartesian_product_indices([array1, array2]) expected_array1_result = np.array([0, 0, 1, 1], dtype=np.int64) expected_array2_result = np.array([0, 1, 0, 1], dtype=np.int64) np.testing.assert_array_equal(expected_array1_result, result[0].evaluate(verbose=False), "First array result is incorrect") np.testing.assert_array_equal(expected_array2_result, result[1].evaluate(verbose=False), "Second array result is incorrect")
def test_correct_lazy_data_input_second(self): array1 = np.array([1, 2, 3], dtype=np.dtype(np.int32)) array2 = np.array([4, 5], dtype=np.dtype(np.int32)) array2 = npw.duplicate_elements_indices(array2, 2L) result = npw.cartesian_product_indices([array1, array2]) expected_array1_result = np.array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2], dtype=np.int64) expected_array2_result = np.array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], dtype=np.int64) np.testing.assert_array_equal(expected_array1_result, result[0].evaluate(verbose=False), "First array result is incorrect") np.testing.assert_array_equal(expected_array2_result, result[1].evaluate(verbose=False), "Second array result is incorrect")
def from_product(cls, levels, names): """ Create MultiIndex when no labels are available Parameters ---------- levels : list of np.ndarray or list of LazyResult names : list of str Returns ------- MultiIndex """ labels = npw.cartesian_product_indices(levels, MultiIndex._cache_flag) return cls(levels, labels, names)
def test_correct_lazy_data_input_both(self): array1 = np.array([1, 2, 3], dtype=np.dtype(np.int32)) array1 = npw.duplicate_elements_indices(array1, 2L) array2 = np.array([4, 5], dtype=np.dtype(np.int32)) array2 = npw.duplicate_elements_indices(array2, 2L) result = npw.cartesian_product_indices([array1, array2]) # this was incorrect before; if one duplicate_elements([0, 0], 2L) it results in [0, 0, 0, 0] # as values, however the indices are in fact [0, 0, 1, 1] which is what we requested expected_array1_result = np.array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5], dtype=np.int64) expected_array2_result = np.array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3], dtype=np.int64) np.testing.assert_array_equal(expected_array1_result, result[0].evaluate(verbose=False), "First array result is incorrect") np.testing.assert_array_equal(expected_array2_result, result[1].evaluate(verbose=False), "Second array result is incorrect")