Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmada committed Mar 22, 2024
1 parent bca71f6 commit e7756b6
Show file tree
Hide file tree
Showing 8 changed files with 353 additions and 375 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,25 +36,32 @@ For variables `x`, `y`, and `result`, all of type `Span<float>` and of the same
Tensor.Add(x, y, result);
```

In addition to per-element operations, the library also supports various aggregation operations, including:
In addition to per-element operations, the library also provides support for various aggregation operations, including:

```csharp
var sum = TensorOperations.Sum(values);
var average = TensorOperations.Average(values);
var product = TensorOperations.Product(values);
var min = TensorOperations.Min(values);
var max = TensorOperations.Max(values);
var (min, max) = TensorOperations.MinMax(values);
var (minIndex, maxIndex) = TensorOperations.MinMax(values);
```

The library offers functionality to retrieve the index of the first element meeting a specific condition:
Furthermore, the library offers functionality to retrieve the index of specific elements:

```csharp
var indexOfEqual = IndexOfEquals(values, 0);
var indexOfGreaterThan = IndexOfGreaterThan(values, 0);
var indexOfGreaterThanOrEqual = IndexOfGreaterThanOrEqual(values, 0);
var indexOfLessThan = IndexOfLessThan(values, 0);
var indexOfLessThanOrEqual = IndexOfLessThanOrEqual(values, 0);
var indexOfMin = TensorOperations.IndexOfMin(values);
var indexOfMax = TensorOperations.IndexOfMax(values);
```

It also facilitates finding the index of the first element meeting a particular condition:

```csharp
var indexOfEqualToZero = IndexOfEquals(values, 0);
var indexOfGreaterThanZero = IndexOfGreaterThan(values, 0);
var indexOfGreaterThanOrEqualToZero = IndexOfGreaterThanOrEqual(values, 0);
var indexOfLessThanZero = IndexOfLessThan(values, 0);
var indexOfLessThanOrEqualToZero = IndexOfLessThanOrEqual(values, 0);
```

### Custom Operations
Expand Down
150 changes: 39 additions & 111 deletions docs/articles/Extending-the-library.md

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions docs/articles/Getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,32 @@ TensorOperations.Add(x, y, result);

> **NOTE**: The operations do not allocate any memory, ensuring optimal performance. The library is designed to be memory-efficient and performant. All the spans have to be allocated and managed by the user.
In addition to per-element operations, the library also supports various aggregation operations, including:
In addition to per-element operations, the library also provides support for various aggregation operations, including:

```csharp
var sum = TensorOperations.Sum(values);
var average = TensorOperations.Average(values);
var product = TensorOperations.Product(values);
var min = TensorOperations.Min(values);
var max = TensorOperations.Max(values);
var (min, max) = TensorOperations.MinMax(values);
var (minIndex, maxIndex) = TensorOperations.MinMax(values);
```

The library offers functionality to retrieve the index of the first element meeting a specific condition:
Furthermore, the library offers functionality to retrieve the index of specific elements:

```csharp
var indexOfEqual = IndexOfEquals(values, 0);
var indexOfGreaterThan = IndexOfGreaterThan(values, 0);
var indexOfGreaterThanOrEqual = IndexOfGreaterThanOrEqual(values, 0);
var indexOfLessThan = IndexOfLessThan(values, 0);
var indexOfLessThanOrEqual = IndexOfLessThanOrEqual(values, 0);
var indexOfMin = TensorOperations.IndexOfMin(values);
var indexOfMax = TensorOperations.IndexOfMax(values);
```

It also facilitates finding the index of the first element meeting a particular condition:

```csharp
var indexOfEqualToZero = IndexOfEquals(values, 0);
var indexOfGreaterThanZero = IndexOfGreaterThan(values, 0);
var indexOfGreaterThanOrEqualToZero = IndexOfGreaterThanOrEqual(values, 0);
var indexOfLessThanZero = IndexOfLessThan(values, 0);
var indexOfLessThanOrEqualToZero = IndexOfLessThanOrEqual(values, 0);
```

Dive deeper into the library's capabilities by exploring the API documentation, especially the section under the `TensorOperations` type, for an exhaustive list of available functionalities.
Expand Down
2 changes: 1 addition & 1 deletion src/NetFabric.Numerics.Tensors/AggregateNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public static T AggregateNumber<T, TAggregateOperator>(ReadOnlySpan<T> source)
/// <remarks>This methods does not propagate NaN.</remarks>
public static T AggregateNumber<T, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T> source)
where T : struct
where TAggregateOperator : struct, IAggregationOperator<T, T>
where TTransformOperator : struct, IUnaryOperator<T, T>
where TAggregateOperator : struct, IAggregationOperator<T, T>
=> AggregateNumber<T, T, T, TTransformOperator, TAggregateOperator>(source);

/// <summary>
Expand Down
17 changes: 16 additions & 1 deletion src/NetFabric.Numerics.Tensors/IndexOfAggregate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,22 @@ public static partial class Tensor
public static int IndexOfAggregate<T, TAggregateOperator>(ReadOnlySpan<T> source)
where T : struct, INumberBase<T>
where TAggregateOperator : struct, IAggregationOperator<T, T>
=> IndexOfAggregate<T, T, T, IdentityOperator<T>, TAggregateOperator>(source);
=> IndexOfAggregate<T, IdentityOperator<T>, TAggregateOperator>(source);

/// <summary>
/// Aggregates the elements of a <see cref="ReadOnlySpan{T}"/> using the specified aggregation operator.
/// </summary>
/// <typeparam name="T">The type of the elements in the source span.</typeparam>
/// <typeparam name="TTransformOperator">The type of the transform operator that must implement the <see cref="IUnaryOperator{TSource, TTransformed}"/> interface.</typeparam>
/// <typeparam name="TAggregateOperator">The type of the aggregation operator that must implement the <see cref="IAggregationOperator{T, T}"/> interface.</typeparam>
/// <param name="source">The span of elements to aggregate.</param>
/// <returns>The result of the aggregation.</returns>
/// <remarks>This methods follows the IEEE 754 standard for floating-point arithmetic, it returns the index of the first element to which the transformation and aggregation results in NaN.</remarks>
public static int IndexOfAggregate<T, TTransformOperator, TAggregateOperator>(ReadOnlySpan<T> source)
where T : struct, INumberBase<T>
where TTransformOperator : struct, IUnaryOperator<T, T>
where TAggregateOperator : struct, IAggregationOperator<T, T>
=> IndexOfAggregate<T, T, T, TTransformOperator, TAggregateOperator>(source);

/// <summary>
/// Aggregates the elements of a <see cref="ReadOnlySpan{T1}"/> using the specified transform and aggregation operators.
Expand Down
Loading

0 comments on commit e7756b6

Please sign in to comment.