/** * Create a map from an array and index mapping. * * @param mapping The index mapping specifying the keys. * @param values The array of values. * @return A sparse vector mapping the IDs in {@code map} to the values in {@code values}. * @throws IllegalArgumentException if {@code values} not the same size as {@code idx}. */ public static Long2DoubleSortedArrayMap fromArray(KeyIndex mapping, double[] values) { return fromArray(mapping, DoubleArrayList.wrap(values)); }
@Test public void testFromArray() { HashKeyIndex map = new HashKeyIndex(); map.internId(42); map.internId(37); map.internId(62); double[] values = { 3.5, 4.9, 1.8 }; Long2DoubleMap res = Long2DoubleSortedArrayMap.fromArray(map, values); assertThat(res.size(), equalTo(3)); assertThat(res.keySet(), contains(37L, 42L, 62L)); assertThat(res, hasEntry(37L, 4.9)); assertThat(res, hasEntry(42L, 3.5)); assertThat(res, hasEntry(62L, 1.8)); }
/** * Create a map from an array and index mapping. * * @param mapping The index mapping specifying the keys. * @param values The array of values. * @return A sparse vector mapping the IDs in {@code map} to the values in {@code values}. * @throws IllegalArgumentException if {@code values} not the same size as {@code idx}. */ public static Long2DoubleSortedArrayMap fromArray(KeyIndex mapping, double[] values) { return fromArray(mapping, DoubleArrayList.wrap(values)); }