Rookfighter / knn-cpp

A header-only C++ library for k nearest neighbor search with Eigen3.
MIT License
51 stars 5 forks source link

Windows 64-bit build warnings #2

Closed kdekker closed 2 years ago

kdekker commented 4 years ago

On Windows/Visual Studio a long int does not size up to 64-bit (contrary to all *NIX flavors), but remains 32-bit. As a result, the typedef for Index (matrix.h:15) causes possible loss of precision warnings. Because (almost) everything of STL is using size_t, I would suggest to move to size_t, or if a signed index is wanted, ssize_t (or any other type that sizes with 32 and 64-bit mode of the compiler).

Unfortunately, Visual Studio does not have a typedef for ssize_t, but has SSIZE_T (uppercase). An alternative is also to use typedef long long int Index (which is platform independent). AFAIK long long never sizes to 128 bit :-)

Thanks.

Rookfighter commented 4 years ago

Thanks! I am more of a Linux user and tested the code only on mingw. I'll look into the issue and make a design decision. I'd prefer to stay with signed integers, because Eigen is also using signed integers. Sadly for being compatible with older Eigen3 versions I cannot use the typedefEigen::Index. AFAIK, currently the only option to use the Eigen Index type in a backwards compatible fashion is something like Eigen::MatrixXd::Index. However that looks a bit odd / weird.

kdekker commented 4 years ago

Thanks. I don’t know whether there is at compile time a Eigen version macro that can be used for this purpose. I indeed would prefer Eigen::Index (which is actually a ptrdiff_t type AFAIK). Not sure how many people use older Eigen versions. For now, I’ve created a workaround for myself, so there is no hurry at all. I also don’t know how eagerly Eigen is maintained, as Eigen 3.4 is not yet released and the previous 3.3 release has been released over one year ago. (I’m new to Eigen, i.e. very less experience with it).

Van: Fabian Meyer notifications@github.com Verzonden: vrijdag 6 maart 2020 21:20 Aan: Rookfighter/knn-cpp knn-cpp@noreply.github.com CC: kdekker kees.dkr@outlook.com; Author author@noreply.github.com Onderwerp: Re: [Rookfighter/knn-cpp] Windows 64-bit build warnings (#2)

Thanks! I am more of a Linux user and tested the code only on mingw. I'll look into the issue and make a design decision. I'd prefer to stay with signed integers, because Eigen is also using signed integers. Sadly for being compatible with older Eigen3 versions I cannot use the typedefEigen::Index. AFAIK, currently the only option to use the Eigen Index type in a backwards compatible fashion is something like Eigen::MatrixXd::Index. However that looks a bit odd / weird.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/Rookfighter/knn-cpp/issues/2?email_source=notifications&email_token=AF6NUSWBHHJP4DSGVFNTONTRGFLIJA5CNFSM4LBQC4PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOCXL4Q#issuecomment-595949042, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AF6NUSQYA4ZOD7GH27PYUATRGFLIJANCNFSM4LBQC4PA.