Skip to content

Commit

Permalink
dotnet#867 add comments to public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xhuan8 committed Dec 12, 2022
1 parent 6e0e8a9 commit a9299c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/TorchSharp/Utils/DeconstructExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,46 @@ namespace TorchSharp.Utils
{
/// <summary>
/// Converts IEnumerable to tuple.
/// Example:
/// int[] rect = new int[4];
/// var (left, top, width, height, _) = rect;
/// </summary>
public static class DeconstructExtension
{
/// <summary>
/// Deconstructs a sequence to the first element and rest of elements.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="seq"></param>
/// <param name="first"></param>
/// <param name="rest"></param>
public static void Deconstruct<T>(this IEnumerable<T> seq, out T first, out IEnumerable<T> rest)
{
first = seq.FirstOrDefault();
rest = seq.Skip(1);
}

/// <summary>
/// Deconstrcts one element out of sequence.
/// </summary>
public static void Deconstruct<T>(this IEnumerable<T> seq, out T first, out T second, out IEnumerable<T> rest)
=> (first, (second, rest)) = seq;

/// <summary>
/// Deconstrcts two elements out of sequence.
/// </summary>
public static void Deconstruct<T>(this IEnumerable<T> seq, out T first, out T second, out T third, out IEnumerable<T> rest)
=> (first, second, (third, rest)) = seq;

/// <summary>
/// Deconstrcts three elements out of sequence.
/// </summary>
public static void Deconstruct<T>(this IEnumerable<T> seq, out T first, out T second, out T third, out T fourth, out IEnumerable<T> rest)
=> (first, second, third, (fourth, rest)) = seq;

/// <summary>
/// Deconstrcts four elements out of sequence.
/// </summary>
public static void Deconstruct<T>(this IEnumerable<T> seq, out T first, out T second, out T third, out T fourth, out T fifth, out IEnumerable<T> rest)
=> (first, second, third, fourth, (fifth, rest)) = seq;
}
Expand Down
3 changes: 3 additions & 0 deletions src/TorchVision/Ops/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public static partial class torchvision
{
public static partial class ops
{
/// <summary>
/// Protects from numerical overflows in multiplications by upcasting to the equivalent higher type.
/// </summary>
public static Tensor _upcast(Tensor t)
{
if (t.is_floating_point())
Expand Down

0 comments on commit a9299c1

Please sign in to comment.