| 57 | } |
| 58 | |
| 59 | TEST(SparseTensorTest, DimComparatorSorts) { |
| 60 | int64 N = 5; |
| 61 | const int NDIM = 3; |
| 62 | auto ix = GetSimpleIndexTensor(N, NDIM); |
| 63 | TTypes<int64>::Matrix map(ix.data(), N, NDIM); |
| 64 | |
| 65 | std::vector<int64> sorting(N); |
| 66 | for (std::size_t n = 0; n < N; ++n) sorting[n] = n; |
| 67 | |
| 68 | // new order should be: {0, 4, 3, 2, 1} |
| 69 | std::vector<int64> order{0, 1, 2}; |
| 70 | std::vector<int64> shape{N, N, N}; |
| 71 | DimComparator sorter(map, order, shape); |
| 72 | std::sort(sorting.begin(), sorting.end(), sorter); |
| 73 | EXPECT_EQ(sorting, std::vector<int64>({0, 4, 3, 2, 1})); |
| 74 | |
| 75 | FixedDimComparator<3> sorter_fixed(map, order, shape); |
| 76 | std::sort(sorting.begin(), sorting.end(), sorter_fixed); |
| 77 | EXPECT_EQ(sorting, std::vector<int64>({0, 4, 3, 2, 1})); |
| 78 | |
| 79 | // new order should be: {0, 3, 2, 1, 4} |
| 80 | std::vector<int64> order1{2, 0, 1}; |
| 81 | DimComparator sorter1(map, order1, shape); |
| 82 | for (std::size_t n = 0; n < N; ++n) sorting[n] = n; |
| 83 | std::sort(sorting.begin(), sorting.end(), sorter1); |
| 84 | EXPECT_EQ(sorting, std::vector<int64>({0, 3, 2, 1, 4})); |
| 85 | |
| 86 | FixedDimComparator<3> sorter1_fixed(map, order1, shape); |
| 87 | for (std::size_t n = 0; n < N; ++n) sorting[n] = n; |
| 88 | std::sort(sorting.begin(), sorting.end(), sorter1_fixed); |
| 89 | EXPECT_EQ(sorting, std::vector<int64>({0, 3, 2, 1, 4})); |
| 90 | } |
| 91 | |
| 92 | TEST(SparseTensorTest, SparseTensorInvalidIndicesType) { |
| 93 | int N = 5; |
nothing calls this directly
no test coverage detected