Skip to content

thpp Tensor templatized over Device (and maybe Density, e.g sparse vs dense) #947

@an-kumar

Description

@an-kumar

Right now, THPP exposes four templatized classes:

THTensor<T>, THCTensor<T>, THCSTensor<T>, and THSTensor<T>.

I propose to consolidate these into a single class, like so:

TorchTensor<Type,Device,Density> (or at least, <Type,Device>).

We can then do the following:

template <typename T>
using THTensor = TorchTensor<T,CPU,Dense>

template <typename T>
using THCTensor = TorchTensor<T,GPU,Dense>

and so on.

In this fashion, nothing about the current API would change (and so all current code that uses THPP would all work the same), but users of THPP would be able to choose what level of templatization they want. If there are some current methods that are only in some subset of the classes, we can either do template class specialization, or simply make those methods part of all the classes.

I am interested in this because I am using THPP in a separate project, in which it would be cleaner to have the Tensor class to be templatized over at least the Device (in addition to the Type), as it is in most other frameworks (e.g MXNet).

I am happy to do this and submit a PR if the developers are interested, otherwise I will just make those changes locally.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions