-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Conflicts: # inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/KIOperatorFactory.kt # inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/TFJSOperatorFactory.kt
- Loading branch information
Showing
68 changed files
with
315 additions
and
135 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
52 changes: 52 additions & 0 deletions
52
...ence/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Tan.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,52 @@ | ||
package io.kinference.core.operators.activations | ||
|
||
import io.kinference.attribute.Attribute | ||
import io.kinference.core.KIONNXData | ||
import io.kinference.graph.Contexts | ||
import io.kinference.ndarray.arrays.* | ||
import io.kinference.ndarray.extensions.activations.tan.tan | ||
import io.kinference.operator.* | ||
import io.kinference.primitives.types.DataType | ||
|
||
sealed class Tan( | ||
name: String, | ||
info: OperatorInfo, | ||
attributes: Map<String, Attribute<Any>>, | ||
inputs: List<String>, outputs: List<String> | ||
) : Activation(name, info, attributes, inputs, outputs) { | ||
companion object { | ||
private val DEFAULT_VERSION = VersionInfo(sinceVersion = 7) | ||
|
||
operator fun invoke(name: String, version: Int?, attributes: Map<String, Attribute<Any>>, inputs: List<String>, outputs: List<String>): Tan { | ||
return when (version ?: DEFAULT_VERSION.sinceVersion) { | ||
in TanVer7.VERSION.asRange() -> TanVer7(name, attributes, inputs, outputs) | ||
else -> error("Unsupported version of Tan operator: $version") | ||
} | ||
} | ||
} | ||
} | ||
|
||
class TanVer7( | ||
name: String, | ||
attributes: Map<String, Attribute<Any>> = emptyMap(), | ||
inputs: List<String>, | ||
outputs: List<String> | ||
) : Tan(name, INFO, attributes, inputs, outputs) { | ||
companion object { | ||
private val TYPE_CONSTRAINTS = FLOAT_DATA_TYPES | ||
|
||
private val INPUT_INFO = listOf(IOInfo(0, TYPE_CONSTRAINTS, "input", optional = false)) | ||
private val OUTPUT_INFO = listOf(IOInfo(0, TYPE_CONSTRAINTS, "output", optional = false)) | ||
|
||
internal val VERSION = VersionInfo(sinceVersion = 7) | ||
private val INFO = OperatorInfo("Tan", emptySet(), INPUT_INFO, OUTPUT_INFO, VERSION, OperatorInfo.DEFAULT_DOMAIN) | ||
} | ||
|
||
override suspend fun activate(input: NDArrayCore, contexts: Contexts<KIONNXData<*>>): NDArrayCore { | ||
return when (val type = input.type) { | ||
DataType.FLOAT -> (input as FloatNDArray).tan() | ||
DataType.DOUBLE -> (input as DoubleNDArray).tan() | ||
else -> error("Unsupported data type : $type") | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...rence/inference-core/src/commonTest/kotlin/io/kinference/operators/activations/TanTest.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,19 @@ | ||
package io.kinference.operators.activations | ||
|
||
import io.kinference.KITestEngine | ||
import io.kinference.utils.TestRunner | ||
import kotlin.test.Test | ||
|
||
class TanTest { | ||
private fun getTargetPath(dirName: String) = "tan/$dirName/" | ||
|
||
@Test | ||
fun test_tanh_example() = TestRunner.runTest { | ||
KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_tan_example")) | ||
} | ||
|
||
@Test | ||
fun test_tanh() = TestRunner.runTest { | ||
KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_tan")) | ||
} | ||
} |
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
52 changes: 52 additions & 0 deletions
52
inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/activations/Tan.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,52 @@ | ||
package io.kinference.tfjs.operators.activations | ||
|
||
import io.kinference.attribute.Attribute | ||
import io.kinference.data.ONNXData | ||
import io.kinference.graph.Contexts | ||
import io.kinference.ndarray.arrays.* | ||
import io.kinference.ndarray.extensions.tan | ||
import io.kinference.operator.* | ||
import io.kinference.tfjs.data.tensors.TFJSTensor | ||
import io.kinference.tfjs.data.tensors.asTensor | ||
|
||
sealed class Tan( | ||
name: String, | ||
info: OperatorInfo, | ||
attributes: Map<String, Attribute<Any>>, | ||
inputs: List<String>, | ||
outputs: List<String> | ||
) : Operator<TFJSTensor, TFJSTensor>(name, info, attributes, inputs, outputs) { | ||
companion object { | ||
private val DEFAULT_VERSION = VersionInfo(sinceVersion = 7) | ||
|
||
operator fun invoke(name: String, version: Int?, attributes: Map<String, Attribute<Any>>, inputs: List<String>, outputs: List<String>): Tan { | ||
return when (version ?: DEFAULT_VERSION.sinceVersion) { | ||
in TanVer7.VERSION.asRange() -> TanVer7(name, attributes, inputs, outputs) | ||
else -> error("Unsupported version of Tan operator: $version") | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
class TanVer7( | ||
name: String, | ||
attributes: Map<String, Attribute<Any>> = emptyMap(), | ||
inputs: List<String>, | ||
outputs: List<String> | ||
) : Tan(name, INFO, attributes, inputs, outputs) { | ||
companion object { | ||
private val TYPE_CONSTRAINTS = FLOAT_DATA_TYPES | ||
|
||
private val INPUT_INFO = listOf(IOInfo(0, TYPE_CONSTRAINTS, "input", optional = false)) | ||
private val OUTPUT_INFO = listOf(IOInfo(0, TYPE_CONSTRAINTS, "output", optional = false)) | ||
|
||
internal val VERSION = VersionInfo(sinceVersion = 7) | ||
private val INFO = OperatorInfo("Tan", emptySet(), INPUT_INFO, OUTPUT_INFO, VERSION, OperatorInfo.DEFAULT_DOMAIN) | ||
} | ||
|
||
override suspend fun <D : ONNXData<*, *>> apply(contexts: Contexts<D>, inputs: List<TFJSTensor?>): List<TFJSTensor?> { | ||
val input = inputs[0]!!.data as NumberNDArrayTFJS | ||
return listOf(input.tan().asTensor("output")) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ence/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/activations/TanTest.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,19 @@ | ||
package io.kinference.tfjs.operators.activations | ||
|
||
import io.kinference.tfjs.runners.TFJSTestEngine.TFJSAccuracyRunner | ||
import io.kinference.utils.TestRunner | ||
import kotlin.test.Test | ||
|
||
class TanTest { | ||
private fun getTargetPath(dirName: String) = "tan/$dirName/" | ||
|
||
@Test | ||
fun test_tanh_example() = TestRunner.runTest { | ||
TFJSAccuracyRunner.runFromResources(getTargetPath("test_tan_example")) | ||
} | ||
|
||
@Test | ||
fun test_tanh() = TestRunner.runTest { | ||
TFJSAccuracyRunner.runFromResources(getTargetPath("test_tan")) | ||
} | ||
} |
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
15 changes: 0 additions & 15 deletions
15
...src/commonMain/kotlin/io/kinference/ndarray/arrays/pointers/PrimitivePointerExtensions.kt
This file was deleted.
Oops, something went wrong.
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
3 changes: 0 additions & 3 deletions
3
ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/abs/AbsUtils.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 |
---|---|---|
@@ -1,9 +1,6 @@ | ||
package io.kinference.ndarray.extensions.abs | ||
|
||
import io.kinference.primitives.types.PrimitiveType | ||
import kotlin.math.abs | ||
|
||
internal fun abs(x: Short) = abs(x.toInt()).toShort() | ||
internal fun abs(x: Byte) = abs(x.toInt()).toByte() | ||
|
||
internal inline fun abs(x: PrimitiveType): PrimitiveType = throw UnsupportedOperationException() |
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
5 changes: 0 additions & 5 deletions
5
...core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/acos/AcosUtils.kt
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
...re/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/acosh/AcoshUtils.kt
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
...core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/asin/AsinUtils.kt
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
...re/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/asinh/AsinhUtils.kt
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
...core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/atan/AtanUtils.kt
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
...re/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/atanh/AtanhUtils.kt
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
...y-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/cos/CosUtils.kt
This file was deleted.
Oops, something went wrong.
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
5 changes: 0 additions & 5 deletions
5
...core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/cosh/CoshUtils.kt
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
...re/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/tan/TanPrimitive.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,32 @@ | ||
@file:GeneratePrimitives( | ||
DataType.FLOAT, | ||
DataType.DOUBLE | ||
) | ||
|
||
package io.kinference.ndarray.extensions.activations.tan | ||
|
||
import io.kinference.ndarray.arrays.MutablePrimitiveNDArray | ||
import io.kinference.ndarray.arrays.PrimitiveNDArray | ||
import io.kinference.ndarray.stubs.tan | ||
import io.kinference.primitives.annotations.GeneratePrimitives | ||
import io.kinference.primitives.types.DataType | ||
import kotlin.math.tan | ||
|
||
fun PrimitiveNDArray.tan(): PrimitiveNDArray { | ||
val output = MutablePrimitiveNDArray(this.strides) | ||
|
||
val outputIter = output.array.blocks.iterator() | ||
val inputIter = this.array.blocks.iterator() | ||
val blocksNum = this.array.blocksNum | ||
|
||
repeat(blocksNum) { | ||
val inputBlock = inputIter.next() | ||
val outputBlock = outputIter.next() | ||
|
||
for (idx in outputBlock.indices) { | ||
outputBlock[idx] = tan(inputBlock[idx]) | ||
} | ||
} | ||
|
||
return output | ||
} |
6 changes: 0 additions & 6 deletions
6
...ay-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/bitwise/and/BitAndUtils.kt
This file was deleted.
Oops, something went wrong.
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
6 changes: 0 additions & 6 deletions
6
...ay-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/bitwise/not/BitNotUtils.kt
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.