@@ -2354,6 +2354,20 @@ public class CpuBackend : ComputeBackend<FP32, Float> {
23542354 })
23552355 }
23562356
2357+ override fun fromArray (
2358+ shape : Shape ,
2359+ data : FloatArray
2360+ ): Tensor <FP32 , Float > {
2361+ return CpuTensorFP32 .fromArray(shape, data)
2362+ }
2363+
2364+ override fun fromArray (
2365+ shape : Shape ,
2366+ data : IntArray
2367+ ): Tensor <FP32 , Float > {
2368+ return CpuTensorFP32 .fromArray(shape, FloatArray (data.size) { data[it].toFloat() })
2369+ }
2370+
23572371 private fun generateNormalDistribution (random : kotlin.random.Random , mean : Double , std : Double ): Double {
23582372 // Box-Muller transform for generating normal distribution
23592373 val u1 = random.nextDouble()
@@ -2566,6 +2580,20 @@ public class CpuBackendInt8 : ComputeBackend<Int8, Byte> {
25662580 random.nextInt(min.toInt().coerceAtLeast(- 128 ), max.toInt().coerceAtMost(127 ) + 1 ).toByte()
25672581 })
25682582
2583+ override fun fromArray (
2584+ shape : Shape ,
2585+ data : FloatArray
2586+ ): Tensor <Int8 , Byte > {
2587+ return CpuTensorInt8 .fromArray(shape, ByteArray (data.size) { data[it].toInt().coerceIn(- 128 , 127 ).toByte() })
2588+ }
2589+
2590+ override fun fromArray (
2591+ shape : Shape ,
2592+ data : IntArray
2593+ ): Tensor <Int8 , Byte > {
2594+ return CpuTensorInt8 .fromArray(shape, ByteArray (data.size) { data[it].coerceIn(- 128 , 127 ).toByte() })
2595+ }
2596+
25692597 private fun generateNormalDistributionInt8 (random : kotlin.random.Random , mean : Double , std : Double ): Byte {
25702598 // Box-Muller transform for generating normal distribution
25712599 val u1 = random.nextDouble()
@@ -2777,6 +2805,20 @@ public class CpuBackendInt32 : ComputeBackend<Int32, Int> {
27772805 random.nextInt(min.toInt(), max.toInt() + 1 )
27782806 })
27792807
2808+ override fun fromArray (
2809+ shape : Shape ,
2810+ data : FloatArray
2811+ ): Tensor <Int32 , Int > {
2812+ return CpuTensorInt32 .fromArray(shape, IntArray (data.size) { data[it].toInt() })
2813+ }
2814+
2815+ override fun fromArray (
2816+ shape : Shape ,
2817+ data : IntArray
2818+ ): Tensor <Int32 , Int > {
2819+ return CpuTensorInt32 .fromArray(shape, data)
2820+ }
2821+
27802822 private fun generateNormalDistributionInt32 (random : kotlin.random.Random , mean : Double , std : Double ): Int {
27812823 // Box-Muller transform for generating normal distribution
27822824 val u1 = random.nextDouble()
@@ -3533,6 +3575,20 @@ public class CpuBackendFP16 : ComputeBackend<FP16, Float> {
35333575 (random.nextDouble() * (max - min) + min).toFloat()
35343576 })
35353577
3578+ override fun fromArray (
3579+ shape : Shape ,
3580+ data : FloatArray
3581+ ): Tensor <FP16 , Float > {
3582+ return CpuTensorFP16 .fromArray(shape, data)
3583+ }
3584+
3585+ override fun fromArray (
3586+ shape : Shape ,
3587+ data : IntArray
3588+ ): Tensor <FP16 , Float > {
3589+ return CpuTensorFP16 .fromArray(shape, FloatArray (data.size) { data[it].toFloat() })
3590+ }
3591+
35363592 private fun generateNormalDistributionFP16 (random : kotlin.random.Random , mean : Double , std : Double ): Float {
35373593 // Box-Muller transform for generating normal distribution
35383594 val u1 = random.nextDouble()
0 commit comments