[mlpack-svn] r10832 - mlpack/trunk/src/mlpack/core/arma_extend/sparse
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Thu Dec 15 06:02:42 EST 2011
Author: rcurtin
Date: 2011-12-15 06:02:42 -0500 (Thu, 15 Dec 2011)
New Revision: 10832
Modified:
mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpMat_meat.hpp
Log:
Some SpMat bugfixes.
Modified: mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpMat_meat.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpMat_meat.hpp 2011-12-15 08:43:17 UTC (rev 10831)
+++ mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpMat_meat.hpp 2011-12-15 11:02:42 UTC (rev 10832)
@@ -1853,6 +1853,10 @@
template<typename T1>
inline
SpMat<eT>::SpMat(const BaseCube<eT, T1>& X)
+ : n_rows(0)
+ , n_cols(0)
+ , n_elem(0)
+ , n_nonzero(0)
{
arma_extra_debug_sigprint_this(this);
@@ -2258,6 +2262,10 @@
template<typename eT>
inline
SpMat<eT>::SpMat(const SpSubview<eT>& X)
+ : n_rows(0)
+ , n_cols(0)
+ , n_elem(0)
+ , n_nonzero(0)
{
arma_extra_debug_sigprint_this(this);
@@ -2279,7 +2287,7 @@
init(in_n_rows, in_n_cols);
// Iterate through the matrix using the internal matrix's iterators.
- const_iterator it = const_iterator(X.m, X.m.aux_row1, X.m.aux_col1);
+ const_iterator it = const_iterator(X.m, X.aux_row1, X.aux_col1);
while(it.col < (X.aux_col1 + in_n_cols) && it.row < (X.aux_row1 + in_n_rows))
{
@@ -2288,7 +2296,7 @@
{
values.push_back(*it);
row_indices.push_back(it.row - X.aux_row1);
- ++col_ptrs[(it.col - X.m.aux_col1) + 1]; // This is not completely correct, we'll fix it later.
+ ++col_ptrs[(it.col - X.aux_col1) + 1]; // This is not completely correct, we'll fix it later.
}
++it;
@@ -2299,6 +2307,8 @@
{
col_ptrs[col] += col_ptrs[col - 1];
}
+
+ return *this;
}
@@ -2315,7 +2325,7 @@
const uword in_n_cols = X.n_cols;
const uword in_n_rows = X.n_rows;
- const_iterator it = const_iterator(X.m, X.m.aux_row1, X.m.aux_col1);
+ const_iterator it = const_iterator(X.m, X.aux_row1, X.aux_col1);
while(it.col < (X.aux_col1 + in_n_cols) && it.row < (X.aux_row1 + in_n_rows))
{
@@ -2325,6 +2335,8 @@
at(it.row - X.aux_row1, it.col - X.aux_col1) += (*it);
}
}
+
+ return *this;
}
@@ -2341,7 +2353,7 @@
const uword in_n_cols = X.n_cols;
const uword in_n_rows = X.n_rows;
- const_iterator it = const_iterator(X.m, X.m.aux_row1, X.m.aux_col1);
+ const_iterator it = const_iterator(X.m, X.aux_row1, X.aux_col1);
while(it.col < (X.aux_col1 + in_n_cols) && it.row < (X.aux_row1 + in_n_rows))
{
@@ -2351,6 +2363,8 @@
at(it.row - X.aux_row1, it.col - X.aux_col1) -= (*it);
}
}
+
+ return *this;
}
@@ -2384,6 +2398,8 @@
// With the calculation done, assign the temporary to ourselves.
init(z);
+
+ return *this;
}
@@ -2420,6 +2436,8 @@
++it;
}
}
+
+ return *this;
}
@@ -2437,6 +2455,8 @@
{
at(elem) /= x(elem);
}
+
+ return *this;
}
/**
@@ -2445,6 +2465,10 @@
template<typename eT>
inline
SpMat<eT>::SpMat(const subview<eT>& x)
+ : n_rows(0)
+ , n_cols(0)
+ , n_elem(0)
+ , n_nonzero(0)
{
arma_extra_debug_sigprint_this(this);
@@ -2477,6 +2501,8 @@
col_ptrs[col + 1] = values.size();
}
+
+ return *this;
}
@@ -2495,6 +2521,8 @@
{
at(elem) += x(elem);
}
+
+ return *this;
}
@@ -2513,6 +2541,8 @@
{
at(elem) -= x(elem);
}
+
+ return *this;
}
@@ -2537,6 +2567,8 @@
z(x_row_it.row, col) += (*x_row_it) * y(x_row_it.col, col);
}
}
+
+ return *this;
}
@@ -2555,6 +2587,8 @@
{
at(elem) *= x(elem);
}
+
+ return *this;
}
@@ -2573,6 +2607,8 @@
{
at(elem) /= x(elem);
}
+
+ return *this;
}
@@ -2681,6 +2717,16 @@
SpMat<eT>::rows(const uword in_row1, const uword in_row2)
{
arma_extra_debug_sigprint();
+
+ arma_debug_check
+ (
+ (in_row1 > in_row2) || (in_row2 >= n_rows),
+ "SpMat::rows(): indices out of bounds or incorrectly used"
+ );
+
+ const uword subview_n_rows = in_row2 - in_row1 + 1;
+
+ return SpSubview<eT>(*this, in_row1, 0, subview_n_rows, n_cols);
}
template<typename eT>
@@ -2689,6 +2735,16 @@
SpMat<eT>::rows(const uword in_row1, const uword in_row2) const
{
arma_extra_debug_sigprint();
+
+ arma_debug_check
+ (
+ (in_row1 > in_row2) || (in_row2 >= n_rows),
+ "SpMat::rows(): indices out of bounds or incorrectly used"
+ );
+
+ const uword subview_n_rows = in_row2 - in_row1 + 1;
+
+ return SpSubview<eT>(*this, in_row1, 0, subview_n_rows, n_cols);
}
template<typename eT>
@@ -2697,6 +2753,16 @@
SpMat<eT>::cols(const uword in_col1, const uword in_col2)
{
arma_extra_debug_sigprint();
+
+ arma_debug_check
+ (
+ (in_col1 > in_col2) || (in_col2 >= n_cols),
+ "SpMat::cols(): indices out of bounds or incorrectly used"
+ );
+
+ const uword subview_n_cols = in_col2 - in_col1 + 1;
+
+ return SpSubview<eT>(*this, 0, in_col1, n_rows, subview_n_cols);
}
template<typename eT>
@@ -2705,6 +2771,16 @@
SpMat<eT>::cols(const uword in_col1, const uword in_col2) const
{
arma_extra_debug_sigprint();
+
+ arma_debug_check
+ (
+ (in_col1 > in_col2) || (in_col2 >= n_cols),
+ "SpMat::cols(): indices out of bounds or incorrectly used"
+ );
+
+ const uword subview_n_cols = in_col2 - in_col1 + 1;
+
+ return SpSubview<eT>(*this, 0, in_col1, n_rows, subview_n_cols);
}
template<typename eT>
More information about the mlpack-svn
mailing list