Created
September 8, 2022 20:54
-
-
Save iaverypadberg/0112cc6cff7dad9916c2d618746861a3 to your computer and use it in GitHub Desktop.
Kotlin Scratch File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.jetbrains.kotlinx.multik.api.toNDArray | |
import org.jetbrains.kotlinx.multik.ndarray.data.get | |
import org.jetbrains.kotlinx.multik.ndarray.data.slice | |
import org.jetbrains.kotlinx.multik.ndarray.operations.last | |
import org.jetbrains.kotlinx.multik.ndarray.operations.minus | |
import org.jetbrains.kotlinx.multik.ndarray.operations.plus | |
import org.jetbrains.kotlinx.multik.ndarray.operations.toList | |
// Filter out all items | |
val startList = listOf(Pair(1,.2),Pair(2,.4),Pair(3,.6),Pair(4,.3)) | |
val startIndicies = startList.indices.toList() | |
val allFiltered = startIndicies.filter { startList[it].second > .3 } | |
println(allFiltered) | |
// Argsort | |
val needsSorting = listOf<Int>(4,6,2,3,8,3,6) | |
val theRange = IntRange(0,needsSorting.size-1) | |
val idxs = theRange.toList().sortedBy { needsSorting[it] } | |
print(idxs) | |
print(needsSorting.indices.last()) | |
// np.maximum | |
var xmins = mutableListOf<Int>(1,6,5,4) | |
var selected_idx = xmins.last() | |
println(selected_idx) | |
var overlappedXMins = mutableListOf<Int>() | |
xmins.subList(0,xmins.size-1).forEach { overlappedXMins.add(maxOf(it, selected_idx)) } | |
println(overlappedXMins) | |
// Element wise division | |
var vec1 = listOf<Int>(1,2,3) | |
var weights1 = listOf<Int>(4,4,6) | |
val result1 = vec1.zip(weights1) { a, b -> b/a } | |
println(result1) | |
// Slicing an NDarray | |
val selectedIdx = 2 | |
val areas = listOf<Int>(1,2,3,4).toNDArray() | |
val intersections = listOf<Int>(1,2,3).toNDArray() | |
//val unions = areas.toList().subList(0,areas.size-1).toNDArray() | |
val unions = areas[0 until areas.last()] + areas[selectedIdx] - intersections | |
println(unions |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment