Created
May 23, 2019 21:02
-
-
Save matteo-grella/e5bb7e6e5aa262a830cf947911597893 to your computer and use it in GitHub Desktop.
sumWithPrevAndNext
This file contains 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 com.kotlinnlp.simplednn.simplemath.ndarray.dense.DenseNDArray | |
fun List<DenseNDArray>.sumWithPrevAndNext(): List<DenseNDArray> = this.indices.map { i -> | |
val cur = this[i].copy() | |
if (i > 0) cur.assignSum(this[i - 1]) | |
if (i < this.lastIndex) cur.assignSum(this[i + 1]) | |
cur | |
} | |
fun List<DenseNDArray>.addBackwardOfSumWithPrevAndNext(gradients: List<DenseNDArray>) = this.indices.map { i -> | |
this[i].assignSum(gradients[i]) | |
if (i > 0) this[i].assignSum(gradients[i - 1]) | |
if (i < this.lastIndex) this[i].assignSum(gradients[i + 1]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment