The most efficient is to collect a vector of triplets (i,j,value) and use the setFromTriplets method. It would not work with eigen older than 3.1.0 though.