diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/KIOperatorFactory.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/KIOperatorFactory.kt index 534b24bda..be1dd3d53 100755 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/KIOperatorFactory.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/KIOperatorFactory.kt @@ -131,6 +131,7 @@ object KIOperatorFactory : OperatorFactory> { "Softmax" -> Softmax(name, version, attributes, inputs, outputs) "Split" -> Split(name, version, attributes, inputs, outputs) "SplitToSequence" -> SplitToSequence(name, version, attributes, inputs, outputs) + "Sqrt" -> Sqrt(name, version, attributes, inputs, outputs) "Squeeze" -> Squeeze(name, version, attributes, inputs, outputs) "Sub" -> Sub(name, version, attributes, inputs, outputs) "Tan" -> Tan(name, version, attributes, inputs, outputs) diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Acos.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Acos.kt index a8e232943..755ee2bb5 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Acos.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Acos.kt @@ -4,7 +4,7 @@ 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.acos.acos +import io.kinference.ndarray.extensions.activations.acos import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Acosh.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Acosh.kt index 84eca2383..e85c6015c 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Acosh.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Acosh.kt @@ -4,7 +4,7 @@ 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.acosh.acosh +import io.kinference.ndarray.extensions.activations.acosh import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Asin.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Asin.kt index d5a5b4206..8560526e5 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Asin.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Asin.kt @@ -4,7 +4,7 @@ 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.asin.asin +import io.kinference.ndarray.extensions.activations.asin import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Asinh.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Asinh.kt index c80289afa..323a2f890 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Asinh.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Asinh.kt @@ -4,7 +4,7 @@ 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.asinh.asinh +import io.kinference.ndarray.extensions.activations.asinh import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Atan.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Atan.kt index 4c8df6dd9..67784f6cc 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Atan.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Atan.kt @@ -4,7 +4,7 @@ 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.atan.atan +import io.kinference.ndarray.extensions.activations.atan import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Atanh.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Atanh.kt index 988caa126..1f06f6b2b 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Atanh.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Atanh.kt @@ -4,7 +4,7 @@ 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.atanh.atanh +import io.kinference.ndarray.extensions.activations.atanh import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Cos.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Cos.kt index 07b44f8d4..2ff8ed410 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Cos.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Cos.kt @@ -4,7 +4,7 @@ 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.cos.cos +import io.kinference.ndarray.extensions.activations.cos import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Cosh.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Cosh.kt index d3297bee5..a1e0bead6 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Cosh.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Cosh.kt @@ -4,7 +4,7 @@ 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.cosh.cosh +import io.kinference.ndarray.extensions.activations.cosh import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Tan.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Tan.kt index 9c1bed312..cbc1eaf06 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Tan.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/activations/Tan.kt @@ -4,7 +4,7 @@ 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.ndarray.extensions.activations.tan import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/math/Sqrt.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/math/Sqrt.kt new file mode 100644 index 000000000..e11d9dfb4 --- /dev/null +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/math/Sqrt.kt @@ -0,0 +1,64 @@ +package io.kinference.core.operators.math + +import io.kinference.attribute.Attribute +import io.kinference.core.data.tensor.KITensor +import io.kinference.core.data.tensor.asTensor +import io.kinference.data.ONNXData +import io.kinference.graph.Contexts +import io.kinference.ndarray.arrays.* +import io.kinference.ndarray.extensions.sqrt +import io.kinference.operator.* +import io.kinference.primitives.types.DataType + +sealed class Sqrt( + name: String, + info: OperatorInfo, + attributes: Map>, + inputs: List, + outputs: List +) : Operator(name, info, attributes, inputs, outputs) { + companion object { + private val DEFAULT_VERSION = VersionInfo(sinceVersion = 6) + + operator fun invoke(name: String, version: Int?, attributes: Map>, inputs: List, outputs: List): Sqrt { + return when (version ?: DEFAULT_VERSION.sinceVersion) { + in SqrtVer6.VERSION.asRange() -> SqrtVer6(name, attributes, inputs, outputs) + else -> error("Unsupported version of Sqrt operator: $version") + } + } + } +} + +class SqrtVer6( + name: String, + attributes: Map>, + inputs: List, + outputs: List +) : Sqrt(name, INFO, attributes, inputs, outputs) { + companion object { + private val TYPE_CONSTRAINTS = FLOAT_DATA_TYPES + + private val INPUTS_INFO = listOf( + IOInfo(0, TYPE_CONSTRAINTS, "X", optional = false) + ) + + private val OUTPUTS_INFO = listOf( + IOInfo(0, TYPE_CONSTRAINTS, "Y", optional = false) + ) + + internal val VERSION = VersionInfo(sinceVersion = 6) + private val INFO = OperatorInfo("Sqrt", emptyMap(), INPUTS_INFO, OUTPUTS_INFO, VERSION, domain = OperatorInfo.DEFAULT_DOMAIN) + } + + + override suspend fun > apply(contexts: Contexts, inputs: List): List { + val input = inputs[0]!!.data as NumberNDArrayCore + val output = when(val type = input.type) { + DataType.FLOAT -> (input as FloatNDArray).sqrt() + DataType.DOUBLE -> (input as DoubleNDArray).sqrt() + else -> error("Unsupported data type: $type") + } + + return listOf(output.asTensor("Y")) + } +} diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Ceil.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Ceil.kt index 1eb63cc09..4c0ebb8d7 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Ceil.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Ceil.kt @@ -6,7 +6,7 @@ import io.kinference.core.data.tensor.asTensor import io.kinference.data.ONNXData import io.kinference.graph.Contexts import io.kinference.ndarray.arrays.* -import io.kinference.ndarray.extensions.ceil.ceil +import io.kinference.ndarray.extensions.ceil import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Floor.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Floor.kt index 4e10ff90a..eec8913c8 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Floor.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/Floor.kt @@ -6,7 +6,7 @@ import io.kinference.core.data.tensor.asTensor import io.kinference.data.ONNXData import io.kinference.graph.Contexts import io.kinference.ndarray.arrays.* -import io.kinference.ndarray.extensions.floor.floor +import io.kinference.ndarray.extensions.floor import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/IsNaN.kt b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/IsNaN.kt index 6082de1e8..87ad00fd0 100644 --- a/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/IsNaN.kt +++ b/inference/inference-core/src/commonMain/kotlin/io/kinference.core/operators/tensor/IsNaN.kt @@ -6,7 +6,7 @@ import io.kinference.core.data.tensor.asTensor import io.kinference.data.ONNXData import io.kinference.graph.Contexts import io.kinference.ndarray.arrays.* -import io.kinference.ndarray.extensions.isNaN.isNaN +import io.kinference.ndarray.extensions.isNaN import io.kinference.operator.* import io.kinference.primitives.types.DataType diff --git a/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/math/SqrtTest.kt b/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/math/SqrtTest.kt new file mode 100644 index 000000000..78329ced9 --- /dev/null +++ b/inference/inference-core/src/commonTest/kotlin/io/kinference/operators/math/SqrtTest.kt @@ -0,0 +1,19 @@ +package io.kinference.operators.math + +import io.kinference.KITestEngine +import io.kinference.utils.TestRunner +import kotlin.test.Test + +class SqrtTest { + private fun getTargetPath(dirName: String) = "sqrt/$dirName/" + + @Test + fun test_sqrt() = TestRunner.runTest { + KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_sqrt")) + } + + @Test + fun test_sqrt_example() = TestRunner.runTest { + KITestEngine.KIAccuracyRunner.runFromResources(getTargetPath("test_sqrt_example")) + } +} diff --git a/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/TFJSOperatorFactory.kt b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/TFJSOperatorFactory.kt index b2cd50abf..c91375e49 100755 --- a/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/TFJSOperatorFactory.kt +++ b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/TFJSOperatorFactory.kt @@ -114,6 +114,7 @@ object TFJSOperatorFactory : OperatorFactory> { "Softmax" -> Softmax(name, version, attributes, inputs, outputs) "Split" -> Split(name, version, attributes, inputs, outputs) "SplitToSequence" -> SplitToSequence(name, version, attributes, inputs, outputs) + "Sqrt" -> Sqrt(name, version, attributes, inputs, outputs) "Squeeze" -> Squeeze(name, version, attributes, inputs, outputs) "Sub" -> Sub(name, version, attributes, inputs, outputs) "Tan" -> Tan(name, version, attributes, inputs, outputs) diff --git a/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/math/Sqrt.kt b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/math/Sqrt.kt new file mode 100644 index 000000000..97a20e600 --- /dev/null +++ b/inference/inference-tfjs/src/jsMain/kotlin/io.kinference.tfjs/operators/math/Sqrt.kt @@ -0,0 +1,58 @@ +package io.kinference.tfjs.operators.math + +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.sqrt +import io.kinference.operator.* +import io.kinference.tfjs.data.tensors.TFJSTensor +import io.kinference.tfjs.data.tensors.asTensor + +sealed class Sqrt( + name: String, + info: OperatorInfo, + attributes: Map>, + inputs: List, + outputs: List +) : Operator(name, info, attributes, inputs, outputs) { + companion object { + private val DEFAULT_VERSION = VersionInfo(sinceVersion = 6) + + operator fun invoke(name: String, version: Int?, attributes: Map>, inputs: List, outputs: List): Sqrt { + return when (version ?: DEFAULT_VERSION.sinceVersion) { + in SqrtVer6.VERSION.asRange() -> SqrtVer6(name, attributes, inputs, outputs) + else -> error("Unsupported version of Sqrt operator: $version") + } + } + } +} + +class SqrtVer6( + name: String, + attributes: Map>, + inputs: List, + outputs: List +) : Sqrt(name, INFO, attributes, inputs, outputs) { + companion object { + private val TYPE_CONSTRAINTS = FLOAT_DATA_TYPES + + private val INPUTS_INFO = listOf( + IOInfo(0, TYPE_CONSTRAINTS, "X", optional = false) + ) + + private val OUTPUTS_INFO = listOf( + IOInfo(0, TYPE_CONSTRAINTS, "Y", optional = false) + ) + + internal val VERSION = VersionInfo(sinceVersion = 6) + private val INFO = OperatorInfo("Sqrt", emptyMap(), INPUTS_INFO, OUTPUTS_INFO, VERSION, domain = OperatorInfo.DEFAULT_DOMAIN) + } + + + override suspend fun > apply(contexts: Contexts, inputs: List): List { + val input = inputs[0]!!.data as NumberNDArrayTFJS + + return listOf(input.sqrt().asTensor("Y")) + } +} diff --git a/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/math/SqrtTest.kt b/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/math/SqrtTest.kt new file mode 100644 index 000000000..3c18cdd79 --- /dev/null +++ b/inference/inference-tfjs/src/jsTest/kotlin/io/kinference/tfjs/operators/math/SqrtTest.kt @@ -0,0 +1,19 @@ +package io.kinference.tfjs.operators.math + +import io.kinference.tfjs.runners.TFJSTestEngine +import io.kinference.utils.TestRunner +import kotlin.test.Test + +class SqrtTest { + private fun getTargetPath(dirName: String) = "sqrt/$dirName/" + + @Test + fun test_sqrt() = TestRunner.runTest { + TFJSTestEngine.TFJSAccuracyRunner.runFromResources(getTargetPath("test_sqrt")) + } + + @Test + fun test_sqrt_example() = TestRunner.runTest { + TFJSTestEngine.TFJSAccuracyRunner.runFromResources(getTargetPath("test_sqrt_example")) + } +} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/PrimitiveElementWise.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/PrimitiveElementWise.kt new file mode 100644 index 000000000..6cee223fa --- /dev/null +++ b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/PrimitiveElementWise.kt @@ -0,0 +1,46 @@ +@file:GeneratePrimitives(DataType.ALL) + +package io.kinference.ndarray.extensions + +import io.kinference.ndarray.arrays.* +import io.kinference.primitives.annotations.GeneratePrimitives +import io.kinference.primitives.types.DataType +import io.kinference.primitives.types.PrimitiveType + +fun PrimitiveNDArray.applyElementWise(func: (PrimitiveType) -> PrimitiveType): MutablePrimitiveNDArray { + val output = MutablePrimitiveNDArray(strides) + + val inputBlockIter = array.blocks.iterator() + val outputBlockIter = output.array.blocks.iterator() + val blockSize = output.array.blockSize + + repeat(output.array.blocksNum) { + val inputBlock = inputBlockIter.next() + val outputBlock = outputBlockIter.next() + + for (idx in 0 until blockSize) { + outputBlock[idx] = func(inputBlock[idx]) + } + } + + return output +} + +fun PrimitiveNDArray.predicateElementWise(predicate: (PrimitiveType) -> Boolean): BooleanNDArray { + val output = MutableBooleanNDArray(strides) + + val inputBlockIter = array.blocks.iterator() + val outputBlockIter = output.array.blocks.iterator() + val blockSize = output.array.blockSize + + repeat(output.array.blocksNum) { + val inputBlock = inputBlockIter.next() + val outputBlock = outputBlockIter.next() + + for (idx in 0 until blockSize) { + outputBlock[idx] = predicate(inputBlock[idx]) + } + } + + return output +} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/PrimitiveFPMath.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/PrimitiveFPMath.kt new file mode 100644 index 000000000..363cfec35 --- /dev/null +++ b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/PrimitiveFPMath.kt @@ -0,0 +1,20 @@ +@file:GeneratePrimitives( + DataType.DOUBLE, + DataType.FLOAT +) + +package io.kinference.ndarray.extensions + +import io.kinference.ndarray.arrays.BooleanNDArray +import io.kinference.ndarray.arrays.PrimitiveNDArray +import io.kinference.ndarray.stubs.* +import io.kinference.primitives.annotations.GeneratePrimitives +import io.kinference.primitives.types.DataType +import kotlin.math.* + +fun PrimitiveNDArray.isNaN(): BooleanNDArray = predicateElementWise { it.isNaN() } + +fun PrimitiveNDArray.ceil(): PrimitiveNDArray = applyElementWise { ceil(it) } +fun PrimitiveNDArray.floor(): PrimitiveNDArray = applyElementWise { floor(it) } + +fun PrimitiveNDArray.sqrt(): PrimitiveNDArray = applyElementWise { sqrt(it) } diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/abs/AbsPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/abs/AbsPrimitive.kt index 0fe1aa1e6..f662a250d 100644 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/abs/AbsPrimitive.kt +++ b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/abs/AbsPrimitive.kt @@ -9,8 +9,8 @@ package io.kinference.ndarray.extensions.abs -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray import io.kinference.ndarray.arrays.PrimitiveNDArray +import io.kinference.ndarray.extensions.applyElementWise import io.kinference.ndarray.stubs.abs import io.kinference.primitives.annotations.GenerateNameFromPrimitives import io.kinference.primitives.annotations.GeneratePrimitives @@ -18,21 +18,4 @@ import io.kinference.primitives.types.DataType import kotlin.math.abs @GenerateNameFromPrimitives -internal fun absPrimitive(array: PrimitiveNDArray): PrimitiveNDArray { - val output = MutablePrimitiveNDArray(array.strides) - - val inputBlockIter = array.array.blocks.iterator() - val outputBlockIter = output.array.blocks.iterator() - val blockSize = output.array.blockSize - - repeat(output.array.blocksNum) { - val inputBlock = inputBlockIter.next() - val outputBlock = outputBlockIter.next() - - for (idx in 0 until blockSize) { - outputBlock[idx] = abs(inputBlock[idx]) - } - } - - return output -} +internal fun absPrimitive(array: PrimitiveNDArray): PrimitiveNDArray = array.applyElementWise { abs(it) } diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/PrimitiveSimpleActivations.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/PrimitiveSimpleActivations.kt new file mode 100644 index 000000000..ba1b66740 --- /dev/null +++ b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/PrimitiveSimpleActivations.kt @@ -0,0 +1,25 @@ +@file:GeneratePrimitives( + DataType.FLOAT, + DataType.DOUBLE +) + +package io.kinference.ndarray.extensions.activations + +import io.kinference.ndarray.arrays.PrimitiveNDArray +import io.kinference.ndarray.extensions.applyElementWise +import io.kinference.ndarray.stubs.* +import io.kinference.primitives.annotations.GeneratePrimitives +import io.kinference.primitives.types.DataType +import kotlin.math.* + +fun PrimitiveNDArray.acos(): PrimitiveNDArray = applyElementWise { acos(it) } +fun PrimitiveNDArray.acosh(): PrimitiveNDArray = applyElementWise { acosh(it) } +fun PrimitiveNDArray.cos(): PrimitiveNDArray = applyElementWise { cos(it) } +fun PrimitiveNDArray.cosh(): PrimitiveNDArray = applyElementWise { cosh(it) } + +fun PrimitiveNDArray.asin(): PrimitiveNDArray = applyElementWise { asin(it) } +fun PrimitiveNDArray.asinh(): PrimitiveNDArray = applyElementWise { asinh(it) } + +fun PrimitiveNDArray.atan(): PrimitiveNDArray = applyElementWise { atan(it) } +fun PrimitiveNDArray.atanh(): PrimitiveNDArray = applyElementWise { atanh(it) } +fun PrimitiveNDArray.tan(): PrimitiveNDArray = applyElementWise { tan(it) } diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/acos/AcosPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/acos/AcosPrimitive.kt deleted file mode 100644 index 18cab58a0..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/acos/AcosPrimitive.kt +++ /dev/null @@ -1,31 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.activations.acos - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.acos -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.acos - -fun PrimitiveNDArray.acos(): PrimitiveNDArray { - val output = MutablePrimitiveNDArray(this.strides) - - val outputIter = output.array.blocks.iterator() - val inputIter = this.array.blocks.iterator() - - repeat(this.array.blocksNum) { - val inputBlock = inputIter.next() - val outputBlock = outputIter.next() - - for (j in outputBlock.indices) { - outputBlock[j] = acos(inputBlock[j]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/acosh/AcoshPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/acosh/AcoshPrimitive.kt deleted file mode 100644 index 7138f1540..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/acosh/AcoshPrimitive.kt +++ /dev/null @@ -1,32 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.activations.acosh - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.acosh -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.acosh - -fun PrimitiveNDArray.acosh(): 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] = acosh(inputBlock[idx]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/asin/AsinPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/asin/AsinPrimitive.kt deleted file mode 100644 index 439bd502d..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/asin/AsinPrimitive.kt +++ /dev/null @@ -1,31 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.activations.asin - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.asin -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.asin - -fun PrimitiveNDArray.asin(): PrimitiveNDArray { - val output = MutablePrimitiveNDArray(this.strides) - - val outputIter = output.array.blocks.iterator() - val inputIter = this.array.blocks.iterator() - - repeat(this.array.blocksNum) { - val inputBlock = inputIter.next() - val outputBlock = outputIter.next() - - for (j in outputBlock.indices) { - outputBlock[j] = asin(inputBlock[j]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/asinh/AsinhPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/asinh/AsinhPrimitive.kt deleted file mode 100644 index 2107f8b29..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/asinh/AsinhPrimitive.kt +++ /dev/null @@ -1,31 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.activations.asinh - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.asinh -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.asinh - -fun PrimitiveNDArray.asinh(): PrimitiveNDArray { - val output = MutablePrimitiveNDArray(this.strides) - - val outputIter = output.array.blocks.iterator() - val inputIter = this.array.blocks.iterator() - - repeat(this.array.blocksNum) { - val inputBlock = inputIter.next() - val outputBlock = outputIter.next() - - for (j in outputBlock.indices) { - outputBlock[j] = asinh(inputBlock[j]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/atan/AtanPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/atan/AtanPrimitive.kt deleted file mode 100644 index 055f4f51e..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/atan/AtanPrimitive.kt +++ /dev/null @@ -1,31 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.activations.atan - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.atan -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.atan - -fun PrimitiveNDArray.atan(): PrimitiveNDArray { - val output = MutablePrimitiveNDArray(this.strides) - - val outputIter = output.array.blocks.iterator() - val inputIter = this.array.blocks.iterator() - - repeat(this.array.blocksNum) { - val inputBlock = inputIter.next() - val outputBlock = outputIter.next() - - for (j in outputBlock.indices) { - outputBlock[j] = atan(inputBlock[j]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/atanh/AtanhPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/atanh/AtanhPrimitive.kt deleted file mode 100644 index 3b4439a92..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/atanh/AtanhPrimitive.kt +++ /dev/null @@ -1,31 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.activations.atanh - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.atanh -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.atanh - -fun PrimitiveNDArray.atanh(): PrimitiveNDArray { - val output = MutablePrimitiveNDArray(this.strides) - - val outputIter = output.array.blocks.iterator() - val inputIter = this.array.blocks.iterator() - - repeat(this.array.blocksNum) { - val inputBlock = inputIter.next() - val outputBlock = outputIter.next() - - for (j in outputBlock.indices) { - outputBlock[j] = atanh(inputBlock[j]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/cos/CosPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/cos/CosPrimitive.kt deleted file mode 100644 index 99dd5179f..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/cos/CosPrimitive.kt +++ /dev/null @@ -1,31 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.activations.cos - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.cos -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.cos - -fun PrimitiveNDArray.cos(): PrimitiveNDArray { - val output = MutablePrimitiveNDArray(this.strides) - - val outputIter = output.array.blocks.iterator() - val inputIter = this.array.blocks.iterator() - - repeat(this.array.blocksNum) { - val inputBlock = inputIter.next() - val outputBlock = outputIter.next() - - for (j in outputBlock.indices) { - outputBlock[j] = cos(inputBlock[j]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/cosh/CoshPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/cosh/CoshPrimitive.kt deleted file mode 100644 index 9cd9c4f24..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/cosh/CoshPrimitive.kt +++ /dev/null @@ -1,32 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.activations.cosh - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.cosh -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.cosh - -fun PrimitiveNDArray.cosh(): 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] = cosh(inputBlock[idx]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/tan/TanPrimitive.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/tan/TanPrimitive.kt deleted file mode 100644 index 34826a03c..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/activations/tan/TanPrimitive.kt +++ /dev/null @@ -1,32 +0,0 @@ -@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 -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/bitwise/not/PrimitiveBitwiseNot.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/bitwise/not/PrimitiveBitwiseNot.kt index da08554d0..68742a38a 100644 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/bitwise/not/PrimitiveBitwiseNot.kt +++ b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/bitwise/not/PrimitiveBitwiseNot.kt @@ -11,28 +11,11 @@ package io.kinference.ndarray.extensions.bitwise.not -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray import io.kinference.ndarray.arrays.PrimitiveNDArray +import io.kinference.ndarray.extensions.applyElementWise import io.kinference.ndarray.stubs.inv import io.kinference.primitives.annotations.GeneratePrimitives import io.kinference.primitives.types.DataType import kotlin.experimental.inv -fun PrimitiveNDArray.bitNot(): 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] = inputBlock[idx].inv() - } - } - - return output -} +fun PrimitiveNDArray.bitNot(): PrimitiveNDArray = applyElementWise { it.inv() } diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/ceil/PrimitiveCeil.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/ceil/PrimitiveCeil.kt deleted file mode 100644 index a36e60891..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/ceil/PrimitiveCeil.kt +++ /dev/null @@ -1,32 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.ceil - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.ceil -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.ceil - -fun PrimitiveNDArray.ceil(): PrimitiveNDArray { - val output = MutablePrimitiveNDArray(strides) - - val inputBlockIter = array.blocks.iterator() - val outputBlockIter = output.array.blocks.iterator() - val blockSize = output.array.blockSize - - repeat(output.array.blocksNum) { - val inputBlock = inputBlockIter.next() - val outputBlock = outputBlockIter.next() - - for (idx in 0 until blockSize) { - outputBlock[idx] = ceil(inputBlock[idx]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/floor/PrimitiveFloor.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/floor/PrimitiveFloor.kt deleted file mode 100644 index 6986ac57f..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/floor/PrimitiveFloor.kt +++ /dev/null @@ -1,32 +0,0 @@ -@file:GeneratePrimitives( - DataType.FLOAT, - DataType.DOUBLE -) - -package io.kinference.ndarray.extensions.floor - -import io.kinference.ndarray.arrays.MutablePrimitiveNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.floor -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType -import kotlin.math.floor - -fun PrimitiveNDArray.floor(): PrimitiveNDArray { - val output = MutablePrimitiveNDArray(strides) - - val inputBlockIter = array.blocks.iterator() - val outputBlockIter = output.array.blocks.iterator() - val blockSize = output.array.blockSize - - repeat(output.array.blocksNum) { - val inputBlock = inputBlockIter.next() - val outputBlock = outputBlockIter.next() - - for (idx in 0 until blockSize) { - outputBlock[idx] = floor(inputBlock[idx]) - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/isInf/PrimitiveIsInf.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/isInf/PrimitiveIsInf.kt index bb59362f7..85b1aac1f 100644 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/isInf/PrimitiveIsInf.kt +++ b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/isInf/PrimitiveIsInf.kt @@ -7,6 +7,7 @@ package io.kinference.ndarray.extensions.isInf import io.kinference.ndarray.arrays.BooleanNDArray import io.kinference.ndarray.arrays.PrimitiveNDArray +import io.kinference.ndarray.extensions.predicateElementWise import io.kinference.ndarray.stubs.* import io.kinference.primitives.annotations.GeneratePrimitives import io.kinference.primitives.types.DataType @@ -26,11 +27,6 @@ private val ONLY_POSITIVE = { x: PrimitiveType -> x == PrimitiveType.POSITIVE_IN * indicates whether the corresponding element in the current NDArray is infinite or not. */ fun PrimitiveNDArray.isInf(detectNegative: Boolean = true, detectPositive: Boolean = true): BooleanNDArray { - val output = BooleanNDArray(strides) - - val inputBlocksIterator = this.array.blocks.iterator() - val outputBlocksIterator = output.array.blocks.iterator() - val detector = when { detectNegative && detectPositive -> PrimitiveType::isInfinite detectNegative -> ONLY_NEGATIVE @@ -38,14 +34,5 @@ fun PrimitiveNDArray.isInf(detectNegative: Boolean = true, detectPositive: Boole else -> error("At least one of detectNegative or detectPositive must be true") } - for (blockNum in 0 until this.array.blocksNum) { - val inputBlock = inputBlocksIterator.next() - val outputBlock = outputBlocksIterator.next() - - for (idx in outputBlock.indices) { - outputBlock[idx] = detector(inputBlock[idx]) - } - } - - return output + return predicateElementWise(detector) } diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/isNaN/PrimitiveIsNaN.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/isNaN/PrimitiveIsNaN.kt deleted file mode 100644 index f256f2c55..000000000 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/extensions/isNaN/PrimitiveIsNaN.kt +++ /dev/null @@ -1,30 +0,0 @@ -@file:GeneratePrimitives( - DataType.DOUBLE, - DataType.FLOAT -) - -package io.kinference.ndarray.extensions.isNaN - -import io.kinference.ndarray.arrays.BooleanNDArray -import io.kinference.ndarray.arrays.PrimitiveNDArray -import io.kinference.ndarray.stubs.isNaN -import io.kinference.primitives.annotations.GeneratePrimitives -import io.kinference.primitives.types.DataType - -fun PrimitiveNDArray.isNaN(): BooleanNDArray { - val output = BooleanNDArray(strides) - - val inputBlockIter = this.array.blocks.iterator() - val outputBlockIter = output.array.blocks.iterator() - - for (blockIdx in 0 until this.array.blocksNum) { - val inputBlock = inputBlockIter.next() - val outputBlock = outputBlockIter.next() - - for (idx in outputBlock.indices) { - outputBlock[idx] = inputBlock[idx].isNaN() - } - } - - return output -} diff --git a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/stubs/PrimitiveMathStubs.kt b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/stubs/PrimitiveMathStubs.kt index 16c8e9027..fbb3552f2 100644 --- a/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/stubs/PrimitiveMathStubs.kt +++ b/ndarray/ndarray-core/src/commonMain/kotlin/io/kinference/ndarray/stubs/PrimitiveMathStubs.kt @@ -28,6 +28,8 @@ internal inline fun exp(x: PrimitiveType): PrimitiveType = throw UnsupportedOper internal fun ceil(x: PrimitiveType): PrimitiveType = throw UnsupportedOperationException() internal fun floor(x: PrimitiveType): PrimitiveType = throw UnsupportedOperationException() +internal fun sqrt(x: PrimitiveType): PrimitiveType = throw UnsupportedOperationException() + internal fun min(a: PrimitiveType, b: PrimitiveType): PrimitiveType = throw UnsupportedOperationException() internal fun max(a: PrimitiveType, b: PrimitiveType): PrimitiveType = throw UnsupportedOperationException() internal fun maxOf(a: PrimitiveType, b: PrimitiveType): PrimitiveType = throw UnsupportedOperationException() diff --git a/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/descriptor.txt b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/descriptor.txt new file mode 100644 index 000000000..887e1c1e4 --- /dev/null +++ b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/descriptor.txt @@ -0,0 +1,2 @@ +test_data_set_0/input_0.pb +test_data_set_0/output_0.pb diff --git a/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/model.onnx b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/model.onnx new file mode 100644 index 000000000..59b5f4b0a --- /dev/null +++ b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/model.onnx @@ -0,0 +1,13 @@ + backend-test:K + +xy"Sqrt test_sqrtZ +x + + + +b +y + + + +B \ No newline at end of file diff --git a/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/test_data_set_0/input_0.pb b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/test_data_set_0/input_0.pb new file mode 100644 index 000000000..c3a1c952e --- /dev/null +++ b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/test_data_set_0/input_0.pb @@ -0,0 +1 @@ +BxJx?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.:=ݚ>b"?6> \ No newline at end of file diff --git a/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/test_data_set_0/output_0.pb b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/test_data_set_0/output_0.pb new file mode 100644 index 000000000..292f9e179 Binary files /dev/null and b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt/test_data_set_0/output_0.pb differ diff --git a/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/descriptor.txt b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/descriptor.txt new file mode 100644 index 000000000..887e1c1e4 --- /dev/null +++ b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/descriptor.txt @@ -0,0 +1,2 @@ +test_data_set_0/input_0.pb +test_data_set_0/output_0.pb diff --git a/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/model.onnx b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/model.onnx new file mode 100644 index 000000000..8236f8c45 --- /dev/null +++ b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/model.onnx @@ -0,0 +1,11 @@ + backend-test:C + +xy"Sqrttest_sqrt_exampleZ +x + + +b +y + + +B \ No newline at end of file diff --git a/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/test_data_set_0/input_0.pb b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/test_data_set_0/input_0.pb new file mode 100644 index 000000000..a9e7f45d2 Binary files /dev/null and b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/test_data_set_0/input_0.pb differ diff --git a/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/test_data_set_0/output_0.pb b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/test_data_set_0/output_0.pb new file mode 100644 index 000000000..1b32d5d74 Binary files /dev/null and b/utils/utils-testing/src/commonMain/resources/sqrt/test_sqrt_example/test_data_set_0/output_0.pb differ