You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
t.MakeLike(tt.reshape(toTorchShape shape), shape=shape)// Use Reshape instead of View to ensure underlying non-contiguous libtorch tensors can be viewed. Internally Reshape uses View if possible, otherwise it copies data to a contiguous tensor and then views.
if shape.Length <> indicesShape.Length then failwithf "Expecting tensorShape (%A) and indicesShape (%A) to have the same number of dimensions" shape indicesShape
527
-
if dim <0|| dim > shape.Length-1then failwithf "Expecting 0<= dim (%A) < tensorShape.Length (%A)" dim shape.Length
528
-
if indicesShape.[dim]<1then failwithf "Expecting indicesShape.[dim] (%A) >= 1" indicesShape.[dim]
526
+
if shape.Length <> indicesShape.Length then failwithf "Expecting tensor (%A) and indices (%A) to have the same number of dimensions" shape indicesShape
527
+
if dim <0|| dim > shape.Length-1then failwithf "Expecting 0<= dim (%A) < tensor dim (%A)" dim shape.Length
528
+
if indicesShape.[dim]<1then failwithf "Expecting indices shape at dim %A (%A) >= 1" dim indicesShape.[dim]
529
+
if indicesDtype <> Dtype.Int32 then failwithf "Expecting indices to have type %A" Dtype.Int32
530
+
531
+
/// Checks if the given shape is appropriate for a scatter operation.
if shape.Length <> indicesShape.Length then failwithf "Expecting tensor (%A) and indices (%A) to have the same number of dimensions" shape indicesShape
534
+
if shape.Length <> destinationShape.Length then failwithf "Expecting tensor (%A) and destination (%A) to have the same number of dimensions" shape destinationShape
535
+
ifnot(contains shape indicesShape)then failwithf "Expecting tensor shape (%A) to contain indices shape (%A)" shape indicesShape
536
+
if dim <0|| dim > shape.Length-1then failwithf "Expecting 0<= dim (%A) < tensor dim (%A)" dim shape.Length
529
537
if indicesDtype <> Dtype.Int32 the
E377
n failwithf "Expecting indices to have type %A" Dtype.Int32
530
538
531
539
/// Checks if the given shape is appropriate for a view operation.
letdim= Shape.completeDim a.dim dim // Handles -1 semantics
1807
+
Shape.checkCanScatter a.shape dim indices.shape indices.dtype destinationShape
1808
+
let inlinefRaw(a:RawTensor)= a.ScatterT(dim, indices.primalRaw, destinationShape)
1809
+
let inlinefTensor(a:Tensor)= a.scatter(dim, indices, destinationShape)
1810
+
let inlinedfFwd(ap,ad:Tensor,fp)= ad.scatter(dim, indices, destinationShape)
1811
+
let inlinedfRev(a)= ScatterT(a, dim, indices)
1812
+
Tensor.OpUnary(a, fRaw, fTensor, dfFwd, dfRev)
1813
+
1799
1814
/// <summary>Returns a new tensor with the same data as the self tensor but of a different shape.</summary>
1800
1815
/// <remarks>
1801
1816
/// The returned tensor shares the same data and must have the same number of elements, but may have a different size.
@@ -2224,44 +2239,26 @@ type Tensor =
2224
2239
if target.shape.[0]<> n then failwithf "Expecting either: input with shape (N,C) and target with shape (N); or input with shape (N,C,d1,d2,...,dk) and target with shape (N,d1,d2,...,dk). Received input.shape %A and target.shape %A" input.shape target.shape
2225
2240
if d <> target.shape.[1..]then failwithf "Expecting either: input with shape (N,C) and target with shape (N); or input with shape (N,C,d1,d2,...,dk) and target with shape (N,d1,d2,...,dk). Received input.shape %A and target.shape %A" input.shape target.shape
// TODO: a.zerosLike() below is to handle non-scalar TensorRs with a scalar derivative Tensor(0.) (representing the initialization before accumulation). This is correct but can be changed to eliminate the extra op.
2955
-
if a.derivative.dim =0then a.derivative <- a.zerosLike()+ a.derivative
2941
+
if a.derivative.dim =0then a.derivative <- a.derivative.expandAs(a)
0 commit comments