Skip to content

Commit

Permalink
VXL 2023-11-01 (6456d120)
Browse files Browse the repository at this point in the history
Code extracted from:

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

at commit 6456d12066d92a6a94c7749d189946853ab9ce98 (master).
  • Loading branch information
VXL Maintainers authored and dzenanz committed Nov 1, 2023
1 parent 9c18c34 commit 85daed4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 29 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 4.3.1.0 # defines #MAJOR,MINOR,PATCH,TWEAK}
VERSION 5.1.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
83 changes: 56 additions & 27 deletions core/vnl/vnl_sparse_matrix.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -413,32 +413,36 @@ T& vnl_sparse_matrix<T>::operator()(unsigned int r, unsigned int c)
{
assert((r < rows()) && (c < columns()));
row& rw = elements[r];
typename row::iterator ri;
for (ri = rw.begin(); (ri != rw.end()) && ((*ri).first < c); ++ri)
/*nothing*/;

if ((ri == rw.end()) || ((*ri).first != c)) {
// Add new column to the row.
ri = rw.insert(ri, vnl_sparse_matrix_pair<T>(c,T()));
if (rw.empty())
{
rw.push_back(vnl_sparse_matrix_pair<T>(c, T()));
return rw.back().second;
}

if (c < rw.back().first)
{
// Because the column number of the last entry in the row is greater than `c`, the following iteration will stop
// before the end of the row.
typename row::iterator ri = rw.begin();
while (ri->first < c)
++ri;

return (ri->first == c ? ri : rw.insert(ri, vnl_sparse_matrix_pair<T>(c, T())))->second;
}

return (*ri).second;
if (c > rw.back().first)
rw.push_back(vnl_sparse_matrix_pair<T>(c, T()));

return rw.back().second;
}

//------------------------------------------------------------
//: Get the value of an entry in the matrix.
template <class T>
T vnl_sparse_matrix<T>::operator()(unsigned int r, unsigned int c) const
{
assert((r < rows()) && (c < columns()));
row const& rw = elements[r];
typename row::const_iterator ri = rw.begin();
while (ri != rw.end() && (*ri).first < c)
++ri;
if (ri == rw.end() || (*ri).first != c)
return T(); // uninitialised value (default constructor) is returned
else
return (*ri).second;
return this->get(r, c);
}

//------------------------------------------------------------
Expand All @@ -449,13 +453,19 @@ T vnl_sparse_matrix<T>::get(unsigned int r, unsigned int c) const
{
assert((r < rows()) && (c < columns()));
row const& rw = elements[r];

if (rw.empty() || c > rw.back().first)
return T();

// Because at this point `rw.back().first >= c`, the following iteration will stop before the end of the row.
typename row::const_iterator ri = rw.begin();
while (ri != rw.end() && (*ri).first < c)
while (ri->first < c)
++ri;
if (ri == rw.end() || (*ri).first != c)
return T(); // uninitialised value (default constructor) is returned

if (ri->first == c)
return ri->second;
else
return (*ri).second;
return T();
}

//------------------------------------------------------------
Expand All @@ -465,16 +475,35 @@ void vnl_sparse_matrix<T>::put(unsigned int r, unsigned int c, T v)
{
assert((r < rows()) && (c < columns()));
row& rw = elements[r];
typename row::iterator ri = rw.begin();
while (ri != rw.end() && (*ri).first < c)
++ri;

if (ri == rw.end() || (*ri).first != c) {
// Add new column to the row.
rw.insert(ri, vnl_sparse_matrix_pair<T>(c,v));
if (rw.empty())
{
rw.push_back(vnl_sparse_matrix_pair<T>(c, v));
// Early return, having just added an entry to an empty row.
return;
}

if (c < rw.back().first)
{
// Because the column number of the last entry in the row is greater than `c`, the following iteration will stop
// before the end of the row.
typename row::iterator ri = rw.begin();
while (ri->first < c)
++ri;

if (ri->first == c)
ri->second = v;
else
rw.insert(ri, vnl_sparse_matrix_pair<T>(c, v));
}
else
(*ri).second = v;
{
if (c > rw.back().first)
rw.push_back(vnl_sparse_matrix_pair<T>(c, v));
else
// So now `c` is equal to the column number of the last entry in the row, `rw.back().first`.
rw.back().second = v;
}
}

template <class T>
Expand Down
2 changes: 1 addition & 1 deletion vcl/vcl_msvc_warnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@

// data-conversion related to 'size_t'
#pragma warning ( disable : 4267 )

#endif // _MSC_VER
#endif //vcl_msvc_warnings_h__

0 comments on commit 85daed4

Please sign in to comment.