|
@@ -7,6 +7,7 @@
|
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
#include "slice_into.h"
|
|
#include "slice_into.h"
|
|
|
#include "colon.h"
|
|
#include "colon.h"
|
|
|
|
|
+#include "sort.h"
|
|
|
|
|
|
|
|
// Bug in unsupported/Eigen/SparseExtra needs iostream first
|
|
// Bug in unsupported/Eigen/SparseExtra needs iostream first
|
|
|
#include <iostream>
|
|
#include <iostream>
|
|
@@ -20,31 +21,42 @@ IGL_INLINE void igl::slice_into(
|
|
|
Eigen::SparseMatrix<T>& Y)
|
|
Eigen::SparseMatrix<T>& Y)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
-#ifndef NDEBUG
|
|
|
|
|
- int xm = X.rows();
|
|
|
|
|
- int xn = X.cols();
|
|
|
|
|
|
|
+ const int xm = X.rows();
|
|
|
|
|
+ const int xn = X.cols();
|
|
|
assert(R.size() == xm);
|
|
assert(R.size() == xm);
|
|
|
assert(C.size() == xn);
|
|
assert(C.size() == xn);
|
|
|
- int ym = Y.rows();
|
|
|
|
|
- int yn = Y.cols();
|
|
|
|
|
|
|
+ const int ym = Y.rows();
|
|
|
|
|
+ const int yn = Y.cols();
|
|
|
assert(R.minCoeff() >= 0);
|
|
assert(R.minCoeff() >= 0);
|
|
|
assert(R.maxCoeff() < ym);
|
|
assert(R.maxCoeff() < ym);
|
|
|
assert(C.minCoeff() >= 0);
|
|
assert(C.minCoeff() >= 0);
|
|
|
assert(C.maxCoeff() < yn);
|
|
assert(C.maxCoeff() < yn);
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|
- // create temporary dynamic sparse matrix
|
|
|
|
|
- Eigen::DynamicSparseMatrix<T, Eigen::RowMajor> dyn_Y(Y);
|
|
|
|
|
- // Iterate over outside
|
|
|
|
|
- for(int k=0; k<X.outerSize(); ++k)
|
|
|
|
|
|
|
+ std::vector<bool> in_R(Y.rows());
|
|
|
|
|
+ for(int r = 0;r<R.size();r++) { in_R[R(r)] = true; }
|
|
|
|
|
+
|
|
|
|
|
+ // Rebuild each column in C
|
|
|
|
|
+ for(int c = 0;c<C.size();c++)
|
|
|
{
|
|
{
|
|
|
- // Iterate over inside
|
|
|
|
|
- for(typename Eigen::SparseMatrix<T>::InnerIterator it (X,k); it; ++it)
|
|
|
|
|
|
|
+ int k = C(c);
|
|
|
|
|
+ Eigen::SparseVector<T> Yk = Y.col(k);
|
|
|
|
|
+ // implicit zeros
|
|
|
|
|
+ for(typename Eigen::SparseMatrix<T>::InnerIterator yit(Y, k);yit;++yit)
|
|
|
{
|
|
{
|
|
|
- dyn_Y.coeffRef(R(it.row()),C(it.col())) = it.value();
|
|
|
|
|
|
|
+ if(in_R[yit.row()]){ Yk.coeffRef(yit.row()) = 0; }
|
|
|
}
|
|
}
|
|
|
|
|
+ // explicit values
|
|
|
|
|
+ for(typename Eigen::SparseMatrix<T>::InnerIterator xit(X, c);xit;++xit)
|
|
|
|
|
+ {
|
|
|
|
|
+ // row in X
|
|
|
|
|
+ int r = xit.row();
|
|
|
|
|
+ // row in Y
|
|
|
|
|
+ int s = R(r);
|
|
|
|
|
+ Yk.coeffRef(s) = xit.value();
|
|
|
|
|
+ }
|
|
|
|
|
+ Y.col(k) = Yk;
|
|
|
}
|
|
}
|
|
|
- Y = Eigen::SparseMatrix<T>(dyn_Y);
|
|
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
template <typename DerivedX, typename DerivedY, typename DerivedR, typename DerivedC>
|
|
template <typename DerivedX, typename DerivedY, typename DerivedR, typename DerivedC>
|
|
@@ -57,16 +69,14 @@ IGL_INLINE void igl::slice_into(
|
|
|
|
|
|
|
|
int xm = X.rows();
|
|
int xm = X.rows();
|
|
|
int xn = X.cols();
|
|
int xn = X.cols();
|
|
|
-#ifndef NDEBUG
|
|
|
|
|
assert(R.size() == xm);
|
|
assert(R.size() == xm);
|
|
|
assert(C.size() == xn);
|
|
assert(C.size() == xn);
|
|
|
- int ym = Y.rows();
|
|
|
|
|
- int yn = Y.cols();
|
|
|
|
|
|
|
+ const int ym = Y.rows();
|
|
|
|
|
+ const int yn = Y.cols();
|
|
|
assert(R.minCoeff() >= 0);
|
|
assert(R.minCoeff() >= 0);
|
|
|
assert(R.maxCoeff() < ym);
|
|
assert(R.maxCoeff() < ym);
|
|
|
assert(C.minCoeff() >= 0);
|
|
assert(C.minCoeff() >= 0);
|
|
|
assert(C.maxCoeff() < yn);
|
|
assert(C.maxCoeff() < yn);
|
|
|
-#endif
|
|
|
|
|
|
|
|
|
|
// Build reindexing maps for columns and rows, -1 means not in map
|
|
// Build reindexing maps for columns and rows, -1 means not in map
|
|
|
Eigen::Matrix<typename DerivedR::Scalar,Eigen::Dynamic,1> RI;
|
|
Eigen::Matrix<typename DerivedR::Scalar,Eigen::Dynamic,1> RI;
|
|
@@ -128,6 +138,9 @@ IGL_INLINE void igl::slice_into(
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
|
|
|
+// Explicit template instantiation
|
|
|
|
|
+// generated by autoexplicit.sh
|
|
|
|
|
+template void igl::slice_into<double, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<double, 0, int> const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::SparseMatrix<double, 0, int>&);
|
|
|
template void igl::slice_into<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
|
|
template void igl::slice_into<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
|
|
|
template void igl::slice_into<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
|
|
template void igl::slice_into<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
|
|
|
template void igl::slice_into<double, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<double, 0, int> const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::SparseMatrix<double, 0, int>&);
|
|
template void igl::slice_into<double, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::SparseMatrix<double, 0, int> const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::SparseMatrix<double, 0, int>&);
|