public RescaleMappings invert() {
        IntArrayList[] inverted = new IntArrayList[numberOfTargets];
        for (int source = 0; source < mappings.length; source++) {
            final int[] targets = mappings[source];
            for (int target : targets) {
                IntArrayList sources = inverted[target];
                if (sources == null) {
                    inverted[target] = sources = new IntArrayList(1);
                }
                sources.add(source);
            }
        }
        return of(Arrays.stream(inverted).map(RescaleMappings::toSortedArray), numberOfSources);
    }
@Test
    void testInvert() {
        RescaleMappings mapping = mappings(to(0), to(0), to(), to(2, 3), to(0, 5));
        RescaleMappings inverted = mapping.invert();
        RescaleMappings expected = mappings(to(0, 1, 4), to(), to(3), to(3), to(), to(4));

        assertThat(inverted).isEqualTo(expected);

        assertThat(inverted.invert()).isEqualTo(mapping);
    }