kyonifer / koma

A scientific computing library for Kotlin. https://kyonifer.github.io/koma
Other
270 stars 23 forks source link

Add toTypedArray, toList, to${dtype}Array conversion functions #52

Closed drmoose closed 6 years ago

drmoose commented 6 years ago

As part of my ongoing campaign to make NDArray<T> behave more like kotlin's Collection<T> this PR adds to*** functions that convert NDArrays into row-major 1D objects that behave like builtins.

The first three are just convenience methods, but the last one avoids a round of boxing and unboxing that would occur using the technique it replaced:

someNdArray.toIterable().toList().toDoubleArray()
                     // ^- lg n array allocations + n boxing allocations
                              // ^- n unboxings

toDoubleArray() and its brethren use .size and the non-boxing linearized getters introduced in #51, so the number of allocations should be O(1).