Skip to content

Commit 9c18c34

Browse files
VXL Maintainersdzenanz
authored andcommitted
VXL 2023-06-18 (4332fd74)
Code extracted from: https://github.com/vxl/vxl.git at commit 4332fd7409a6d26902c0477fe2991a3185282e45 (master).
1 parent 3735130 commit 9c18c34

21 files changed

+207
-44
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ foreach(p
6767
endforeach()
6868

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

core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ CMAKE_DEPENDENT_OPTION( VXL_BUILD_VGUI "Build VGUI" OFF
121121
mark_as_advanced(VXL_BUILD_VGUI)
122122
if(VXL_BUILD_VGUI)
123123
add_subdirectory(vgui)
124+
else()
125+
unset(VGUI_FOUND)
124126
endif()
125127

126128

core/vnl/tests/test_matrix.cxx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,24 @@ test_int()
349349
for (unsigned int i = 0; i < vc.size(); ++i)
350350
TEST("vc.apply_columnwise(sum_vector)", vc.get(i), 5);
351351
}
352+
353+
{ // test operator-() on unsigned values
354+
unsigned int vvalues[] = {1, 2, 3, 4};
355+
int out_values[] = {-1, -2, -3, -4};
356+
const vnl_matrix<int> outm(2, 2, 4, out_values);
357+
358+
vnl_matrix<unsigned int> unsigned_m22(2, 2, 4, vvalues);
359+
const vnl_matrix<int> minus_v1 = -unsigned_m22;
360+
const vnl_matrix<int> minus_v2 = unsigned_m22.operator-();
361+
TEST("unsigned_m22.operator-()",
362+
(outm(0, 0) == minus_v1(0, 0) && outm(0, 1) == minus_v1(0, 1) && outm(1, 0) == minus_v1(1, 0) &&
363+
outm(1, 1) == minus_v1(1, 1)), true);
364+
TEST("unsigned_m22.operator-()",
365+
(outm(0, 0) == minus_v2(0, 0) && outm(0, 1) == minus_v2(0, 1) && outm(1, 0) == minus_v2(1, 0) &&
366+
outm(1, 1) == minus_v2(1, 1)), true);
367+
}
368+
369+
352370
}
353371

354372

core/vnl/tests/test_matrix_fixed.cxx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,22 @@ test_int()
292292
TEST("m.update([4],1,1)",
293293
((m3 = 4), (m.update(m3, 1, 1)), (m(0, 0) == 0 && m(0, 1) == -2 && m(1, 0) == 2 && m(1, 1) == 4)),
294294
true);
295+
296+
{ // test operator-() on unsigned values
297+
unsigned int vvalues[] = {1, 2, 3, 4};
298+
int out_values[] = {-1, -2, -3, -4};
299+
const vnl_matrix_fixed<int,2,2> outm( out_values);
300+
301+
vnl_matrix_fixed<unsigned int,2,2> unsigned_m22(vvalues);
302+
const vnl_matrix_fixed<int,2,2> minus_v1 = -unsigned_m22;
303+
const vnl_matrix_fixed<int,2,2> minus_v2 = unsigned_m22.operator-();
304+
TEST("unsigned_m22.operator-()",
305+
(outm(0, 0) == minus_v1(0, 0) && outm(0, 1) == minus_v1(0, 1) && outm(1, 0) == minus_v1(1, 0) &&
306+
outm(1, 1) == minus_v1(1, 1)), true);
307+
TEST("unsigned_m22.operator-()",
308+
(outm(0, 0) == minus_v2(0, 0) && outm(0, 1) == minus_v2(0, 1) && outm(1, 0) == minus_v2(1, 0) &&
309+
outm(1, 1) == minus_v2(1, 1)), true);
310+
}
295311
}
296312

297313
static void

core/vnl/tests/test_vector.cxx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,37 @@ vnl_vector_test_int()
317317
v = v_temp, v.roll_inplace(-5); // Positive, in range
318318
TEST("v.roll_inplace(-5)", (1 == v[0] && 2 == v[1] && 3 == v[2] && 0 == v[3]), true);
319319
}
320+
321+
{ // test operator-() on unsigned values
322+
unsigned int vvalues[] = {1, 2, 3, 4};
323+
int out_values[] = {-1, -2, -3, -4};
324+
325+
vnl_vector<unsigned int> unsigned_v(4, 4, vvalues);
326+
const vnl_vector<int> minus_v1 = -unsigned_v;
327+
const vnl_vector<int> minus_v2 = unsigned_v.operator-();
328+
TEST("unsigned_v.operator-()",
329+
(out_values[0] == minus_v1[0] && out_values[1] == minus_v1[1] && out_values[2] == minus_v1[2] &&
330+
out_values[3] == minus_v1[3]), true);
331+
TEST("unsigned_v.operator-()",
332+
(out_values[0] == minus_v2[0] && out_values[1] == minus_v2[1] && out_values[2] == minus_v2[2] &&
333+
out_values[3] == minus_v2[3]), true);
334+
}
335+
336+
{ // test operator-() on unsigned values
337+
unsigned int vvalues[] = {1, 2, 3, 4};
338+
int out_values[] = {-1, -2, -3, -4};
339+
340+
vnl_vector_fixed<unsigned int,4> unsigned_v(vvalues);
341+
const vnl_vector_fixed<int,4> minus_v1 = -unsigned_v;
342+
const vnl_vector_fixed<int,4> minus_v2 = unsigned_v.operator-();
343+
TEST("unsigned_v.operator-()",
344+
(out_values[0] == minus_v1[0] && out_values[1] == minus_v1[1] && out_values[2] == minus_v1[2] &&
345+
out_values[3] == minus_v1[3]), true);
346+
TEST("unsigned_v.operator-()",
347+
(out_values[0] == minus_v2[0] && out_values[1] == minus_v2[1] && out_values[2] == minus_v2[2] &&
348+
out_values[3] == minus_v2[3]), true);
349+
}
350+
320351
}
321352

