11 instantiations of TensorShape
System.Numerics.Tensors (11)
System\Numerics\Tensors\netcore\TensorShape.cs (11)
57
private static readonly TensorShape s_empty = new
TensorShape
(0, [0], [], TensorFlags.None);
876
return new
TensorShape
(linearLength, lengths, strides, pinned ? TensorFlags.IsPinned : TensorFlags.None);
930
TensorShape result = new
TensorShape
(
1035
TensorShape result = new
TensorShape
(linearLength - computedOffset, lengths, strides, TensorFlags.None);
1060
return new
TensorShape
(linearLength: -1, lengths: lengths, strides: strides, flags: flags);
1078
return new
TensorShape
(
1093
return new
TensorShape
(array.Length, lengths, strides, pinned ? TensorFlags.IsPinned : TensorFlags.None);
1115
return new
TensorShape
(linearLength, lengths, strides, pinned ? TensorFlags.IsPinned : TensorFlags.None);
1146
return new
TensorShape
(
1168
return new
TensorShape
(linearLength, lengths, strides, flags);
1470
TensorShape result = new
TensorShape
(
177 references to TensorShape
System.Numerics.Tensors (177)
System\Numerics\Tensors\netcore\ReadOnlyTensorDimensionSpan_1.cs (4)
17
private readonly
TensorShape
_sliceShape;
24
tensor = new ReadOnlyTensorSpan<T>(in tensor._reference,
TensorShape
.Normalize(tensor._shape));
36
_length =
TensorShape
.GetProduct(lengths[..dimension]);
38
_sliceShape =
TensorShape
.Create((dimension != rank) ? lengths[dimension..] : [1], tensor.Strides[dimension..], tensor.IsPinned);
System\Numerics\Tensors\netcore\ReadOnlyTensorSpan_1.cs (23)
29
internal readonly
TensorShape
_shape;
40
_shape =
TensorShape
.Create(array);
75
_shape =
TensorShape
.Create(array, lengths, strides);
99
_shape =
TensorShape
.Create(array, start, lengths, strides);
111
_shape =
TensorShape
.Create(ref reference, span.Length, pinned: false);
141
_shape =
TensorShape
.Create(ref reference, span.Length, lengths, strides, pinned: false);
156
_shape =
TensorShape
.Create(array);
186
_shape =
TensorShape
.Create(array, start, lengths, strides, out nint linearOffset);
201
_shape =
TensorShape
.Create(data, dataLength);
240
_shape =
TensorShape
.Create(data, dataLength, lengths, strides);
246
_shape =
TensorShape
.CreateForView(dataLength, lengths, strides, pinned);
250
internal ReadOnlyTensorSpan(ref readonly T reference, scoped in
TensorShape
shape)
259
get => ref Unsafe.Add(ref _reference, _shape.GetLinearOffset<
TensorShape
.GetOffsetAndLengthForNInt, nint>(indexes));
265
get => ref Unsafe.Add(ref _reference, _shape.GetLinearOffset<
TensorShape
.GetOffsetAndLengthForNIndex, NIndex>(indexes));
411
TensorShape
shape = _shape.Slice<
TensorShape
.GetOffsetAndLengthForSlice, nint>(startIndexes, out nint linearOffset);
421
TensorShape
shape = _shape.Slice<
TensorShape
.GetOffsetAndLengthForNIndex, NIndex>(startIndexes, out nint linearOffset);
431
TensorShape
shape = _shape.Slice<
TensorShape
.GetOffsetAndLengthForNRange, NRange>(ranges, out nint linearOffset);
457
TensorShape
.AreCompatible(destination._shape, _shape, false))
480
nint longestContiguousLength = _shape.GetLongestContiguousLength<
TensorShape
.GetOffsetAndLengthForNInt, nint>(startIndexes, out nint linearOffset);
496
nint longestContiguousLength = _shape.GetLongestContiguousLength<
TensorShape
.GetOffsetAndLengthForNIndex, NIndex>(startIndexes, out nint linearOffset);
System\Numerics\Tensors\netcore\Tensor_1.cs (15)
23
internal readonly
TensorShape
_shape;
29
_shape =
TensorShape
.Create(lengths, strides, pinned);
37
_shape =
TensorShape
.Create(array);
45
_shape =
TensorShape
.Create(array, lengths, strides);
53
_shape =
TensorShape
.Create(array, start, lengths, strides, pinned);
58
internal Tensor(T[] array, in
TensorShape
shape)
67
internal Tensor(T[] array, int start, in
TensorShape
shape)
86
get => ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_values), _start + _shape.GetLinearOffset<
TensorShape
.GetOffsetAndLengthForNInt, nint>(indexes));
92
get => ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_values), _start + _shape.GetLinearOffset<
TensorShape
.GetOffsetAndLengthForNIndex, NIndex>(indexes));
223
TensorShape
shape = _shape.Slice<
TensorShape
.GetOffsetAndLengthForSlice, nint>(startIndexes, out nint linearOffset);
238
TensorShape
shape = _shape.Slice<
TensorShape
.GetOffsetAndLengthForNIndex, NIndex>(startIndexes, out nint linearOffset);
253
TensorShape
shape = _shape.Slice<
TensorShape
.GetOffsetAndLengthForNRange, NRange>(ranges, out nint linearOffset);
System\Numerics\Tensors\netcore\Tensor.cs (41)
136
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensors[0]._shape);
195
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensors[0]._shape);
231
ReadOnlySpan<nint> destinationLengths =
TensorShape
.Normalize(destination._shape).Lengths;
232
if (!
TensorShape
.AreLengthsEquivalentExceptDimension(lengths, destinationLengths, dimension, out nint destinationAxisLength)
294
alignedTarget = new TensorSpan<T>(ref destination._reference,
TensorShape
.WithRank(destination._shape, rank));
325
source = new ReadOnlyTensorSpan<T>(in source._reference,
TensorShape
.WithRank(source._shape, targetRank));
342
private static nint GetConcatenatedLength<T>(int dimension, scoped ReadOnlySpan<Tensor<T>> tensors, in
TensorShape
shape)
349
ReadOnlySpan<nint> sourceLengths =
TensorShape
.Normalize(tensors[i]._shape).Lengths;
350
if (!
TensorShape
.AreLengthsEquivalentExceptDimension(lengths, sourceLengths, dimension, out nint axisLength))
464
source = new ReadOnlyTensorSpan<T>(in source._reference,
TensorShape
.WithRank(source._shape, rank));
471
hasMore =
TensorShape
.AdjustToNextIndex(ranges, dimension - 1, destination.Lengths);
518
TensorShape
shape =
TensorShape
.Create(lengths, strides, pinned);
1738
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensor._shape);
1770
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensor._shape);
2035
if (dimension < -1 || dimension >=
TensorShape
.Normalize(tensor._shape).Rank)
2047
&&
TensorShape
.AreLayoutsTheSame(tensor._shape, destination._shape))
2277
|| !
TensorShape
.AreLengthsEquivalent(tensor.Lengths, other.Lengths))
2302
alignedOther = new ReadOnlyTensorSpan<T>(in other._reference,
TensorShape
.WithRank(other._shape, rank));
2407
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensor._shape);
2709
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensors[0]._shape);
2742
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensors[0]._shape);
2762
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensors[0]._shape);
2767
if (!
TensorShape
.AreLengthsEquivalent(lengths,
TensorShape
.Normalize(tensors[i]._shape).Lengths))
2794
alignedTarget = new TensorSpan<T>(ref destination._reference,
TensorShape
.WithRank(destination._shape, rank + 1));
2881
TensorShape
tmpShape =
TensorShape
.Create(lengths[1..], tensor.Strides[1..], tensor.IsPinned);
3032
if (!
TensorShape
.AreCompatible(destination._shape, tensor._shape, false))
3100
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensor._shape);
3145
ref readonly
TensorShape
shape = ref
TensorShape
.Normalize(tensor._shape);
System\Numerics\Tensors\netcore\TensorDimensionSpan_1.cs (4)
17
private readonly
TensorShape
_sliceShape;
24
tensor = new TensorSpan<T>(ref tensor._reference,
TensorShape
.Normalize(tensor._shape));
36
_length =
TensorShape
.GetProduct(lengths[..dimension]);
38
_sliceShape =
TensorShape
.Create((dimension != rank) ? lengths[dimension..] : [1], tensor.Strides[dimension..], tensor.IsPinned);
System\Numerics\Tensors\netcore\TensorOperation.cs (30)
37
&&
TensorShape
.AreLayoutsTheSame(source._shape, destination._shape))
401
private static ReadOnlyTensorSpan<T> BroadcastSource<T>(in ReadOnlyTensorSpan<T> source, in
TensorShape
destination)
420
TensorShape
shape =
TensorShape
.Create(in source._reference, source._shape.LinearLength, destination.Lengths, strides, source.IsPinned);
425
internal static int GetDenseSliceDimension(in
TensorShape
source, in
TensorShape
destination, in
TensorShape
other = default,
684
TensorShape
destinationShape = GetBroadcastShape(x._shape, y._shape);
747
private static
TensorShape
GetBroadcastShape(in
TensorShape
x, in
TensorShape
y)
749
x = ref
TensorShape
.Normalize(x);
750
y = ref
TensorShape
.Normalize(y);
752
if (
TensorShape
.AreLengthsTheSame(x, y))
768
TensorShape
shape =
TensorShape
.Create(lengths, [], pinned: false);
1240
TensorShape
destinationShape = GetBroadcastShape(x._shape, y._shape);
1455
if (!
TensorShape
.AreCompatible(lengths, x._shape))
1462
if (!
TensorShape
.AreCompatible(x._shape, y._shape, true))
1469
if (!
TensorShape
.AreCompatible(destination._shape, x._shape, false))
1476
if (
TensorShape
.AreCompatible(x._shape, y._shape, true))
1478
if (
TensorShape
.AreCompatible(destination._shape, x._shape, false))
1480
if (
TensorShape
.AreCompatible(destination._shape, y._shape, false))
1493
if (
TensorShape
.AreCompatible(x._shape, y._shape, true))
1495
ref readonly
TensorShape
xShape = ref
TensorShape
.Normalize(x._shape);
1496
ref readonly
TensorShape
yShape = ref
TensorShape
.Normalize(y._shape);
3942
private
TensorShape
.InlineBuffer<T> _inline;
3946
if (rank >
TensorShape
.MaxInlineRank)
System\Numerics\Tensors\netcore\TensorShape.cs (38)
44
internal readonly struct TensorShape : IEquatable<
TensorShape
>
57
private static readonly
TensorShape
s_empty = new TensorShape(0, [0], [], TensorFlags.None);
451
public static bool operator ==(in
TensorShape
left, in
TensorShape
right)
492
public static bool operator !=(in
TensorShape
left, in
TensorShape
right) => !(left == right);
494
public nint AdjustToNextIndex(in
TensorShape
destinationShape, nint linearOffset, Span<nint> indexes)
559
public nint AdjustToPreviousIndex(in
TensorShape
destinationShape, nint linearOffset, Span<nint> indexes)
647
public static bool AreCompatible(in
TensorShape
shape1, in
TensorShape
shape2, bool allowBidirectional)
668
ref readonly
TensorShape
tmpShape = ref shape1;
733
public static bool AreCompatible(in ReadOnlySpan<nint> shape1Lengths, in
TensorShape
shape2)
784
public static ref readonly
TensorShape
Normalize(in
TensorShape
shape)
847
internal static
TensorShape
WithRank(in
TensorShape
shape, int rank)
866
TensorShape
result = CreateForView(shape.LinearLength, lengths, strides, shape.IsPinned);
874
public static
TensorShape
CreateForView(nint linearLength, scoped ReadOnlySpan<nint> lengths, scoped ReadOnlySpan<nint> strides, bool pinned)
879
public static bool AreLayoutsTheSame(in
TensorShape
shape1, in
TensorShape
shape2)
893
public static bool AreLengthsTheSame(in
TensorShape
shape1, in
TensorShape
shape2)
903
public static
TensorShape
Create(Array? array)
930
TensorShape
result = new TensorShape(
946
public static
TensorShape
Create(Array? array, scoped ReadOnlySpan<int> start, scoped ReadOnlySpan<nint> lengths, scoped ReadOnlySpan<nint> strides, out nint linearOffset)
1035
TensorShape
result = new TensorShape(linearLength - computedOffset, lengths, strides, TensorFlags.None);
1057
public static
TensorShape
Create(scoped ReadOnlySpan<nint> lengths, scoped ReadOnlySpan<nint> strides, bool pinned)
1063
public static
TensorShape
Create<T>(T[]? array)
1089
public static
TensorShape
Create<T>(T[]? array, scoped ReadOnlySpan<nint> lengths, scoped ReadOnlySpan<nint> strides, bool pinned = false)
1103
public static
TensorShape
Create<T>(T[]? array, int start, scoped ReadOnlySpan<nint> lengths, scoped ReadOnlySpan<nint> strides, bool pinned = false)
1129
public static
TensorShape
Create<T>(ref readonly T reference, nint linearLength, bool pinned)
1161
public static
TensorShape
Create<T>(ref readonly T reference, nint linearLength, scoped ReadOnlySpan<nint> lengths, scoped ReadOnlySpan<nint> strides, bool pinned)
1182
public static unsafe
TensorShape
Create<T>(T* address, nint linearLength)
1185
public static unsafe
TensorShape
Create<T>(T* address, nint linearLength, scoped ReadOnlySpan<nint> lengths, scoped ReadOnlySpan<nint> strides = default)
1189
=> (obj is
TensorShape
other) && (this == other);
1191
public bool Equals(
TensorShape
other) => (this == other);
1348
public
TensorShape
Slice<TGetOffsetAndLength, T>(ReadOnlySpan<T> state, out nint linearOffset)
1470
TensorShape
result = new TensorShape(
System\Numerics\Tensors\netcore\TensorSpan_1.cs (22)
29
internal readonly
TensorShape
_shape;
38
_shape =
TensorShape
.Create(array);
55
_shape =
TensorShape
.Create(array, lengths, strides);
67
_shape =
TensorShape
.Create(array, start, lengths, strides);
77
_shape =
TensorShape
.Create(ref reference, span.Length, pinned: false);
89
_shape =
TensorShape
.Create(ref reference, span.Length, lengths, strides, pinned: false);
99
_shape =
TensorShape
.Create(array);
111
_shape =
TensorShape
.Create(array, start, lengths, strides, out nint linearOffset);
121
_shape =
TensorShape
.Create(data, dataLength);
134
_shape =
TensorShape
.Create(data, dataLength, lengths, strides);
140
_shape =
TensorShape
.CreateForView(dataLength, lengths, strides, pinned);
144
internal TensorSpan(ref T reference, scoped in
TensorShape
shape)
153
get => ref Unsafe.Add(ref _reference, _shape.GetLinearOffset<
TensorShape
.GetOffsetAndLengthForNInt, nint>(indexes));
159
get => ref Unsafe.Add(ref _reference, _shape.GetLinearOffset<
TensorShape
.GetOffsetAndLengthForNIndex, NIndex>(indexes));
301
TensorShape
shape = _shape.Slice<
TensorShape
.GetOffsetAndLengthForSlice, nint>(startIndexes, out nint linearOffset);
311
TensorShape
shape = _shape.Slice<
TensorShape
.GetOffsetAndLengthForNIndex, NIndex>(startIndexes, out nint linearOffset);
321
TensorShape
shape = _shape.Slice<
TensorShape
.GetOffsetAndLengthForNRange, NRange>(ranges, out nint linearOffset);
344
nint longestContiguousLength = _shape.GetLongestContiguousLength<
TensorShape
.GetOffsetAndLengthForNInt, nint>(startIndexes, out nint linearOffset);
360
nint longestContiguousLength = _shape.GetLongestContiguousLength<
TensorShape
.GetOffsetAndLengthForNIndex, NIndex>(startIndexes, out nint linearOffset);