Skip to content

Commit

Permalink
VXL 2024-07-31 (02dd6b78)
Browse files Browse the repository at this point in the history
Code extracted from:

    https://github.com/vxl/vxl.git

at commit 02dd6b78394d4e2cc43ff0fb39454c0fcf1aa85e (master).
  • Loading branch information
VXL Maintainers authored and seanm committed Jul 31, 2024
1 parent 85daed4 commit 365c764
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ foreach(p
endforeach()

project(VXL #Project name must be all caps to have properly generated VXL_VERSION_* variables
VERSION 5.1.0.0 # defines #MAJOR,MINOR,PATCH,TWEAK}
VERSION 5.3.0.0 # defines #MAJOR,MINOR,PATCH,TWEAK}
DESCRIPTION "A multi-platform collection of C++ software libraries for Computer Vision and Image Understanding."
LANGUAGES CXX C)

Expand Down
2 changes: 1 addition & 1 deletion core/vnl/algo/vnl_amoeba.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ vnl_amoebaFit::amoeba(vnl_vector<double> & x, std::vector<vnl_amoeba_SimplexCorn
if (verbose)
{
char buf[16383];
std::sprintf(buf, "iter %5d: %s ", cnt, how);
std::snprintf(buf, sizeof(buf), "iter %5d: %s ", cnt, how);
std::cerr << buf;
if (verbose == 2)
std::cerr << "\nFirst corner: " << simplex[0].v;
Expand Down
6 changes: 6 additions & 0 deletions core/vnl/tests/test_matrix_fixed.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,12 @@ test_float()
TEST("m.update([4],1,1)",
((m3 = 4), (m.update(m3, 1, 1)), (m(0, 0) == 0 && m(0, 1) == -2 && m(1, 0) == 2 && m(1, 1) == 4)),
true);

constexpr auto quiet_NaN = std::numeric_limits<float>::quiet_NaN();
TEST("vnl_float_2x2 { NaN, ... } != { 0.0f, ... }", vnl_float_2x2(quiet_NaN) != vnl_float_2x2(0.0f), true);
TEST("vnl_float_2x2 { NaN, ... } is_equal { 0.0f, ... } is false",
vnl_float_2x2(quiet_NaN).is_equal(vnl_float_2x2(0.0f), 0.0f),
false);
}

static void
Expand Down
32 changes: 32 additions & 0 deletions core/vnl/tests/test_vector.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,33 @@ vnl_vector_test_int()
(out_values[0] == minus_v2[0] && out_values[1] == minus_v2[1] && out_values[2] == minus_v2[2] &&
out_values[3] == minus_v2[3]), true);
}
{ // test vnl_vector_fixed::is_equal
using int_vector_fixed_type = vnl_vector_fixed<int, 2>;

TEST("vnl_vector_fixed(0) instances compare equal",
int_vector_fixed_type(0).is_equal(int_vector_fixed_type(0), 0.0),
true);
TEST("vnl_vector_fixed(1) instances compare equal",
int_vector_fixed_type(1).is_equal(int_vector_fixed_type(1), 0.0),
true);
TEST("vnl_vector_fixed(0) and vnl_vector_fixed(1) do not compare equal",
int_vector_fixed_type(0).is_equal(int_vector_fixed_type(1), 0.0),
false);

using double_vector_fixed_type = vnl_vector_fixed<double, 2>;

const double_vector_fixed_type default_vector_fixed{};

TEST("A default double_vector_fixed_type compares equal to itself",
default_vector_fixed.is_equal(default_vector_fixed, 0.0),
true);
TEST("vnl_vector_fixed(0.9) and vnl_vector_fixed(1.1) do not compare equal with zero tol",
double_vector_fixed_type(0.9).is_equal(double_vector_fixed_type(1.1), 0.0),
false);
TEST("vnl_vector_fixed(0.9) and vnl_vector_fixed(1.1) compare equal with tol 0.3",
double_vector_fixed_type(0.9).is_equal(double_vector_fixed_type(1.1), 0.3),
true);
}
}

bool
Expand Down Expand Up @@ -616,6 +642,12 @@ vnl_vector_test_float()
}

TEST("vnl_vector_ssd", vnl_vector_ssd(vnl_vector<float>(4, 0.0f), vnl_vector<float>(4, 1.0f)), 4.0);

constexpr auto quiet_NaN = std::numeric_limits<float>::quiet_NaN();
TEST("vnl_vector { NaN } != { 0.0f }", vnl_vector<float>(1, quiet_NaN) != vnl_vector<float>(1, 0.0f), true);
TEST("vnl_vector { NaN } is_equal { 0.0f } is false",
vnl_vector<float>(1, quiet_NaN).is_equal(vnl_vector<float>(1, 0.0f), 0.0f),
false);
}

void
Expand Down
2 changes: 1 addition & 1 deletion core/vnl/vnl_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class VNL_EXPORT vnl_alloc
}
*my_free_list = result -> free_list_link;
return result;
};
}

/* p may not be 0 */
static void deallocate(void *p, std::size_t n)
Expand Down
2 changes: 1 addition & 1 deletion core/vnl/vnl_matrix.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ bool vnl_matrix<T>::is_equal(vnl_matrix<T> const& rhs, double tol) const

for (unsigned int i = 0; i < this->rows(); ++i)
for (unsigned int j = 0; j < this->columns(); ++j)
if (vnl_math::abs(this->data[i][j] - rhs.data[i][j]) > tol)
if (!(vnl_math::abs(this->data[i][j] - rhs.data[i][j]) <= tol))
return false; // difference greater than tol

return true;
Expand Down
2 changes: 1 addition & 1 deletion core/vnl/vnl_matrix_fixed.h
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ class VNL_EXPORT vnl_matrix_fixed
#endif
operator const vnl_matrix_ref<T>() const { return this->as_ref(); }
#endif
explicit operator vnl_matrix<T>() const { return this->as_matrix(); };
explicit operator vnl_matrix<T>() const { return this->as_matrix(); }


//----------------------------------------------------------------------
Expand Down
5 changes: 1 addition & 4 deletions core/vnl/vnl_matrix_fixed.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -699,12 +699,9 @@ bool vnl_matrix_fixed<T,nrows,ncols>
if (this == &rhs) // same object => equal.
return true;

if (this->rows() != rhs.rows() || this->cols() != rhs.cols())
return false; // different sizes => not equal.

for (unsigned int i = 0; i < nrows; ++i)
for (unsigned int j = 0; j < ncols; ++j)
if (vnl_math::abs(this->data_[i][j] - rhs.data_[i][j]) > tol)
if (!(vnl_math::abs(this->data_[i][j] - rhs.data_[i][j]) <= tol))
return false; // difference greater than tol

return true;
Expand Down
2 changes: 1 addition & 1 deletion core/vnl/vnl_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class VNL_EXPORT vnl_vector
this->data= indata ;
this->num_elmts = nelmts;
this->m_LetArrayManageMemory = manage_own_memory;
};
}
//#endif

void assert_size_internal(size_t sz) const;
Expand Down
2 changes: 1 addition & 1 deletion core/vnl/vnl_vector.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ bool vnl_vector<T>::is_equal(vnl_vector<T> const& rhs, double tol) const
if (this->size() != rhs.size()) //Size different ?
return false;
for (size_t i = 0; i < size(); i++)
if (vnl_math::abs(this->data[i] - rhs.data[i]) > tol) //Element different ?
if (!(vnl_math::abs(this->data[i] - rhs.data[i]) <= tol)) //Element different ?
return false;

return true;
Expand Down
3 changes: 3 additions & 0 deletions core/vnl/vnl_vector_fixed.h
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ class VNL_EXPORT vnl_vector_fixed
//: Return true iff the size is zero.
bool empty() const { return n==0; }

//: Return true if all elements of the two vectors are equal, within given tolerance
bool is_equal(vnl_vector_fixed const& rhs, double tol) const;

//: Return true if *this == v
bool operator_eq (vnl_vector_fixed<T,n> const& v) const
{
Expand Down
13 changes: 13 additions & 0 deletions core/vnl/vnl_vector_fixed.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,19 @@ vnl_vector_fixed<T,n>::assert_finite_internal() const
std::abort();
}

template <class T, unsigned int n>
bool vnl_vector_fixed<T,n>::is_equal(vnl_vector_fixed<T,n> const& rhs, double tol) const
{
if (this == &rhs) //Same object ? => equal.
return true;

for (size_t i = 0; i < n; ++i)
if (!(vnl_math::abs(this->data_[i] - rhs.data_[i]) <= tol)) //Element different ?
return false;

return true;
}

template <class T, unsigned int n>
void
vnl_vector_fixed<T,n>::print(std::ostream& s) const
Expand Down

0 comments on commit 365c764

Please sign in to comment.