Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[API Proposal]: Non-Generic base type #111968

Open
michaelgsharp opened this issue Jan 29, 2025 · 3 comments
Open

[API Proposal]: Non-Generic base type #111968

michaelgsharp opened this issue Jan 29, 2025 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Numerics.Tensors untriaged New issue has not been triaged by the area owner

Comments

@michaelgsharp
Copy link
Member

Background and motivation

We currently do not have a non-generic base type for Tensor. This is fine, but there are many times you need info about the Tensor (its rank, lengths of dimenions, etc) and you can get this info without needing to know or care about the generic type itself. We need to add a base type that will better facilitate this.

We can evaluate whether we need to add more methods, maybe involving boxing, as time goes on.

API Proposal

namespace System.Numerics.Tensors;

// All of these existed in higher types. Just creating a new base type and moving these down.
public interface ITensor
{
    /// <summary>
    /// Gets a value that indicates whether the collection is currently empty.
    /// </summary>
    bool IsEmpty { get; }

    /// <summary>
    /// Gets a value that indicates whether the underlying buffer is pinned.
    /// </summary>
    bool IsPinned { get; }

    /// <summary>
    /// Gets the number of elements in the tensor.
    /// </summary>
    nint FlattenedLength { get; }

    /// <summary>
    /// Gets the number of dimensions in the tensor.
    /// </summary>
    int Rank { get; }

    /// <summary>
    /// Gets the length of each dimension in the tensor.
    /// </summary>
    [UnscopedRef]
    ReadOnlySpan<nint> Lengths { get; }

    /// <summary>
    /// Gets the stride of each dimension in the tensor.
    /// </summary>
    [UnscopedRef]
    ReadOnlySpan<nint> Strides { get; }
}

API Usage

public void DoStuffWithNonGenericTensor(ITensor tensor);

Tensor<int> tensor = Tensor.Create<int>([1, 2, 3, 4], [2, 2]);

DoStuffWithNonGenericTensor(tensor);

Alternative Designs

Potentially have more methods for getting data involving boxing.

Risks

Low risk because it's a preview type, but because we are changing the class heirarchy there is more than none.

@michaelgsharp michaelgsharp added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Jan 29, 2025
@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Jan 29, 2025
@michaelgsharp
Copy link
Member Author

@tannergooding

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Jan 29, 2025
@michaelgsharp michaelgsharp added area-System.Numerics.Tensors and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Jan 29, 2025
Copy link
Contributor

Tagging subscribers to this area: @dotnet/area-system-numerics-tensors
See info in area-owners.md if you want to be subscribed.

@tannergooding
Copy link
Member

We can evaluate whether we need to add more methods, maybe involving boxing, as time goes on.

This notably needs to be decided up front, prior to shipping, as we cannot expose such APIs after we ship it as stable.

Such considerations should likely be part of this API proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Numerics.Tensors untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

2 participants