alex cole
01/10/2021, 1:54 AMVampire
01/10/2021, 2:01 AMfoo.zip(bar).all { (f, b) -> f > b }
alex cole
01/10/2021, 2:25 AMfun inBounds(shape: Array<Int>, indices: Array<Int>): Boolean {
for (i in 0 until shape.size) {
if (indices[i] > shape[i]) return false
}
return true
}
Vampire
01/10/2021, 2:27 AMVampire
01/10/2021, 2:29 AMfun inBounds(shape: Array<Int>, indices: Array<Int>) =
shape.zip(indices).all { (s, i) -> s >= i }
alex cole
01/10/2021, 2:40 AMshape.size == indices.size
other than:
private fun inBounds(shape: Array<Int>, indices: Array<Int>): Boolean {
if (shape.size != indices.size) return false
return shape.zip(indices).all { (s, i) -> s >= i }
}
Vampire
01/10/2021, 2:45 AMfun inBounds(shape: Array<Int>, indices: Array<Int>) =
(shape.size == indices.size)
&& shape.zip(indices).all { (s, i) -> s >= i }
Or probably many other variantsalex cole
01/10/2021, 2:46 AMVampire
01/10/2021, 2:47 AMalex cole
01/10/2021, 2:56 AMVampire
01/10/2021, 2:57 AMephemient
01/11/2021, 2:01 AMzip
where I would expect differences. probably direct indexing is faster for arrays and iterators is faster for certain types of collections. but zip is almost certainly good enough.ephemient
01/11/2021, 2:02 AMalex cole
01/11/2021, 3:10 AM