Skip to content

Commit 8a61b39

Browse files
committed
Rename fromGGUFData to fromByteArray in factories.
Related-To: #121 #95
1 parent 82843c8 commit 8a61b39

13 files changed

Lines changed: 71 additions & 71 deletions

File tree

skainet-core/skainet-tensors/src/commonMain/kotlin/sk/ainet/core/tensor/factory/FP16TensorFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public object FP16TensorFactory : TensorFactoryRegistry.TensorFromBytesFactory<F
2828
* @return A new FP16 tensor instance
2929
* @throws NotImplementedError Currently not implemented
3030
*/
31-
override fun fromGGUFData(shape: Shape, data: ByteArray): Tensor<FP16, Float> {
31+
override fun fromByteArray(shape: Shape, data: ByteArray): Tensor<FP16, Float> {
3232
// Validate data size for FP16 (2 bytes per value)
3333
val expectedBytes = shape.volume * 2
3434
require(data.size == expectedBytes) {

skainet-core/skainet-tensors/src/commonMain/kotlin/sk/ainet/core/tensor/factory/FP32TensorFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public object FP32TensorFactory : TensorFactoryRegistry.TensorFromBytesFactory<F
1919
* @return A new CpuTensorFP32 instance
2020
* @throws IllegalArgumentException if data size doesn't match expected float count
2121
*/
22-
override fun fromGGUFData(shape: Shape, data: ByteArray): Tensor<FP32, Float> {
22+
override fun fromByteArray(shape: Shape, data: ByteArray): Tensor<FP32, Float> {
2323
// Validate input data size matches shape requirements
2424
val expectedFloatCount = shape.volume
2525
val expectedByteSize = expectedFloatCount * 4 // 4 bytes per float

skainet-core/skainet-tensors/src/commonMain/kotlin/sk/ainet/core/tensor/factory/Int32TensorFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public object Int32TensorFactory : TensorFactoryRegistry.TensorFromBytesFactory<
1818
* @return A new CpuTensorInt32 instance
1919
* @throws IllegalArgumentException if data size doesn't match expected int count
2020
*/
21-
override fun fromGGUFData(shape: Shape, data: ByteArray): Tensor<Int32, Int> {
21+
override fun fromByteArray(shape: Shape, data: ByteArray): Tensor<Int32, Int> {
2222
// Validate input data size matches shape requirements
2323
val expectedIntCount = shape.volume
2424
val expectedByteSize = expectedIntCount * 4 // 4 bytes per int

skainet-core/skainet-tensors/src/commonMain/kotlin/sk/ainet/core/tensor/factory/Int4TensorFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public object Int4TensorFactory : TensorFactoryRegistry.TensorFromBytesFactory<I
3838
* @return A new Int4 tensor instance
3939
* @throws NotImplementedError Currently not implemented
4040
*/
41-
override fun fromGGUFData(shape: Shape, data: ByteArray): Tensor<Int4, Byte> {
41+
override fun fromByteArray(shape: Shape, data: ByteArray): Tensor<Int4, Byte> {
4242
// Validate data size for packed Int4 (2 values per byte, rounded up)
4343
val expectedBytes = (shape.volume + 1) / 2 // Ceiling division for odd volumes
4444
require(data.size == expectedBytes) {

skainet-core/skainet-tensors/src/commonMain/kotlin/sk/ainet/core/tensor/factory/Int8TensorFactory.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public object Int8TensorFactory : TensorFactoryRegistry.TensorFromBytesFactory<I
1818
* @return A new CpuTensorInt8 instance
1919
* @throws IllegalArgumentException if data size doesn't match expected byte count
2020
*/
21-
override fun fromGGUFData(shape: Shape, data: ByteArray): Tensor<Int8, Byte> {
21+
override fun fromByteArray(shape: Shape, data: ByteArray): Tensor<Int8, Byte> {
2222
// Validate input data size matches shape requirements
2323
val expectedByteCount = shape.volume
2424

@@ -36,13 +36,13 @@ public object Int8TensorFactory : TensorFactoryRegistry.TensorFromBytesFactory<I
3636

3737
/**
3838
* Creates a tensor from byte data with validation.
39-
* This method is identical to fromGGUFData since Int8 doesn't need endianness conversion.
39+
* This method is identical to fromByteArray since Int8 doesn't need endianness conversion.
4040
* @param shape The desired shape of the tensor
4141
* @param data The byte array containing the tensor data
4242
* @return A new CpuTensorInt8 instance
4343
*/
4444
public fun fromByteData(shape: Shape, data: ByteArray): Tensor<Int8, Byte> {
45-
return fromGGUFData(shape, data)
45+
return fromByteArray(shape, data)
4646
}
4747

4848
/**

skainet-core/skainet-tensors/src/commonMain/kotlin/sk/ainet/core/tensor/factory/TensorFactoryDocumentation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ import sk.ainet.core.tensor.Tensor
146146
*
147147
* // Example: Custom factory for Q4_0
148148
* object Q4_0TensorFactory : TensorFactoryRegistry.TensorFromBytesFactory<Q4_0, Byte> {
149-
* override fun fromGGUFData(shape: Shape, data: ByteArray): Tensor<Q4_0, Byte> {
149+
* override fun fromByteArray(shape: Shape, data: ByteArray): Tensor<Q4_0, Byte> {
150150
* // Validate packed 4-bit data
151151
* val expectedBytes = (shape.volume + 1) / 2 // 2 values per byte
152152
* require(data.size == expectedBytes) {

skainet-core/skainet-tensors/src/commonMain/kotlin/sk/ainet/core/tensor/factory/TensorFactoryRegistry.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public object TensorFactoryRegistry {
3232
* @param data The byte array containing the tensor data
3333
* @return A new tensor instance
3434
*/
35-
public fun fromGGUFData(shape: Shape, data: ByteArray): Tensor<T, V>
35+
public fun fromByteArray(shape: Shape, data: ByteArray): Tensor<T, V>
3636
}
3737

3838
/**
@@ -67,7 +67,7 @@ public object TensorFactoryRegistry {
6767
// 4.5: Add logging/debugging support for factory operations
6868
try {
6969
@Suppress("UNCHECKED_CAST")
70-
val result = (factory as TensorFromBytesFactory<DType, Any>).fromGGUFData(shape, data)
70+
val result = (factory as TensorFromBytesFactory<DType, Any>).fromByteArray(shape, data)
7171

7272
// Debug logging (can be enabled by setting debugLogging flag)
7373
if (debugLogging) {

skainet-core/skainet-tensors/src/commonMain/kotlin/sk/ainet/core/tensor/factory/TernaryTensorFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public object TernaryTensorFactory : TensorFactoryRegistry.TensorFromBytesFactor
4242
* @return A new Ternary tensor instance
4343
* @throws NotImplementedError Currently not implemented
4444
*/
45-
override fun fromGGUFData(shape: Shape, data: ByteArray): Tensor<Ternary, Byte> {
45+
override fun fromByteArray(shape: Shape, data: ByteArray): Tensor<Ternary, Byte> {
4646
// Validate data size for packed Ternary (4 values per byte, rounded up)
4747
val expectedBytes = (shape.volume + 3) / 4 // Ceiling division for non-multiples of 4
4848
require(data.size == expectedBytes) {

skainet-core/skainet-tensors/src/commonTest/kotlin/sk/ainet/core/tensor/factory/FP32TensorFactoryTest.kt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class FP32TensorFactoryTest {
4040
val floats = floatArrayOf(1.0f, 2.0f, 3.0f, 4.0f)
4141
val bytes = createFloatBytes(floats)
4242

43-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
43+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
4444

4545
assertNotNull(tensor, "Tensor should be created")
4646
assertEquals(shape, tensor.shape, "Shape should match")
@@ -59,7 +59,7 @@ class FP32TensorFactoryTest {
5959
val floats = floatArrayOf(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f)
6060
val bytes = createFloatBytes(floats)
6161

62-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
62+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
6363

6464
assertNotNull(tensor, "Tensor should be created")
6565
assertEquals(shape, tensor.shape, "Shape should match")
@@ -81,7 +81,7 @@ class FP32TensorFactoryTest {
8181
val floats = floatArrayOf(1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f)
8282
val bytes = createFloatBytes(floats)
8383

84-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
84+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
8585

8686
assertNotNull(tensor, "Tensor should be created")
8787
assertEquals(shape, tensor.shape, "Shape should match")
@@ -100,7 +100,7 @@ class FP32TensorFactoryTest {
100100
val floats = FloatArray(16) { (it + 1).toFloat() } // [1.0, 2.0, ..., 16.0]
101101
val bytes = createFloatBytes(floats)
102102

103-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
103+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
104104

105105
assertNotNull(tensor, "Tensor should be created")
106106
assertEquals(shape, tensor.shape, "Shape should match")
@@ -118,7 +118,7 @@ class FP32TensorFactoryTest {
118118
val floats = FloatArray(10000) { it.toFloat() }
119119
val bytes = createFloatBytes(floats)
120120

121-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
121+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
122122

123123
assertNotNull(tensor, "Large tensor should be created")
124124
assertEquals(shape, tensor.shape, "Shape should match")
@@ -147,7 +147,7 @@ class FP32TensorFactoryTest {
147147
val shape = Shape(8)
148148
val bytes = createFloatBytes(specialFloats)
149149

150-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
150+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
151151

152152
assertNotNull(tensor, "Tensor with special values should be created")
153153
assertEquals(shape, tensor.shape, "Shape should match")
@@ -170,7 +170,7 @@ class FP32TensorFactoryTest {
170170
val wrongSizeBytes = ByteArray(12) // Only 12 bytes (3 floats)
171171

172172
assertFailsWith<IllegalArgumentException>("Should throw for wrong byte array size") {
173-
FP32TensorFactory.fromGGUFData(shape, wrongSizeBytes)
173+
FP32TensorFactory.fromByteArray(shape, wrongSizeBytes)
174174
}
175175
}
176176

@@ -182,13 +182,13 @@ class FP32TensorFactoryTest {
182182
// Test with zero dimension
183183
assertFailsWith<IllegalArgumentException>("Should throw for zero dimension") {
184184
val invalidShape = Shape(0, 4)
185-
FP32TensorFactory.fromGGUFData(invalidShape, bytes)
185+
FP32TensorFactory.fromByteArray(invalidShape, bytes)
186186
}
187187

188188
// Test with negative dimension
189189
assertFailsWith<IllegalArgumentException>("Should throw for negative dimension") {
190190
val invalidShape = Shape(-1, 4)
191-
FP32TensorFactory.fromGGUFData(invalidShape, bytes)
191+
FP32TensorFactory.fromByteArray(invalidShape, bytes)
192192
}
193193
}
194194

@@ -199,7 +199,7 @@ class FP32TensorFactoryTest {
199199
val emptyBytes = ByteArray(0)
200200

201201
assertFailsWith<IllegalArgumentException>("Should throw for empty byte array") {
202-
FP32TensorFactory.fromGGUFData(shape, emptyBytes)
202+
FP32TensorFactory.fromByteArray(shape, emptyBytes)
203203
}
204204
}
205205

@@ -210,7 +210,7 @@ class FP32TensorFactoryTest {
210210
val misalignedBytes = ByteArray(7) // Not divisible by 4
211211

212212
assertFailsWith<IllegalArgumentException>("Should throw for misaligned bytes") {
213-
FP32TensorFactory.fromGGUFData(shape, misalignedBytes)
213+
FP32TensorFactory.fromByteArray(shape, misalignedBytes)
214214
}
215215
}
216216

@@ -221,7 +221,7 @@ class FP32TensorFactoryTest {
221221
val floats = floatArrayOf(42.0f)
222222
val bytes = createFloatBytes(floats)
223223

224-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
224+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
225225

226226
assertNotNull(tensor, "Minimal tensor should be created")
227227
assertEquals(shape, tensor.shape, "Shape should match")
@@ -239,7 +239,7 @@ class FP32TensorFactoryTest {
239239
val floats = FloatArray(size) { it.toFloat() }
240240
val bytes = createFloatBytes(floats)
241241

242-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
242+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
243243

244244
assertNotNull(tensor, "Tensor of size $size should be created")
245245
assertEquals(shape, tensor.shape, "Shape should match for size $size")
@@ -273,7 +273,7 @@ class FP32TensorFactoryTest {
273273
val floats = FloatArray(expectedVolume) { (it + 1).toFloat() }
274274
val bytes = createFloatBytes(floats)
275275

276-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
276+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
277277

278278
assertNotNull(tensor, "Tensor with shape $shape should be created")
279279
assertEquals(shape, tensor.shape, "Shape should match for $shape")
@@ -296,7 +296,7 @@ class FP32TensorFactoryTest {
296296
val shape = Shape(6)
297297
val bytes = createFloatBytes(preciseFloats)
298298

299-
val tensor = FP32TensorFactory.fromGGUFData(shape, bytes)
299+
val tensor = FP32TensorFactory.fromByteArray(shape, bytes)
300300

301301
assertNotNull(tensor, "Precision tensor should be created")
302302
assertEquals(shape, tensor.shape, "Shape should match")

0 commit comments

Comments
 (0)