Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
003fcd3
Ensure the DynamicallyAccessedMembersAnalyzer doesn't crash for new l…
tannergooding Jul 22, 2025
166c3d4
Adding the extensions for operator + and operator +=
tannergooding Jul 22, 2025
1a797d8
Adding the extensions for operator / and operator /=
tannergooding Jul 22, 2025
9688da1
Adding the extensions for operator * and operator *=
tannergooding Jul 22, 2025
b79804b
Adding the extensions for operator - and operator -=
tannergooding Jul 22, 2025
b6e34c4
Adding the extensions for operator & and operator &=
tannergooding Jul 22, 2025
237895f
Adding the extensions for operator | and operator |=
tannergooding Jul 22, 2025
939e9d3
Adding the extensions for operator ^ and operator ^=
tannergooding Jul 22, 2025
2eab0d8
Adding the extensions for operator ~
tannergooding Jul 22, 2025
58d8f1c
Adding the extensions for operator - (unary)
tannergooding Jul 22, 2025
8c00f6e
Adding the extensions for operator + (unary)
tannergooding Jul 22, 2025
6aa4108
Adding the extensions for operator << and operator <<=
tannergooding Jul 22, 2025
bebb06f
Adding the extensions for operator >> and operator >>=
tannergooding Jul 23, 2025
21ca60d
Adding the extensions for operator >>> and operator >>>=
tannergooding Jul 23, 2025
c38c44b
Adding the extensions for operator ++
tannergooding Jul 23, 2025
6ccf176
Adding the extensions for operator --
tannergooding Jul 23, 2025
f80fc86
Ensure the extension member order in the ref matches the impl
tannergooding Jul 24, 2025
82baad5
Update CompatibilitySuppressions for a fixed parameter name in an exp…
tannergooding Jul 24, 2025
ce60d19
Change TrimAnalysisVisitor.VisitParameterReference to skip parameters…
tannergooding Jul 24, 2025
cde89cc
Merge branch 'main' into fix-112781
tannergooding Aug 3, 2025
52ca7ac
Apply suggestions from code review
tannergooding Aug 3, 2025
d025787
Merge branch 'main' into fix-112781
tannergooding Aug 5, 2025
e94505c
Merge branch 'main' into fix-112781
tannergooding Aug 7, 2025
9579b65
Merge branch 'main' into fix-112781
tannergooding Aug 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,24 @@
<Right>lib/net9.0/System.Numerics.Tensors.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0017</DiagnosticId>
<Target>M:System.Numerics.Tensors.Tensor.OnesComplement``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,System.Numerics.Tensors.TensorSpan{``0}@)$0</Target>
<Left>ref/net10.0/System.Numerics.Tensors.dll</Left>
<Right>lib/net10.0/System.Numerics.Tensors.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0017</DiagnosticId>
<Target>M:System.Numerics.Tensors.Tensor.OnesComplement``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,System.Numerics.Tensors.TensorSpan{``0}@)$0</Target>
<Left>ref/net8.0/System.Numerics.Tensors.dll</Left>
<Right>lib/net8.0/System.Numerics.Tensors.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0017</DiagnosticId>
<Target>M:System.Numerics.Tensors.Tensor.OnesComplement``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@,System.Numerics.Tensors.TensorSpan{``0}@)$0</Target>
<Left>ref/net9.0/System.Numerics.Tensors.dll</Left>
<Right>lib/net9.0/System.Numerics.Tensors.dll</Right>
</Suppression>
<Suppression>
<DiagnosticId>CP0021</DiagnosticId>
<Target>M:System.Numerics.Tensors.Tensor.Average``1(System.Numerics.Tensors.ReadOnlyTensorSpan{``0}@)``0:T:System.Numerics.INumberBase{``0}</Target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@
<Compile Include="System\Numerics\Tensors\netcore\ReadOnlyTensorDimensionSpan_1.cs" />
<Compile Include="System\Numerics\Tensors\netcore\ReadOnlyTensorSpan_1.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_Addition.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_BitwiseAnd.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_BitwiseOr.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_Decrement.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_Division.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_ExclusiveOr.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_Increment.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_LeftShift.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_Multiply.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_OnesComplement.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_RightShift.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_Subtraction.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_UnaryNegation.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_UnaryPlus.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor.op_UnsignedRightShift.cs" />
<Compile Include="System\Numerics\Tensors\netcore\Tensor_1.cs" />
<Compile Include="System\Numerics\Tensors\netcore\TensorDimensionSpan_1.cs" />
<Compile Include="System\Numerics\Tensors\netcore\TensorOperation.cs" />
Expand Down Expand Up @@ -149,6 +164,8 @@
<Compile Include="System\Numerics\Tensors\netcore\TensorPrimitives.Round.cs" />
<Compile Include="System\Numerics\Tensors\netcore\TensorPrimitives.ScaleB.cs" />
<Compile Include="System\Numerics\Tensors\netcore\TensorPrimitives.ShiftLeft.cs" />
<Compile Include="System\Numerics\Tensors\netcore\TensorPrimitives.ShiftRightArithmetic.cs" />
<Compile Include="System\Numerics\Tensors\netcore\TensorPrimitives.ShiftRightLogical.cs" />
<Compile Include="System\Numerics\Tensors\netcore\TensorPrimitives.Sigmoid.cs" />
<Compile Include="System\Numerics\Tensors\netcore\TensorPrimitives.Sign.cs" />
<Compile Include="System\Numerics\Tensors\netcore\TensorPrimitives.Sin.cs" />
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace System.Numerics.Tensors
{
public static partial class Tensor
{
/// <summary>Performs element-wise addition between two tensors.</summary>
/// <typeparam name="T">The type of the elements in the tensor.</typeparam>
/// <param name="x">The tensor to add with <paramref name="y" />.</param>
/// <param name="y">The tensor to add with <paramref name="x" />.</param>
/// <returns>A new tensor containing the result of <paramref name="x" /> + <paramref name="y" />.</returns>
/// <exception cref="ArgumentException">The shapes of <paramref name="x" /> and <paramref name="y" /> are not compatible.</exception>
public static Tensor<T> Add<T>(in ReadOnlyTensorSpan<T> x, in ReadOnlyTensorSpan<T> y)
where T : IAdditionOperators<T, T, T>, IAdditiveIdentity<T, T>
{
TensorOperation.ValidateCompatibility(x, y, out Tensor<T> destination);
TensorOperation.Invoke<TensorOperation.Add<T>, T, T>(x, y, destination);
return destination;
}

/// <summary>Performs element-wise addition between a tensor and scalar.</summary>
/// <typeparam name="T">The type of the elements in the tensor.</typeparam>
/// <param name="x">The tensor to add with <paramref name="y" />.</param>
/// <param name="y">The scalar to add with <paramref name="x" />.</param>
/// <returns>A new tensor containing the result of <paramref name="x" /> + <paramref name="y" />.</returns>
public static Tensor<T> Add<T>(in ReadOnlyTensorSpan<T> x, T y)
where T : IAdditionOperators<T, T, T>, IAdditiveIdentity<T, T>
{
Tensor<T> destination = CreateFromShapeUninitialized<T>(x.Lengths);
TensorOperation.Invoke<TensorOperation.Add<T>, T, T>(x, y, destination);
return destination;
}

/// <summary>Performs element-wise addition between two tensors.</summary>
/// <typeparam name="T">The type of the elements in the tensor.</typeparam>
/// <param name="x">The tensor to add with <paramref name="y" />.</param>
/// <param name="y">The tensor to add with <paramref name="x" />.</param>
/// <param name="destination">The destination where the result of <paramref name="x" /> + <paramref name="y" /> is written.</param>
/// <returns>A reference to <paramref name="destination" />.</returns>
/// <exception cref="ArgumentException">The shapes of <paramref name="x" />, <paramref name="y" />, and <paramref name="destination" /> are not compatible.</exception>
public static ref readonly TensorSpan<T> Add<T>(scoped in ReadOnlyTensorSpan<T> x, scoped in ReadOnlyTensorSpan<T> y, in TensorSpan<T> destination)
where T : IAdditionOperators<T, T, T>, IAdditiveIdentity<T, T>
{
TensorOperation.ValidateCompatibility(x, y, destination);
TensorOperation.Invoke<TensorOperation.Add<T>, T, T>(x, y, destination);
return ref destination;
}

/// <summary>Performs element-wise addition between a tensor and scalar.</summary>
/// <typeparam name="T">The type of the elements in the tensor.</typeparam>
/// <param name="x">The tensor to add with <paramref name="y" />.</param>
/// <param name="y">The scalar to add with <paramref name="x" />.</param>
/// <param name="destination">The destination where the result of <paramref name="x" /> + <paramref name="y" /> is written.</param>
/// <returns>A reference to <paramref name="destination" />.</returns>
/// <exception cref="ArgumentException">The shapes of <paramref name="x" /> and <paramref name="destination" /> are not compatible.</exception>
public static ref readonly TensorSpan<T> Add<T>(scoped in ReadOnlyTensorSpan<T> x, T y, in TensorSpan<T> destination)
where T : IAdditionOperators<T, T, T>, IAdditiveIdentity<T, T>
{
TensorOperation.ValidateCompatibility(x, destination);
TensorOperation.Invoke<TensorOperation.Add<T>, T, T>(x, y, destination);
return ref destination;
}

/// <typeparam name="TScalar">The type of the elements in the tensor.</typeparam>
extension<TScalar>(ReadOnlyTensorSpan<TScalar>)
where TScalar : IAdditionOperators<TScalar, TScalar, TScalar>, IAdditiveIdentity<TScalar, TScalar>
{
/// <summary>Performs element-wise addition between two tensors.</summary>
/// <param name="left">The tensor to add with <paramref name="right" />.</param>
/// <param name="right">The tensor to add with <paramref name="left" />.</param>
/// <returns>A new tensor containing the result of <paramref name="left" /> + <paramref name="right" />.</returns>
/// <exception cref="ArgumentException">The shapes of <paramref name="left" /> and <paramref name="right" /> are not compatible.</exception>
public static Tensor<TScalar> operator +(in ReadOnlyTensorSpan<TScalar> left, in ReadOnlyTensorSpan<TScalar> right) => Add(left, right);

/// <summary>Performs element-wise addition between a tensor and scalar.</summary>
/// <param name="left">The tensor to add with <paramref name="right" />.</param>
/// <param name="right">The scalar to add with <paramref name="left" />.</param>
/// <returns>A new tensor containing the result of <paramref name="left" /> + <paramref name="right" />.</returns>
public static Tensor<TScalar> operator +(in ReadOnlyTensorSpan<TScalar> left, TScalar right) => Add(left, right);

/// <summary>Performs element-wise addition between a tensor and scalar.</summary>
/// <param name="left">The scalar to add with <paramref name="right" />.</param>
/// <param name="right">The tensor to add with <paramref name="left" />.</param>
/// <returns>A new tensor containing the result of <paramref name="left" /> + <paramref name="right" />.</returns>
public static Tensor<TScalar> operator +(TScalar left, in ReadOnlyTensorSpan<TScalar> right) => Add(right, left);
}

/// <typeparam name="TScalar">The type of the elements in the tensor.</typeparam>
extension<TScalar>(Tensor<TScalar> tensor)
where TScalar : IAdditionOperators<TScalar, TScalar, TScalar>, IAdditiveIdentity<TScalar, TScalar>
{
/// <inheritdoc cref="op_Addition{T}(in ReadOnlyTensorSpan{T}, in ReadOnlyTensorSpan{T})" />
public static Tensor<TScalar> operator +(Tensor<TScalar> left, Tensor<TScalar> right) => Add<TScalar>(left, right);

/// <inheritdoc cref="op_Addition{T}(in ReadOnlyTensorSpan{T}, T)" />
public static Tensor<TScalar> operator +(Tensor<TScalar> left, TScalar right) => Add(left, right);

/// <inheritdoc cref="op_Addition{T}(T, in ReadOnlyTensorSpan{T})" />
public static Tensor<TScalar> operator +(TScalar left, Tensor<TScalar> right) => Add(right, left);

/// <inheritdoc cref="op_AdditionAssignment{T}(ref TensorSpan{T}, in ReadOnlyTensorSpan{T})" />
public void operator +=(in ReadOnlyTensorSpan<TScalar> other) => Add(tensor, other, tensor);

/// <inheritdoc cref="op_AdditionAssignment{T}(ref TensorSpan{T}, T)" />
public void operator +=(TScalar other) => Add(tensor, other, tensor);
}

/// <typeparam name="TScalar">The type of the elements in the tensor.</typeparam>
/// <param name="tensor">The tensor to operate on.</param>
extension<TScalar>(ref TensorSpan<TScalar> tensor)
where TScalar : IAdditionOperators<TScalar, TScalar, TScalar>, IAdditiveIdentity<TScalar, TScalar>
{
/// <inheritdoc cref="op_Addition{T}(in ReadOnlyTensorSpan{T}, in ReadOnlyTensorSpan{T})" />
public static Tensor<TScalar> operator +(in TensorSpan<TScalar> left, in TensorSpan<TScalar> right) => Add<TScalar>(left, right);

/// <inheritdoc cref="op_Addition{T}(in ReadOnlyTensorSpan{T}, T)" />
public static Tensor<TScalar> operator +(in TensorSpan<TScalar> left, TScalar right) => Add(left, right);

/// <inheritdoc cref="op_Addition{T}(T, in ReadOnlyTensorSpan{T})" />
public static Tensor<TScalar> operator +(TScalar left, in TensorSpan<TScalar> right) => Add(right, left);

/// <summary>Performs in-place element-wise addition between two tensors.</summary>
/// <param name="other">The tensor to add to the tensor being operated on.</param>
public void operator +=(in ReadOnlyTensorSpan<TScalar> other) => Add(tensor, other, tensor);

/// <summary>Performs in-place element-wise addition between a tensor and scalar.</summary>
/// <param name="other">The scalar to add to the tensor being operated on.</param>
public void operator +=(TScalar other) => Add(tensor, other, tensor);
}
}
}
Loading
Loading