Skip to content

Commit cc25f02

Browse files
committed
feat(csharp/Tensor.NET): add clone method implementation.
1 parent b2c7699 commit cc25f02

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

csharp/Tensor.NET/Tensor/Tensor.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public T this[params int[] indices]{
6464
}
6565
}
6666

67+
/// <summary>
68+
/// Make the tensor contiguous. Note that if the tensor is already contiguous, the method will return itself.
69+
/// If the tensor is not contiguous, a new contiguous tensor will be returned.
70+
/// </summary>
71+
/// <returns></returns>
6772
public Tensor<T> ToContiguousTensor(){
6873
Tensor<T> res = new Tensor<T>(new TensorLayout(TLayout as TensorShape, TLayout.DType));
6974
this.CopyTo(res);
@@ -105,9 +110,13 @@ IEnumerator<T> IEnumerable<T>.GetEnumerator()
105110
IEnumerator IEnumerable.GetEnumerator()
106111
=> new TensorEnumerator<T>(this);
107112

108-
[Obsolete("This method need to be revised in the future because the tensor may not be contiguous", true)]
109113
public object Clone(){
110-
return new Tensor<T>(new TensorMemory<T>(TMemory.AsSpan()), new TensorLayout(TLayout));
114+
if(TLayout.IsContiguous()){
115+
return new Tensor<T>(new TensorMemory<T>(TMemory.AsSpan()), new TensorLayout(TLayout));
116+
}
117+
else{
118+
return ToContiguousTensor();
119+
}
111120
}
112121

113122
public override string ToString()

doc/TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
| Add arrange op | | p0 | Complete ✅ |
5555
| Add zeros_like, ones_like, fill_like methods | | p0 | Complete ✅ |
5656
| Add flatten method | | p0 | Complete ✅ |
57-
| Add max, min, mean op | | p0 | Waiting 🔵 |
57+
| Add max, min, mean op | | p0 | Complete ✅ |
5858

5959

6060
✅ ❌ 🚀 🔵

0 commit comments

Comments
 (0)