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

Aliasing error during eigen decomposition #49

Open
crud89 opened this issue Feb 1, 2019 · 3 comments
Open

Aliasing error during eigen decomposition #49

crud89 opened this issue Feb 1, 2019 · 3 comments

Comments

@crud89
Copy link

crud89 commented Feb 1, 2019

Hey there,

I found your library really useful so far and I am really surprised by its efficiency. However, I am experiencing some aliasing issues. The following code fails during embedding. Note that I have defined TAPKEE_CUSTOM_INTERNAL_NUMTYPE as float. 1

// Create a matrix with 512x512 32-dim features.
tapkee::DenseMatrix descriptors(32, 262144);

// Randomly fill the matrix.
for (int i(0); i < 32; ++i)
for (int j(0); j < 262144; ++j)
	descriptors(i, j) = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);

// Reduce to dim 8 using PCA.
tapkee::ParametersSet parameters = tapkee::kwargs[
	tapkee::method = tapkee::PCA,
	tapkee::target_dimension = 8
];

// Perform PCA
tapkee::TapkeeOutput result = tapkee::initialize()
	.withParameters(parameters)
	.embedUsing(descriptors);

Basically I want to reduce a set of 512x512 32 dimensional features to 8D, which I randomly initialize for demonstration purposes. When ran in debug-mode (under Win64), Eigen detects aliasing:

aliasing detected during transposition, use transposeInPlace() or evaluate the rhs into a temporary using .eval()

The error is raised during eigen decomposition (eigendecomposition.hpp):

//! Eigen library dense implementation of eigendecomposition-based embedding
template <class MatrixType, class MatrixOperationType>
EigendecompositionResult eigendecomposition_impl_dense(const MatrixType& wm, IndexType target_dimension, unsigned int skip)
{
	timed_context context("Eigen library dense eigendecomposition");

	DenseSymmetricMatrix dense_wm = wm;
	dense_wm += dense_wm.transpose();	// Invalid.
	dense_wm /= 2.0;
	DenseSelfAdjointEigenSolver solver(dense_wm);
	
	// ...
}

It relates to the issues described here. Changing this line to dense_wm += dense_wm.transpose().eval(); resolves the issue. I think transposeInPlace() should also work, however I was not able to get it to compile that way.

Did I miss something or is this an actual bug?!

1 Also note that the documentation says TAPKEE_CUSTOM_NUMTYPE, which is actually incorrect.

@lisitsyn
Copy link
Owner

lisitsyn commented Feb 1, 2019

Hey, thanks for the report.

It seems to be an actual bug. The eval thing resolves that indeed but it would bump the memory usage 2x for a moment. Let me check if there is a memory-efficient solution.

lisitsyn added a commit that referenced this issue Feb 1, 2019
@lisitsyn
Copy link
Owner

lisitsyn commented Feb 1, 2019

It seems that eval should be here.

I just added it in ec35140

@crud89
Copy link
Author

crud89 commented Feb 1, 2019

Thank you for the fast fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants