@@ -12,25 +12,25 @@ import sk.ainet.core.tensor.Tensor
1212/* *
1313 * Creates a tensor from byte data using the factory registry.
1414 * This provides a convenient way to load tensors from GGUF files and similar formats.
15- *
15+ *
1616 * Task 5.1 & 5.2: Extension functions for easy GGUF-style loading and Tensor.fromBytes method
17- *
17+ *
1818 * @param dtype The DType instance indicating the tensor type
1919 * @param shape The desired shape of the tensor
2020 * @param data The byte array containing the tensor data
2121 * @return A new tensor instance
2222 * @throws IllegalArgumentException if no factory is registered for the given DType
2323 * @throws IllegalArgumentException if shape or data validation fails
24- *
24+ *
2525 * Example usage:
2626 * ```kotlin
2727 * val floatData = byteArrayOf(/* float bytes */)
2828 * val tensor = fromBytes(FP32, Shape(2, 3), floatData)
2929 * ```
3030 */
3131public fun fromBytes (
32- dtype : DType ,
33- shape : Shape ,
32+ dtype : DType ,
33+ shape : Shape ,
3434 data : ByteArray
3535): Tensor <* , * > {
3636 return TensorFactoryRegistry .createTensor(dtype, shape, data)
@@ -40,13 +40,13 @@ public fun fromBytes(
4040/* *
4141 * Batch tensor creation for loading multiple tensors from GGUF files efficiently.
4242 * This method can optimize memory allocation and validation for multiple tensor creation.
43- *
43+ *
4444 * Task 5.3: Implement batch tensor creation for multiple tensors
45- *
45+ *
4646 * @param tensors List of tensor specifications (dtype, shape, data, optional name)
4747 * @return Map of tensor names (or indices as strings) to created tensors
4848 * @throws IllegalArgumentException if any tensor creation fails
49- *
49+ *
5050 * Example usage:
5151 * ```kotlin
5252 * val specs = listOf(
@@ -60,7 +60,7 @@ public fun createBatch(
6060 tensors : List <TensorSpec >
6161): Map <String , Tensor <* , * >> {
6262 val result = mutableMapOf<String , Tensor <* , * >>()
63-
63+
6464 for ((index, spec) in tensors.withIndex()) {
6565 val tensorName = spec.name ? : " tensor_$index "
6666 try {
@@ -70,13 +70,13 @@ public fun createBatch(
7070 throw IllegalArgumentException (" Batch tensor creation failed at tensor '$tensorName ': ${e.message} " , e)
7171 }
7272 }
73-
73+
7474 return result
7575}
7676
7777/* *
7878 * Data class representing a tensor specification for batch creation.
79- *
79+ *
8080 * @param dtype The tensor data type
8181 * @param shape The tensor shape
8282 * @param data The raw byte data
@@ -114,17 +114,17 @@ public data class TensorSpec(
114114/* *
115115 * Support for custom factory registration by external libraries.
116116 * This allows third-party libraries to register their own DType factories.
117- *
117+ *
118118 * Task 5.4: Add support for custom factory registration by external libraries
119- *
119+ *
120120 * @param factory The custom factory implementation
121121 * @throws IllegalArgumentException if a factory is already registered for this DType
122- *
122+ *
123123 * Example usage:
124124 * ```kotlin
125125 * class CustomDType : DType { /* implementation */ }
126126 * class CustomTensorFactory : TensorFromBytesFactory<CustomDType, Float> { /* implementation */ }
127- *
127+ *
128128 * Tensor.registerCustomFactory<CustomDType>(CustomTensorFactory())
129129 * ```
130130 */
@@ -140,9 +140,9 @@ public inline fun <reified D : DType> registerCustomFactory(
140140/* *
141141 * Fluent API builder for common tensor creation patterns.
142142 * This provides a more readable way to create tensors with validation and error handling.
143- *
143+ *
144144 * Task 5.5: Create fluent API for common tensor creation patterns
145- *
145+ *
146146 * Example usage:
147147 * ```kotlin
148148 * val tensor = tensorBuilder()
@@ -220,9 +220,9 @@ public class TensorBuilder {
220220 */
221221 public fun build (): Tensor <* , * > {
222222 val finalDType = dtype ? : throw IllegalStateException (" DType must be specified" )
223- val finalShape = shape ? : throw IllegalStateException (" Shape must be specified" )
223+ val finalShape = shape ? : throw IllegalStateException (" Shape must be specified" )
224224 val finalData = data ? : throw IllegalStateException (" Data must be specified" )
225-
225+
226226 return try {
227227 TensorFactoryRegistry .createTensor(finalDType, finalShape, finalData)
228228 } catch (e: Exception ) {
0 commit comments