|[eigen] Feature request: Add compile-time access to Eigen::Map dimensionality|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: "eigen@xxxxxxxxxxxxxxxxxxx" <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] Feature request: Add compile-time access to Eigen::Map dimensionality
- From: Kasper Marstal <kaspermarstal@xxxxxxxxx>
- Date: Tue, 20 Mar 2018 15:04:52 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=LdDSiSCA/G5vg/r/CTslPh4FeOF095Tr/MLR8hvHE30=; b=Yy+1CmbBXJ+GFXES4L1/f4mvAJ8QBwzbEdOMr0N2kuuqSBs+wuinYnt/QY1fC5NSgn DYrN/2lrA8G1o2rF1jLnrE6nBfyJ6VdPcDS0QM3OmFre86wjF2BwzL9gGJlxvMVC1Tc7 MgucK16tl5dkrQZABGU1jgzMFMvlKhQD7uG0CACGEA/fjcjhmw9mnQW7+MzJs4F4WjcK //KjjAC/626/LP0icb/uDeATlYa44SkvUoVhPIaWjEZAsMoP1XyRUuERO3WMnsSR9CLf zrSGT1sGsz5Zz7lhR4AbDotHbJJ6AzBeoihZHeVPzzQWYXeLdFtQUGIkZMeKCQv8NB/5 CeYw==
I would like to propose compile-time access to Eigen::Map dimensionality to align the Map API with the TensorMap API. Possible implementation:
const static int NumDimensions = IsVectorAtCompileTime ? 1 : 2;
(If there are more Eigen-idiomatic methods to achieve this functionality suggestions are most welcome)
My use case is this: I have a class Inputs<Ts....> that is templated over a list of tensor maps. The class is constructed with a corresponding number of Tensors, and these Tensors sliced via Eigen::TensorMap and processed in parallel by a thread pool. NumDimensions is used to determine what are spatial dimensions and what are batch dimensions. The leading dimensions (dimension zero to NumIndices) are treated as batch dimensions, while the rest are treated as spatial dimensions.
With this proposal, Eigen::Map and Eigen::TensorMap share the same API for type and dimension (Scalar and NumDimensions), so that Eigen::Map can used together with TensorMaps without meta programming.
In addition, compile time access to image dimensionality is important for medical image processing libraries (my background).
I am happy to contribute a patch with whatever the maintainers deem the best name (NumDimensions or NumIndices or something else), the most appropriate implementation, and the best place to put it (e.g. in matrix class or only in map class).