-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move flattenFloats function to a separate file
- Loading branch information
1 parent
35ebbab
commit 1fe55f3
Showing
5 changed files
with
27 additions
and
21 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
api/src/main/kotlin/org/jetbrains/kotlinx/dl/api/core/util/ArrayUtil.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2022 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.core.util | ||
|
||
/** | ||
* Flattens the given array of float values. | ||
* @return flattened array | ||
*/ | ||
public fun Array<*>.flattenFloats(): FloatArray { | ||
val result = mutableListOf<Float>() | ||
|
||
fun flatten(array: Any?): Unit = when (array) { | ||
is FloatArray -> array.forEach { result.add(it) } | ||
is Array<*> -> array.forEach { flatten(it) } | ||
else -> throw IllegalArgumentException("Cannot flatten object: '$array'") | ||
} | ||
|
||
flatten(this) | ||
|
||
return result.toFloatArray() | ||
} |
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
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
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