Skip to content

Commit e8702cb

Browse files
authored
Merge pull request #7 from interesaaat/LibTorchSharpFirstTest
Added sparse tensors plus few fixes.
2 parents 44712c1 + 6e33484 commit e8702cb

File tree

5 files changed

+744
-446
lines changed

5 files changed

+744
-446
lines changed

Test/TorchSharp/TorchSharp.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ public void InitUniform()
150150
}
151151
}
152152

153+
[TestMethod]
154+
public void TestSparse()
155+
{
156+
using (var i = LongTensor.From(new long[] { 0, 1, 1, 2, 0, 2 }, new long[] { 2, 3 }))
157+
using (var v = FloatTensor.From(new float[] { 3, 4, 5 }, new long[] { 3 }))
158+
{
159+
var sparse = FloatTensor.Sparse(i, v, new long[] { 2, 3 });
160+
161+
Assert.IsNotNull(sparse);
162+
Assert.IsTrue(sparse.IsSparse);
163+
}
164+
}
165+
153166
[TestMethod]
154167
public void CopyCpuToCuda()
155168
{

TorchSharp/Tensor/ITorchTensor.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@ public interface ITorchTensor<T> : IDisposable
1414

1515
string Device { get; }
1616

17-
ITorchTensor<T> Cpu();
18-
19-
ITorchTensor<T> Cuda();
20-
2117
Span<T> Data { get; }
2218

2319
T Item { get; }
2420

21+
bool IsSparse { get; }
22+
23+
bool IsVariable { get; }
24+
2525
long GetTensorDimension(int dim);
2626

2727
long GetTensorStride(int dim);
2828

29+
ITorchTensor<T> Cpu();
30+
31+
ITorchTensor<T> Cuda();
32+
2933
void Backward();
3034

3135
ITorchTensor<float> Grad();

0 commit comments

Comments
 (0)