[mlpack-svn] r10746 - mlpack/trunk/src/mlpack/core/arma_extend/sparse

fastlab-svn at coffeetalk-1.cc.gatech.edu fastlab-svn at coffeetalk-1.cc.gatech.edu
Tue Dec 13 06:17:56 EST 2011


Author: rcurtin
Date: 2011-12-13 06:17:55 -0500 (Tue, 13 Dec 2011)
New Revision: 10746

Modified:
   mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpMat_meat.hpp
   mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpSubview_bones.hpp
   mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpSubview_meat.hpp
Log:
Use a const reference internally in SpSubviews.


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-13 11:17:34 UTC (rev 10745)
+++ mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpMat_meat.hpp	2011-12-13 11:17:55 UTC (rev 10746)
@@ -2786,6 +2786,8 @@
 SpMat<eT>::operator()(const span& row_span, const span& col_span)
   {
   arma_extra_debug_sigprint();
+
+  return submat(row_span, col_span);
   }
 
 template<typename eT>
@@ -2794,6 +2796,8 @@
 SpMat<eT>::operator()(const span& row_span, const span& col_span) const
   {
   arma_extra_debug_sigprint();
+
+  return submat(row_span, col_span);
   }
 
 /**

Modified: mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpSubview_bones.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpSubview_bones.hpp	2011-12-13 11:17:34 UTC (rev 10745)
+++ mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpSubview_bones.hpp	2011-12-13 11:17:55 UTC (rev 10746)
@@ -3,7 +3,7 @@
 template<typename eT>
 class SpSubview : public Base<eT, SpSubview<eT> >
   {
-  public: SpMat<eT>& m;
+  public: const SpMat<eT>& m;
 
   public:
 

Modified: mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpSubview_meat.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpSubview_meat.hpp	2011-12-13 11:17:34 UTC (rev 10745)
+++ mlpack/trunk/src/mlpack/core/arma_extend/sparse/SpSubview_meat.hpp	2011-12-13 11:17:55 UTC (rev 10746)
@@ -95,7 +95,7 @@
     {
     for(uword row = start_row; row < end_row; ++row)
       {
-      m.at(row, col) += val;
+      access::rw(m).at(row, col) += val;
       }
     }
   }
@@ -124,7 +124,7 @@
     {
     for(uword row = start_row; row < end_row; ++row)
       {
-      m.at(row, col) -= val;
+      access::rw(m).at(row, col) -= val;
       }
     }
   }
@@ -149,7 +149,7 @@
       {
       if(m.row_indices[r] >= start_row && m.row_indices[r] < end_row)
         {
-        m.values[r] *= val;
+        access::rw(m).values[r] *= val;
         }
       }
     }
@@ -173,7 +173,7 @@
     {
     for(uword r = m.col_ptrs[c]; r < m.col_ptrs[++c]; ++r)
       {
-      m.values[r] /= val;
+      access::rw(m).values[r] /= val;
       }
     }
   }
@@ -190,7 +190,7 @@
 
   const Proxy<T1> P(x.get_ref());
 
-  arma_debug_assert_same_size(*this, P, "insert into sparse submatrix");
+  arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "insert into sparse submatrix");
 
   const uword start_row = aux_row1;
   const uword end_row   = aux_row1 + n_rows;
@@ -201,7 +201,7 @@
     {
     for(uword r = start_row; r < end_row; ++r)
       {
-      m.at(r, c) = P.at(r, c);
+      access::rw(m).at(r, c) = P.at(r, c);
       }
     }
   }
@@ -218,7 +218,7 @@
 
   const Proxy<T1> P(x.get_ref());
 
-  arma_debug_assert_same_size(*this, P, "insert into sparse submatrix");
+  arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "addition into sparse submatrix");
 
   const uword start_row = aux_row1;
   const uword end_row   = aux_row1 + n_rows;
@@ -229,7 +229,7 @@
     {
     for(uword r = start_row; r < end_row; ++r)
       {
-      m.at(r, c) += P.at(r, c);
+      access::rw(m).at(r, c) += P.at(r, c);
       }
     }
   }
@@ -246,7 +246,7 @@
 
   const Proxy<T1> P(x.get_ref());
 
-  arma_debug_assert_same_size(*this, P, "insert into sparse submatrix");
+  arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "subtraction into sparse submatrix");
 
   const uword start_row = aux_row1;
   const uword end_row   = aux_row1 + n_rows;
@@ -257,7 +257,7 @@
     {
     for(uword r = start_row; r < end_row; ++r)
       {
-      m.at(r, c) += P.at(r, c);
+      access::rw(m).at(r, c) += P.at(r, c);
       }
     }
   }
@@ -274,7 +274,7 @@
 
   const Proxy<T1> P(x.get_ref());
 
-  arma_debug_assert_same_size(*this, P, "insert into sparse submatrix");
+  arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "element-wise multiplication into sparse submatrix");
 
   const uword start_row = aux_row1;
   const uword end_row   = aux_row1 + n_rows;
@@ -285,7 +285,7 @@
     {
     for(uword r = start_row; r < end_row; ++r)
       {
-      m.at(r, c) %= P.at(r, c);
+      access::rw(m).at(r, c) %= P.at(r, c);
       }
     }
   }
@@ -302,7 +302,7 @@
 
   const Proxy<T1> P(x.get_ref());
 
-  arma_debug_assert_same_size(*this, P, "insert into sparse submatrix");
+  arma_debug_assert_same_size(n_rows, n_cols, P.get_n_rows(), P.get_n_cols(), "element-wise division into sparse submatrix");
 
   const uword start_row = aux_row1;
   const uword end_row   = aux_row1 + n_rows;
@@ -313,7 +313,7 @@
     {
     for(uword r = start_row; r < end_row; ++r)
       {
-      m.at(r, c) /= P.at(r, c);
+      access::rw(m).at(r, c) /= P.at(r, c);
       }
     }
   }
@@ -341,7 +341,7 @@
   arma_extra_debug_sigprint();
 
   // we can be a little smarter here
-  for(typename SpMat<eT>::iterator it(m, aux_row1, aux_col1);
+  for(typename SpMat<eT>::iterator it(access::rw(m), aux_row1, aux_col1);
       (it.col < (aux_col1 + n_cols - 1)) || (it.col == (aux_col1 + n_cols - 1) && it.row < (aux_row1 + n_rows));
       ++it)
     {
@@ -473,7 +473,7 @@
 eT&
 SpSubview<eT>::at(const uword in_row, const uword in_col)
   {
-  return m.at(aux_row1 + in_row, aux_col1 + in_col);
+  return access::rw(m).at(aux_row1 + in_row, aux_col1 + in_col);
   }
 
 
@@ -554,8 +554,8 @@
   for(uword c = start_col; c < end_col; ++c)
     {
     eT val = m.at(in_row1 + aux_row1, c);
-    m.at(in_row2 + aux_row1, c) = m.at(in_row1 + aux_row1, c);
-    m.at(in_row1 + aux_row1, c) = val;
+    access::rw(m).at(in_row2 + aux_row1, c) = m.at(in_row1 + aux_row1, c);
+    access::rw(m).at(in_row1 + aux_row1, c) = val;
     }
   }
 
@@ -576,8 +576,8 @@
   for(uword r = start_row; r < end_row; ++r)
     {
     eT val = m.at(r, in_col1 + aux_col1);
-    m.at(r, in_col1 + aux_col1) = m.at(r, in_col2 + aux_col1);
-    m.at(r, in_col2 + aux_col1) = val;
+    access::rw(m).at(r, in_col1 + aux_col1) = m.at(r, in_col2 + aux_col1);
+    access::rw(m).at(r, in_col2 + aux_col1) = val;
     }
   }
 




More information about the mlpack-svn mailing list