lisitsyn / tapkee

A flexible and efficient С++ template library for dimension reduction
http://tapkee.lisitsyn.me
BSD 3-Clause "New" or "Revised" License
231 stars 58 forks source link

Look into attached unit test logs #84

Closed iglesias closed 5 months ago

iglesias commented 5 months ago

While #83, this popped up (summary, complete logs attached)

5: Indirect leak of 40 byte(s) in 1 object(s) allocated from:                                                                                     
5:     #0 0x7a2c008e1359 in __interceptor_malloc /usr/src/debug/gcc/gcc/libsanitizer/asan/asan_malloc_linux.cpp:69                                
5:     #1 0x5c5933bf1fdc in Eigen::internal::handmade_aligned_malloc(unsigned long, unsigned long) /usr/include/eigen3/Eigen/src/Core/util/Memory.
h:105                                                                                                                                             
5:     #2 0x5c5933bf244b in Eigen::internal::aligned_malloc(unsigned long) /usr/include/eigen3/Eigen/src/Core/util/Memory.h:188                   
5:     #3 0x5c5933d85d8e in void* Eigen::internal::conditional_aligned_malloc<true>(unsigned long) /usr/include/eigen3/Eigen/src/Core/util/Memory.
h:241                                                                                                                                             
5:     #4 0x5c5933d1e568 in double* Eigen::internal::conditional_aligned_new_auto<double, true>(unsigned long) /usr/include/eigen3/Eigen/src/Core/
util/Memory.h:404                                                                                                                                 5:     #5 0x5c5933cb5949 in Eigen::DenseStorage<double, -1, -1, 1, 0>::DenseStorage(Eigen::DenseStorage<double, -1, -1, 1, 0> const&) /usr/include
/eigen3/Eigen/src/Core/DenseStorage.h:589                                                                                                         5:     #6 0x5c5933c7ce30 in Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >::PlainObjectBase(Eigen::PlainObjectBase<Eigen::Matrix<
double, -1, 1, 0, -1, 1> > const&) /usr/include/eigen3/Eigen/src/Core/PlainObjectBase.h:512                                                       5:     #7 0x5c5933c46159 in Eigen::Matrix<double, -1, 1, 0, -1, 1>::Matrix(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&) /usr/include/eigen3/Eige
n/src/Core/Matrix.h:414                                                                                                                           5:     #8 0x5c5933c002da in tapkee::MatrixProjectionImplementation::MatrixProjectionImplementation(Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen
::Matrix<double, -1, 1, 0, -1, 1>) tapkee/include/tapkee/projection.hpp:46                                                    5:     #9 0x5c5933d0cf69 in tapkee::tapkee_internal::ImplementationBase<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, tapkee::eigen_kernel_callback, tapkee::eigen_distance_callback, tapkee::eigen_features_callback>::embedPCA() tapkee/include
/tapkee/methods.hpp:341                                                                                                                           5:     #10 0x5c5933caa55c in tapkee::tapkee_internal::ImplementationBase<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, tapkee::eigen_kernel_callback, tapkee::eigen_distance_callback, tapkee::eigen_features_callback>::embedUsing(tapkee::DimensionReductionMethod)
 tapkee/include/tapkee/methods.hpp:113                                                                                        5:     #11 0x5c5933c735ea in tapkee::TapkeeOutput tapkee::embed<__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, tapkee::eigen_kernel_callback, tapkee::eigen_distance_callback, tapkee::eigen_features_callback>(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, tapkee::eigen_kernel_callback, tapkee::eigen_d
istance_callback, tapkee::eigen_features_callback, stichwort::ParametersSet) tapkee/include/tapkee/embed.hpp:117              5:     #12 0x5c5933c3f289 in tapkee::tapkee_internal::ParametersInitializedState::embedUsing(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&) cons
t tapkee/tapkee/include/tapkee/chain_interface.hpp:479                                                                               
5:     #13 0x5c5933bdf964 in Projecting_PCA_Test::TestBody() tapkee/tapkee/test/unit/projecting.cpp:17                               
5:     #14 0x7a2c0100465b  (/usr/lib/libgtest.so.1.14.0+0x5365b)                          
5:                                                                                                                                                
5: SUMMARY: AddressSanitizer: 304 byte(s) leaked in 6 allocation(s).                                                                              
5/5 Test #5: projecting .......................***Failed    0.17 sec 

ctest.log

Hotfix below didn't improve if I didn't overlook results:

--- a/test/unit/projecting.cpp
+++ b/test/unit/projecting.cpp
@@@ -13,7 -13,7 +13,8 @@@ TEST(Projecting, PCA

      TapkeeOutput output;

--    ASSERT_NO_THROW(output = tapkee::initialize().withParameters((method = PCA, target_dimension = 2)).embedUsing(X));
++    const auto tapkee_obj = tapkee::initialize().withParameters((method = PCA, target_dimension = 2));
++    ASSERT_NO_THROW(output = tapkee_obj.embedUsing(X));

      auto projected = output.projection(X.col(0));
      ASSERT_EQ(2, projected.size())

I didn't get around it yet as I would have liked, so I added it here. From tomorrow I have more time again and I am aiming at getting it going this week. 🤓

lisitsyn commented 5 months ago

It looks like ProjectingFunction misses a destructor

iglesias commented 5 months ago

Fixed indeed by #85. Thanks @lisitsyn!