1- package sk.ai.net.safetensor
1+ package sk.ai.net.safetensors
22
33import kotlinx.serialization.json.Json
44import kotlinx.serialization.json.JsonObject
@@ -32,7 +32,7 @@ import sk.ai.net.graph.tensor.shape.Shape
3232 *
3333 * @see <a href="https://huggingface.co/docs/safetensors/index">Hugging Face Safetensors Documentation</a>
3434 */
35- interface SafeTensorReader {
35+ interface SafeTensorsReader {
3636 /* *
3737 * Reads a tensor from the safetensor data.
3838 *
@@ -48,7 +48,7 @@ interface SafeTensorReader {
4848 */
4949 fun getTensorNames (): List <String >
5050
51- companion object {
51+ companion object Companion {
5252 /* *
5353 * Creates a SafeTensorReader from the given byte array.
5454 *
@@ -58,7 +58,7 @@ interface SafeTensorReader {
5858 * @param data The byte array containing the safetensor data.
5959 * @return A SafeTensorReader instance.
6060 */
61- fun fromByteArray (data : ByteArray ): SafeTensorReader = SafeTensorReaderImpl (data)
61+ fun fromByteArray (data : ByteArray ): SafeTensorsReader = SafeTensorsReaderImpl (data)
6262
6363 /* *
6464 * Creates a SafeTensorReader from a resource file.
@@ -71,7 +71,7 @@ interface SafeTensorReader {
7171 * @return A SafeTensorReader instance.
7272 * @throws IllegalArgumentException If the resource could not be found.
7373 */
74- fun fromResource (resourcePath : String ): SafeTensorReader {
74+ fun fromResource (resourcePath : String ): SafeTensorsReader {
7575 val resourceBytes = ResourceUtils .loadResourceAsBytes(resourcePath)
7676 ? : throw IllegalArgumentException (" Resource not found: $resourcePath " )
7777
@@ -91,7 +91,7 @@ interface SafeTensorReader {
9191 * @return A SafeTensorReader instance.
9292 * @throws IllegalArgumentException If the file could not be found or read.
9393 */
94- fun fromFilePath (filePath : String ): SafeTensorReader {
94+ fun fromFilePath (filePath : String ): SafeTensorsReader {
9595 // Default implementation falls back to loading as a resource
9696 // Platform-specific implementations will override this behavior
9797 return fromResource(filePath)
@@ -110,7 +110,7 @@ interface SafeTensorReader {
110110 * @return A SafeTensorReader instance.
111111 * @throws IllegalArgumentException If the file could not be found or read.
112112 */
113- fun fromFile (file : Any ): SafeTensorReader {
113+ fun fromFile (file : Any ): SafeTensorsReader {
114114 // Default implementation falls back to loading as a resource
115115 // Platform-specific implementations will override this behavior
116116 return fromResource(file.toString())
@@ -129,7 +129,7 @@ interface SafeTensorReader {
129129 * The implementation supports different tensor data types (F32, I8) and
130130 * converts them to the appropriate tensor implementation.
131131 */
132- private class SafeTensorReaderImpl (private val data : ByteArray ) : SafeTensorReader {
132+ private class SafeTensorsReaderImpl (private val data : ByteArray ) : SafeTensorsReader {
133133 // Header information
134134 private val headerSize: Long
135135 private val metadata: Map <String , TensorMetadata >
@@ -312,18 +312,3 @@ private data class TensorMetadata(
312312 val dataOffset : Long ,
313313 val dataLength : Long
314314)
315-
316- /* *
317- * Dummy tensor implementation for placeholder purposes.
318- *
319- * This class provides a minimal implementation of the Tensor interface,
320- * returning zero for all element accesses. It's used as a fallback when
321- * a proper tensor implementation cannot be created.
322- *
323- * @property shape The shape of the tensor as a list of dimensions.
324- */
325- private class DummyTensor (override val shape : Shape ) : Tensor {
326- override fun get (vararg indices : Int ): Double {
327- return 0.0
328- }
329- }
0 commit comments