322353
bool

core/vnl/vnl_bignum_traits.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class VNL_EXPORT vnl_numeric_traits<vnl_bignum>
2525
typedef vnl_bignum double_t;
2626
//: Name of type which results from multiplying this type with a double
2727
typedef double real_t;
28+
//: Name of this type
29+
using self = vnl_bignum;
30+
//: Name of type which results from using a unary operator-()
31+
using signed_t = self;
32+
2833
};
2934

3035
#endif // vnl_bignum_traits_h_

core/vnl/vnl_decnum_traits.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class VNL_EXPORT vnl_numeric_traits<vnl_decnum>
2525
typedef vnl_decnum double_t;
2626
//: Name of type which results from multiplying this type with a double
2727
typedef vnl_decnum real_t;
28+
//: Name of this type
29+
using self = vnl_decnum;
30+
//: Name of type which results from using a unary operator-()
31+
using signed_t = self;
32+
2833
};
2934

3035
#endif // vnl_decnum_traits_h_

core/vnl/vnl_matrix.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ class VNL_EXPORT vnl_matrix
284284
vnl_matrix<T>& operator*=(vnl_matrix<T> const&rhs) { return *this = (*this) * rhs; }
285285

286286
//: Negate all elements of matrix
287-
vnl_matrix<T> operator-() const;
287+
vnl_matrix<typename vnl_numeric_traits<T>::signed_t> operator-() const;
288288

289289

290290
//: Add rhs to each element of lhs matrix and return result in new matrix

core/vnl/vnl_matrix.hxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,12 @@ vnl_matrix<T> operator- (T const& value, vnl_matrix<T> const& m)
548548
// O(m*n).
549549

550550
template <class T>
551-
vnl_matrix<T> vnl_matrix<T>::operator- () const
551+
vnl_matrix<typename vnl_numeric_traits<T>::signed_t> vnl_matrix<T>::operator- () const
552552
{
553-
vnl_matrix<T> result(this->num_rows, this->num_cols);
553+
vnl_matrix<typename vnl_numeric_traits<T>::signed_t> result(this->num_rows, this->num_cols);
554554
for (unsigned int i = 0; i < this->num_rows; i++)
555555
for (unsigned int j = 0; j < this->num_cols; j++)
556-
result.data[i][j] = - this->data[i][j];
556+
result(i,j) = - this->data[i][j];
557557
return result;
558558
}
559559

core/vnl/vnl_matrix_fixed.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,26 @@ class VNL_EXPORT vnl_matrix_fixed
223223

224224
//: Access an element for reading or writing
225225
// There are assert style boundary checks - #define NDEBUG to turn them off.
226-
T & operator() (unsigned r, unsigned c);
226+
T & operator() (unsigned r, unsigned c)
227+
{
228+
#if VNL_CONFIG_CHECK_BOUNDS && (!defined NDEBUG)
229+
assert(r < rows()); // Check the row index is valid
230+
assert(c < cols()); // Check the column index is valid
231+
#endif
232+
return this->data_[r][c];
233+
}
234+
227235

228236
//: Access an element for reading
229237
// There are assert style boundary checks - #define NDEBUG to turn them off.
230-
T const & operator() (unsigned r, unsigned c) const;
238+
T const & operator() (unsigned r, unsigned c) const
239+
{
240+
#if VNL_CONFIG_CHECK_BOUNDS && (!defined NDEBUG)
241+
assert(r < rows()); // Check the row index is valid
242+
assert(c < cols()); // Check the column index is valid
243+
#endif
244+
return this->data_[r][c];
245+
}
231246

232247
// ----------------------- Filling and copying -----------------------
233248

@@ -353,10 +368,12 @@ class VNL_EXPORT vnl_matrix_fixed
353368
}
354369

355370
//: Negate all elements of matrix
356-
vnl_matrix_fixed operator- () const
371+
vnl_matrix_fixed<typename vnl_numeric_traits<T>::signed_t, num_rows,num_cols> operator- () const
357372
{
358-
vnl_matrix_fixed r;
359-
self::sub( T(0), data_block(), r.data_block() );
373+
vnl_matrix_fixed<typename vnl_numeric_traits<T>::signed_t, num_rows,num_cols> r;
374+
for(int i=0; i<num_rows; ++i)
375+
for(int j=0; j<num_cols; ++j)
376+
r(i,j) = -(*this)(i,j);
360377
return r;
361378
}
362379

0 commit comments

Comments
 (0)