-
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.
KI-44 [core, tfjs] Add Sinh operator
- Loading branch information
1 parent
c71879b
commit bc972b4
Showing
19 changed files
with
160 additions
and
0 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
53 changes: 53 additions & 0 deletions
53
...nce/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Sinh.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,53 @@ | ||
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.sinh | ||
import io.kinference.operator.* | ||
import io.kinference.primitives.types.DataType | ||
|
||
sealed class Sinh( | ||
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 = 9) | ||
|
||
operator fun invoke(name: String, version: Int?, attributes: Map<String, Attribute<Any>>, inputs: List<String>, outputs: List<String>) = | ||
when (version ?: DEFAULT_VERSION.sinceVersion) { | ||
in SinhVer9.VERSION.asRange() -> SinhVer9(name, attributes, inputs, outputs) | ||
else -> error("Unsupported version of Sinh operator: $version") | ||
} | ||
} | ||
} | ||
|
||
|
||
class SinhVer9( | ||
name: String, | ||
attributes: Map<String, Attribute<Any>>, | ||
inputs: List<String>, | ||
outputs: List<String> | ||
) : Sinh(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 = 9) | ||
private val INFO = OperatorInfo("Sinh", 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).sinh() | ||
DataType.DOUBLE -> (input as DoubleNDArray).sinh() | ||
else -> error("Unsupported data type for this operation: $type") | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ence/inference-core/src/commonTest/kotlin/io/kinference/operators/activations/SinhTest.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 SinhTest { | ||
private fun getTargetPath(dirName: String) = "sinh/$dirName/" | ||
|
||
@Test | ||
fun test_sinh() = TestRunner.runTest { | ||
KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_sinh")) | ||
} | ||
|
||
@Test | ||
fun test_sinh_example() = TestRunner.runTest { | ||
KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_sinh_example")) | ||
} | ||
} |
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
53 changes: 53 additions & 0 deletions
53
inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/activations/Sinh.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,53 @@ | ||
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.NumberNDArrayTFJS | ||
import io.kinference.ndarray.extensions.sinh | ||
import io.kinference.operator.* | ||
import io.kinference.tfjs.data.tensors.TFJSTensor | ||
import io.kinference.tfjs.data.tensors.asTensor | ||
|
||
sealed class Sinh( | ||
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 = 9) | ||
|
||
operator fun invoke(name: String, version: Int?, attributes: Map<String, Attribute<Any>>, inputs: List<String>, outputs: List<String>): Sinh { | ||
return when (version ?: DEFAULT_VERSION.sinceVersion) { | ||
in SinhVer9.VERSION.asRange() -> SinhVer9(name, attributes, inputs, outputs) | ||
else -> error("Unsupported version of Sinh operator: $version") | ||
} | ||
} | ||
} | ||
} | ||
|
||
class SinhVer9( | ||
name: String, | ||
attributes: Map<String, Attribute<Any>>, | ||
inputs: List<String>, | ||
outputs: List<String> | ||
) : Sinh(name, INFO, attributes, inputs, outputs) { | ||
companion object { | ||
private val TYPE_CONSTRAINTS = FLOAT_DATA_TYPES | ||
|
||
private val ATTRIBUTES_INFO = emptyList<AttributeInfo>() | ||
|
||
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 = 9) | ||
private val INFO = OperatorInfo("Sinh", ATTRIBUTES_INFO, 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.sinh().asTensor("output")) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...nce/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/activations/SinhTest.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 SinhTest { | ||
private fun getTargetPath(dirName: String) = "sinh/$dirName/" | ||
|
||
@Test | ||
fun test_sinh() = TestRunner.runTest { | ||
TFJSAccuracyRunner.runFromResources(getTargetPath("test_sinh")) | ||
} | ||
|
||
@Test | ||
fun test_sinh_example() = TestRunner.runTest { | ||
TFJSAccuracyRunner.runFromResources(getTargetPath("test_sinh_example")) | ||
} | ||
} |
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
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
2 changes: 2 additions & 0 deletions
2
utils/utils-testing/src/commonMain/resources/sinh/test_sinh/descriptor.txt
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,2 @@ | ||
test_data_set_0/input_0.pb | ||
test_data_set_0/output_0.pb |
Binary file added
BIN
+99 Bytes
utils/utils-testing/src/commonMain/resources/sinh/test_sinh/model.onnx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
utils/utils-testing/src/commonMain/resources/sinh/test_sinh/test_data_set_0/input_0.pb
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 @@ | ||
BxJ�x��?h��>��z?�j@$�?�.z��8s?b��hdӽ�9�>(�>�%�?^�B?�0�=B�>]ת>�=�?R�iJ�>�Z�/d#��S'?�K]?��=��C@�(��Hm;= �?�2�?��?��>���>�Ec������!��� >*z�?��?�Oƾmǚ��6��&õ�gڿ��?�x�FKྙ[��� G?4�ο��Y�L=e��> �����k��QN�>.:�=�ݚ>�b"�6��� |
1 change: 1 addition & 0 deletions
1
utils/utils-testing/src/commonMain/resources/sinh/test_sinh/test_data_set_0/output_0.pb
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
2 changes: 2 additions & 0 deletions
2
utils/utils-testing/src/commonMain/resources/sinh/test_sinh_example/descriptor.txt
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,2 @@ | ||
test_data_set_0/input_0.pb | ||
test_data_set_0/output_0.pb |
Binary file added
BIN
+91 Bytes
utils/utils-testing/src/commonMain/resources/sinh/test_sinh_example/model.onnx
Binary file not shown.
Binary file added
BIN
+21 Bytes
.../utils-testing/src/commonMain/resources/sinh/test_sinh_example/test_data_set_0/input_0.pb
Binary file not shown.
Binary file added
BIN
+21 Bytes
...utils-testing/src/commonMain/resources/sinh/test_sinh_example/test_data_set_0/output_0.pb
Binary file not shown.