When we use Vector.fromMap(map, size) or SparseVector.fromMap(map, size) API with maps that is not sorted by keys, the lookup on resultant vector fails.
import org.la4j.Vector;
import java.util.LinkedHashMap;
import java.util.Map;
public class Test {
public static void main(String[] args) {
Map<Integer, Double> values = new LinkedHashMap<>();
values.put(5, 5.0);
values.put(0, 0.0);
Vector vec = Vector.fromMap(values, 6);
System.out.println("0: " + vec.get(0));
System.out.println("5: " + vec.get(5));
}
}
When we use
Vector.fromMap(map, size)
orSparseVector.fromMap(map, size)
API with maps that is not sorted by keys, the lookup on resultant vector fails.Output: