kyonifer / koma

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

Add filterRows/filterCols functions. #44

Closed drmoose closed 6 years ago

drmoose commented 6 years ago

This PR adds shortcut functions to the Matrix interface inspired by the filterKeys/filterValues functions supplied by Kotlin's Maps.

All four take a predicate, and return a matrix that includes all of the (rows/cols) from the source matrix for which the predicate returns true.

>>> println(eye(6).filterRows { it[1] == it[3] }.repr())
mat[ 1.00,  0.00,  0.00,  0.00,  0.00,  0.00 end
     0.00,  0.00,  1.00,  0.00,  0.00,  0.00 end
     0.00,  0.00,  0.00,  0.00,  1.00,  0.00 end
     0.00,  0.00,  0.00,  0.00,  0.00,  1.00 ]
kyonifer commented 6 years ago

Looks good, thanks.