Skip to content

Commit 797306f

Browse files
authored
Avoid a LINQ usage in tensor extensions (#109405)
* Avoid a LINQ usage in tensor extensions This one, in particular, was causing an error with upcoming compiler changes: /vmr/src/runtime/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/QCallHandles.cs(39,26): warning CS9265: Field 'ByteRef._ref' is never ref-assigned to, and will always have its default value (null reference) [/vmr/src/runtime/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj] /vmr/src/runtime/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs(1168,30): warning CS8619: Nullability of reference types in value of type 'string[]' doesn't match target type 'Span<string?>'. [/vmr/src/runtime/src/libraries/System.Net.Http/src/System.Net.Http.csproj::TargetFramework=net10.0-linux] /vmr/src/runtime/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs(1208,42): warning CS8620: Argument of type 'string[]' cannot be used for parameter 'values' of type 'Span<string?>' in 'void HttpHeaders.ReadStoreValues<object?>(Span<string?> values, object? storeValue, HttpHeaderParser? parser, ref int currentIndex)' due to differences in the nullability of reference types. [/vmr/src/runtime/src/libraries/System.Net.Http/src/System.Net.Http.csproj::TargetFramework=net10.0-linux] /vmr/src/runtime/src/libraries/System.Net.Http/src/System/Net/Http/Headers/HttpHeaders.cs(1209,42): warning CS8620: Argument of type 'string[]' cannot be used for parameter 'values' of type 'Span<string?>' in 'void HttpHeaders.ReadStoreValues<string?>(Span<string?> values, object? storeValue, HttpHeaderParser? parser, ref int currentIndex)' due to differences in the nullability of reference types. [/vmr/src/runtime/src/libraries/System.Net.Http/src/System.Net.Http.csproj::TargetFramework=net10.0-linux] /vmr/src/runtime/src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorExtensions.cs(2661,56): error CS0023: Operator '.' cannot be applied to operand of type 'void' [/vmr/src/runtime/src/libraries/System.Numerics.Tensors/src/System.Numerics.Tensors.csproj::TargetFramework=net10.0] 4 Warning(s) 1 Error(s) * Fold into one loop * Remove unnecessary wrapper
1 parent 026f615 commit 797306f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libraries/System.Numerics.Tensors/src/System/Numerics/Tensors/netcore/TensorExtensions.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2658,8 +2658,14 @@ public static Tensor<T> PermuteDimensions<T>(this Tensor<T> tensor, params ReadO
26582658

26592659
if (dimensions.IsEmpty)
26602660
{
2661-
lengths = tensor._lengths.Reverse().ToArray();
2662-
permutation = Enumerable.Range(0, tensor.Rank).Reverse().ToArray();
2661+
int[] tempPermutation = new int[tensor.Rank];
2662+
for (int i = 0; i < tensor.Rank; i++)
2663+
{
2664+
lengths[i] = tensor._lengths[tensor.Rank - 1 - i];
2665+
tempPermutation[i] = tensor.Rank - 1 - i;
2666+
}
2667+
2668+
permutation = tempPermutation;
26632669
}
26642670
else
26652671
{

0 commit comments

Comments
 (0)