[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Getfem-commits] (no subject)
From: |
Yves Renard |
Subject: |
[Getfem-commits] (no subject) |
Date: |
Thu, 22 Feb 2018 07:16:16 -0500 (EST) |
branch: master
commit e5587d5a0a65d4d057861a623016cfc480cc08ca
Author: Yves Renard <address@hidden>
Date: Thu Feb 22 13:16:00 2018 +0100
simplifaction for access to a component of a sparse matrix in the interface
---
interface/src/gf_spmat_get.cc | 42 ++++++++++++++++++++++++++++++++----------
1 file changed, 32 insertions(+), 10 deletions(-)
diff --git a/interface/src/gf_spmat_get.cc b/interface/src/gf_spmat_get.cc
index fa5b664..8520307 100644
--- a/interface/src/gf_spmat_get.cc
+++ b/interface/src/gf_spmat_get.cc
@@ -43,29 +43,51 @@ void copydiags(const MAT &M, const std::vector<size_type>
&v,
template <typename T> static void
gf_spmat_get_full(gsparse &gsp, getfemint::mexargs_in& in,
getfemint::mexargs_out& out, T) {
- gmm::dense_matrix<T> ww;
size_type n,m;
if (!in.remaining()) {
m = gsp.nrows(); n = gsp.ncols();
- gmm::resize(ww, m, n);
+ gmm::dense_matrix<T> ww(m,n);
switch (gsp.storage()) {
case gsparse::CSCMAT: gmm::copy(gsp.csc(T()), ww); break;
case gsparse::WSCMAT: gmm::copy(gsp.wsc(T()), ww); break;
default: THROW_INTERNAL_ERROR;
}
+ std::copy(ww.begin(), ww.end(),
+ out.pop().create_array(int(m),int(n),T()).begin());
} else {
sub_index ii = in.pop().to_sub_index().check_range(gsp.nrows());
sub_index jj = in.remaining() ?
- in.pop().to_sub_index().check_range(gsp.ncols()) :
ii.check_range(gsp.ncols());
+ in.pop().to_sub_index().check_range(gsp.ncols())
+ : ii.check_range(gsp.ncols());
m = ii.size(); n = jj.size();
- gmm::resize(ww, m, n);
- switch (gsp.storage()) {
- case gsparse::CSCMAT: gmm::copy(gmm::sub_matrix(gsp.csc(T()),ii,jj), ww);
break;
- case gsparse::WSCMAT: gmm::copy(gmm::sub_matrix(gsp.wsc(T()),ii,jj), ww);
break;
- default: THROW_INTERNAL_ERROR;
+ if (m == 1 && n == 1) {
+ T val = T(0);
+ switch (gsp.storage()) {
+ case gsparse::CSCMAT: val = gsp.csc(T())(ii.first(), jj.first()); break;
+ case gsparse::WSCMAT: val = gsp.wsc(T()).col(jj.first()).r(ii.first());
break;
+ default: THROW_INTERNAL_ERROR;
+ }
+ if (gsp.is_complex()) {
+ if (out.remaining()) out.pop().from_scalar(gmm::real(val));
+ if (out.remaining()) out.pop().from_scalar(gmm::imag(val));
+ } else {
+ if (out.remaining()) out.pop().from_scalar(gmm::real(val));
+ // if (out.remaining()) out.pop().from_scalar(0);
+ }
+ } else {
+ gmm::dense_matrix<T> ww(m,n);
+ switch (gsp.storage()) {
+ case gsparse::CSCMAT:
+ gmm::copy(gmm::sub_matrix(gsp.csc(T()),ii,jj), ww); break;
+ case gsparse::WSCMAT:
+ gmm::copy(gmm::sub_matrix(gsp.wsc(T()),ii,jj), ww); break;
+ default: THROW_INTERNAL_ERROR;
+ }
+ std::copy(ww.begin(), ww.end(),
+ out.pop().create_array(int(m),int(n),T()).begin());
}
}
- std::copy(ww.begin(), ww.end(),
out.pop().create_array(int(m),int(n),T()).begin());
+
}
template <typename T> static void
@@ -203,7 +225,7 @@ void gf_spmat_get(getfemint::mexargs_in& m_in,
sub_command
("full", 0, 2, 0, 1,
if (gsp.is_complex()) gf_spmat_get_full(gsp, in, out, complex_type());
- else gf_spmat_get_full(gsp, in,out,scalar_type());
+ else gf_spmat_get_full(gsp, in, out, scalar_type());
);