Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace lapack with linalg in MahalanobisDistance (#4085)
* Fix broken link in doc * Use linalg in MahalanobisDistance * Apply autoformatter * Remove MehalanobisDistance from LAPACK guarded list * Add lapack guard back * Update license header style * Save ldlt instead of inverse of cov * Replace explict casts and add type check * Remove unnecessary type checks
- Loading branch information
Showing
4 changed files
with
100 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* This software is distributed under BSD 3-clause license (see LICENSE file). | ||
* | ||
* Authors: Wuwei Lin | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
#include <shogun/base/some.h> | ||
#include <shogun/distance/MahalanobisDistance.h> | ||
#include <shogun/features/DenseFeatures.h> | ||
#include <shogun/lib/common.h> | ||
|
||
using namespace shogun; | ||
|
||
TEST(MahalanobisDistance, compute_distance) | ||
{ | ||
// create four points (0,0) (2,10) (2,8) (5,5) | ||
SGMatrix<float64_t> rect(2, 4); | ||
rect(0, 0) = 0; | ||
rect(1, 0) = 0; | ||
rect(0, 1) = 2; | ||
rect(1, 1) = 10; | ||
rect(0, 2) = 2; | ||
rect(1, 2) = 8; | ||
rect(0, 3) = 5; | ||
rect(1, 3) = 5; | ||
|
||
auto feature = some<CDenseFeatures<float64_t>>(rect); | ||
auto distance = some<CMahalanobisDistance>(feature, feature); | ||
EXPECT_NEAR(distance->distance(1, 1), 0.0, 1e-10); | ||
EXPECT_NEAR(distance->distance(1, 3), 2.63447126986, 1e-10); | ||
EXPECT_NEAR(distance->distance(2, 3), 2.22834405812, 1e-10); | ||
} |