org.jetbrains.kotlinx.dl.api.extension.FloatArrayExtensionFunctions.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kotlin-deeplearning-api Show documentation
Show all versions of kotlin-deeplearning-api Show documentation
Deep Learning library for Kotlin.
/*
* Copyright 2020 JetBrains s.r.o. and Kotlin Deep Learning project contributors. All Rights Reserved.
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file.
*/
package org.jetbrains.kotlinx.dl.api.extension
// TODO: add the same method but with 3d channel navigation
/** */
public fun FloatArray.set3D(
rowIndex: Int,
columnIndex: Int,
channelIndex: Int,
width: Int,
channels: Int,
value: Float
) {
this[width * rowIndex * channels + columnIndex * channels + channelIndex] = value
}
/** */
public fun FloatArray.get3D(rowIndex: Int, columnIndex: Int, channelIndex: Int, width: Int, channels: Int): Float {
return this[width * rowIndex * channels + columnIndex * channels + channelIndex]
}
/** */
public fun FloatArray.set2D(rowIndex: Int, columnIndex: Int, width: Int, value: Float) {
this[width * rowIndex + columnIndex] = value
}
/** */
public fun FloatArray.get2D(rowIndex: Int, columnIndex: Int, width: Int): Float {
return this[width * rowIndex + columnIndex]
}
/**
* Returns the index of the maximum element in the given FloatArray.
* TODO: Should be replaced with Multik in future.
*/
public fun FloatArray.argmax(): Int =
maxOrNull()?.let { max -> indexOfFirst { it == max } } ?: -1
© 2015 - 2025 Weber Informatics LLC | Privacy Policy