File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff 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 ( )
Original file line number Diff line number Diff line change 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✅ ❌ 🚀 🔵
You can’t perform that action at this time.
0 commit comments