Re: [eigen] gtest helpers for eigen |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] gtest helpers for eigen
- From: "Benoit Jacob" <jacob.benoit.1@xxxxxxxxx>
- Date: Wed, 14 Jan 2009 17:47:14 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references; bh=PpGBjEe/uHTGVL8bVMFcQbHvskr0ONJmvEY1c/Ie7Gs=; b=p/Y/wKDbXnbw6HR2ckMaCnGiBWEJF2coz7KD9Ji4IIETbYZneh4byRKGDc9rM2q0wU b+HTlUWqS+fFQYIolzrWf4mw76V2DBKDWZKe4pie24YduEQfiPwqqwaZL/ZZXIrd6jax oOZ2gMoHJdNtPs4wadOR+xx3TnyD+wNlrWn5c=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references; b=LnOVFydZx9fIdL+ZSTcex8/r0eSI9XqrVUHqfMsxZg+Uz2Gqtvcb2TXC2ifnc1QFdw YhKgLkvDHZR9F43VuwAP+UUPHBzypsP5KcP8XKUrQtcGp3FHsC4Z2w6EhqEoP386zNnW eybFhMj3Es5sH1R4yOZ2fL+DKO3HtbaBRAXrk=
Hi,
I didn't know about gtest and won't be able to reply regarding that
before this weekend.
But I can already comment on testing.h:
#define EXPECT_MATRIX_NEAR(a, b, tolerance) \
do { \
bool dims_match = (a.rows() == b.rows()) && (a.cols() == b.cols()); \
EXPECT_EQ(a.rows(), b.rows()) << "Matrix rows don't match."; \
EXPECT_EQ(a.cols(), b.cols()) << "Matrix cols don't match."; \
if (dims_match) { \
for (int r = 0; r < a.rows(); ++r) { \
for (int c = 0; c < a.cols(); ++c) { \
EXPECT_NEAR(a(r, c), b(r, c), tolerance) \
<< "r=" << r << ", c=" << c << "."; \
} \
} \
} \
} while(false);
This is taking the l^\infty norm to compare matrices. It's not bad,
but it's not the best norm either.
The best norm from a math point of view is the operator norm, but it's
extremely expensive to compute.
A good compromise, that we take in eigen, is to use the
Hilbert-Schmidt norm aka the L2 norm.
Anyway Eigen offers a.isApprox(b, tolerance) already, using the L2
norm; you could just use that.
#define EXPECT_MATRIX_NEAR_ZERO(a, tolerance) \
do { \
for (int r = 0; r < a.rows(); ++r) { \
for (int c = 0; c < a.cols(); ++c) { \
EXPECT_NEAR(0.0, a(r, c), tolerance) \
<< "r=" << r << ", c=" << c << "."; \
} \
} \
} while(false);
This is potentially dangerous, as with floating point there shouldn't
be any "reference" order of magnitude.
So instead if "near_zero(tolerance)" the correct check is
"much_smaller_than(reference)" where reference depends on your context
-- there is no absolute prefered reference.
Cheers,
Benoit
2009/1/14 Keir Mierle <mierle@xxxxxxxxx>:
> Would anyone be interested in having a extensions for testing numeric code
> based on eigen2 with gtest? (http://code.google.com/p/googletest)
> I have added the following to
> libmv: http://code.google.com/p/libmv/source/browse/trunk/src/testing/testing.h,
> and it has proved very useful.
> I thought others might be interested. Perhaps have something similar in a
> contrib/ directory?
> Keir