Skip to content

Eigen Tensor conversion logic -- potential problem #3

@Algomorph

Description

@Algomorph

I realized recently that the way I implemented the conversion might not be quite logically correct.

I was guided by the principle: "in conversion from numpy array to Eigen Tensor, the indexing with the same subscripts should remain the same".

This rule would basically mean that tensor_as_numpy_array[1,2,3] and tensor_as_Eigen_Tensor(1,2,3) should be the same.

This rule tends to hold alright for the Eigen matrices, which are column-major but are indexed in a row-major fashion, i.e. eigen_tensor(2,3) means "row 2, column 3". I guess Eigen developers noticed they cannot contain the inconsistency between actual layout and indexing scheme beyond 2 dimensions, so the Tensors are actually indexed and stored consistently, as evidenced by the following statement:

By default, Tensors are stored in "column-major" order, &t(x+1, ...) == &t(x, ...) + 1, &t(x, y+1, ...) == &t(x, y, ...) + t.dimension(0), etc.

So, it might make more sense to convert fully without reversing axis order (the way I did it originally).
In this case, entries tensor_as_numpy_array[1,2,3] and tensor_as_Eigen_Tensor(3,2,1) should be the same.So, the last axis is (and should be) most significant in Eigen and the first axis is (and should be) the most significant axis in numpy. Preserving correspondence of the data ordering may is not only important to avoid unnecessary operations (axis swapping) during the conversion, but also important to be better able to optimize code that depends on traversing axes in least-to-most-significant way.

Please let me know what you think and I can alter the design accordingly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions