-
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.
- Loading branch information
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
...ence/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Sin.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.sin | ||
import io.kinference.operator.* | ||
import io.kinference.primitives.types.DataType | ||
|
||
sealed class Sin( | ||
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>) = | ||
when (version ?: DEFAULT_VERSION.sinceVersion) { | ||
in SinVer7.VERSION.asRange() -> SinVer7(name, attributes, inputs, outputs) | ||
else -> error("Unsupported version of Sin operator: $version") | ||
} | ||
} | ||
} | ||
|
||
|
||
class SinVer7( | ||
name: String, | ||
attributes: Map<String, Attribute<Any>>, | ||
inputs: List<String>, | ||
outputs: List<String> | ||
) : Sin(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("Sin", 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).sin() | ||
DataType.DOUBLE -> (input as DoubleNDArray).sin() | ||
else -> error("Unsupported data type for this operation: $type") | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...rence/inference-core/src/commonTest/kotlin/io/kinference/operators/activations/SinTest.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 SinTest { | ||
private fun getTargetPath(dirName: String) = "sin/$dirName/" | ||
|
||
@Test | ||
fun test_sin() = TestRunner.runTest { | ||
KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_sin")) | ||
} | ||
|
||
@Test | ||
fun test_sin_example() = TestRunner.runTest { | ||
KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_sin_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/Sin.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.sin | ||
import io.kinference.operator.* | ||
import io.kinference.tfjs.data.tensors.TFJSTensor | ||
import io.kinference.tfjs.data.tensors.asTensor | ||
|
||
sealed class Sin( | ||
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>): Sin { | ||
return when (version ?: DEFAULT_VERSION.sinceVersion) { | ||
in SinVer7.VERSION.asRange() -> SinVer7(name, attributes, inputs, outputs) | ||
else -> error("Unsupported version of Sin operator: $version") | ||
} | ||
} | ||
} | ||
} | ||
|
||
class SinVer7( | ||
name: String, | ||
attributes: Map<String, Attribute<Any>>, | ||
inputs: List<String>, | ||
outputs: List<String> | ||
) : Sin(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 = 7) | ||
private val INFO = OperatorInfo("Sin", 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.sin().asTensor("output")) | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ence/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/activations/SinTest.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 SinTest { | ||
private fun getTargetPath(dirName: String) = "sin/$dirName/" | ||
|
||
@Test | ||
fun test_sin() = TestRunner.runTest { | ||
TFJSAccuracyRunner.runFromResources(getTargetPath("test_sin")) | ||
} | ||
|
||
@Test | ||
fun test_sin_example() = TestRunner.runTest { | ||
TFJSAccuracyRunner.runFromResources(getTargetPath("test_sin_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/sin/test_sin/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
+97 Bytes
utils/utils-testing/src/commonMain/resources/sin/test_sin/model.onnx
Binary file not shown.
1 change: 1 addition & 0 deletions
1
utils/utils-testing/src/commonMain/resources/sin/test_sin/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/sin/test_sin/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/sin/test_sin_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
+89 Bytes
utils/utils-testing/src/commonMain/resources/sin/test_sin_example/model.onnx
Binary file not shown.
Binary file added
BIN
+21 Bytes
utils/utils-testing/src/commonMain/resources/sin/test_sin_example/test_data_set_0/input_0.pb
Binary file not shown.
Binary file added
BIN
+21 Bytes
...s/utils-testing/src/commonMain/resources/sin/test_sin_example/test_data_set_0/output_0.pb
Binary file not shown.