Share via


TensorPrimitives.Distance Method

Definition

Overloads

Distance(ReadOnlySpan<Single>, ReadOnlySpan<Single>)

Computes the distance between two points, specified as non-empty, equal-length tensors of single-precision floating-point numbers, in Euclidean space.

Distance<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

Computes the distance between two points, specified as non-empty, equal-length tensors of numbers, in Euclidean space.

Distance(ReadOnlySpan<Single>, ReadOnlySpan<Single>)

Source:
TensorPrimitives.cs
Source:
TensorPrimitives.Single.cs
Source:
TensorPrimitives.Single.cs

Computes the distance between two points, specified as non-empty, equal-length tensors of single-precision floating-point numbers, in Euclidean space.

public:
 static float Distance(ReadOnlySpan<float> x, ReadOnlySpan<float> y);
public static float Distance (ReadOnlySpan<float> x, ReadOnlySpan<float> y);
static member Distance : ReadOnlySpan<single> * ReadOnlySpan<single> -> single
Public Shared Function Distance (x As ReadOnlySpan(Of Single), y As ReadOnlySpan(Of Single)) As Single

Parameters

x
ReadOnlySpan<Single>

The first tensor, represented as a span.

y
ReadOnlySpan<Single>

The second tensor, represented as a span.

Returns

The Euclidean distance.

Exceptions

x and y must not be empty.

Remarks

This method effectively computes the equivalent of: Span<float> difference = ...; TensorPrimitives.Subtract(x, y, difference); float result = MathF.Sqrt(TensorPrimitives.SumOfSquares(difference)); but without requiring additional temporary storage for the intermediate differences.

If any element in either input tensor is equal to NaN, NaN is returned.

This method may call into the underlying C runtime or employ instructions specific to the current architecture. Exact results may differ between different operating systems or architectures.

Applies to

Distance<T>(ReadOnlySpan<T>, ReadOnlySpan<T>)

Source:
TensorPrimitives.Distance.cs
Source:
TensorPrimitives.Distance.cs

Computes the distance between two points, specified as non-empty, equal-length tensors of numbers, in Euclidean space.

public:
generic <typename T>
 where T : System::Numerics::IRootFunctions<T> static T Distance(ReadOnlySpan<T> x, ReadOnlySpan<T> y);
public static T Distance<T> (ReadOnlySpan<T> x, ReadOnlySpan<T> y) where T : System.Numerics.IRootFunctions<T>;
static member Distance : ReadOnlySpan<'T (requires 'T :> System.Numerics.IRootFunctions<'T>)> * ReadOnlySpan<'T (requires 'T :> System.Numerics.IRootFunctions<'T>)> -> 'T (requires 'T :> System.Numerics.IRootFunctions<'T>)
Public Shared Function Distance(Of T As IRootFunctions(Of T)) (x As ReadOnlySpan(Of T), y As ReadOnlySpan(Of T)) As T

Type Parameters

T

Parameters

x
ReadOnlySpan<T>

The first tensor, represented as a span.

y
ReadOnlySpan<T>

The second tensor, represented as a span.

Returns

T

The Euclidean distance.

Exceptions

x and y must not be empty.

Remarks

This method effectively computes the equivalent of: Span<T> difference = ...; TensorPrimitives.Subtract(x, y, difference); T result = T.Sqrt(TensorPrimitives.SumOfSquares(difference)); but without requiring additional temporary storage for the intermediate differences.

If any element in either input tensor is equal to NaN, NaN is returned.

This method may call into the underlying C runtime or employ instructions specific to the current architecture. Exact results may differ between different operating systems or architectures.

Applies to