Skip to content

Commit b2c7699

Browse files
committed
feat(csharp/Tensor.NET): add save and load method for static class Tensor.
1 parent 2c62fc0 commit b2c7699

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

csharp/Tensor.NET/Tensor.NET.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
88
<PackageId>Tensor.NET</PackageId>
9-
<Version>0.1.0</Version>
9+
<Version>0.1.1</Version>
1010
<Authors>AsakusaRinne</Authors>
1111
<Company>Null</Company>
1212
<Description>

csharp/Tensor.NET/Tensor/Serializer/Tensor.Reader.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ private static TensorMemory<T> ReadDataInternal<T>(FileStream fs, TensorLayout l
6666
ReadContiguousData(fs, res);
6767
return res;
6868
}
69+
}
6970

71+
public static partial class Tensor{
72+
public static Tensor<T> Load<T>(string path) where T : struct, IEquatable<T>, IConvertible{
73+
return TensorReader.Read<T>(path);
74+
}
7075
}
7176
}

csharp/Tensor.NET/Tensor/Serializer/Tensor.writer.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void Write<T>(string path, Tensor<T> tensor, TensorSerializationMo
3333
}
3434

3535
public static async void WriteAsync<T>(string path, Tensor<T> tensor) where T : struct, IEquatable<T>, IConvertible{
36-
36+
throw new NotImplementedException();
3737
}
3838

3939
private static void WriteMagicAndVersion(FileStream fs){
@@ -75,4 +75,10 @@ private static void WriteStrideData<T>(FileStream fs, Tensor<T> tensor) where T
7575
}
7676
}
7777
}
78+
79+
public partial class Tensor<T>{
80+
public void Save(string path, TensorSerializationMode mode = TensorSerializationMode.TensorNET){
81+
TensorWriter.Write(path, this, mode);
82+
}
83+
}
7884
}

csharp/Tensor.NET/Tensor/Tensor.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ public void CopyTo(Tensor<T> target){
9191
}
9292
}
9393

94-
public void Save(string path, TensorSerializationMode mode = TensorSerializationMode.TensorNET){
95-
TensorWriter.Write(path, this, mode);
96-
}
97-
9894
// Returns an enumerator for this list with the given
9995
// permission for removal of elements. If modifications made to the list
10096
// while an enumeration is in progress, the MoveNext and

0 commit comments

Comments
 (0)