getfem-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Getfem-users] a matrix question on gmm++


From: Yves Renard
Subject: Re: [Getfem-users] a matrix question on gmm++
Date: Fri, 15 Jan 2010 12:32:51 +0100
User-agent: KMail/1.9.9


Dear Umut,

You have to iterate on the columns (because it is a column matrix) and then on 
the non-zero elements. Unforutnately, this is not documented, but you can 
find many examples in the file gmm_blas.h. The better is to use some template 
function not to have to deal with the particular types of iterator used by 
the matrix type. For instance the code which compute the euclidean 
(froebenius) norm of a column matrix is the following :

template <typename M>
   typename number_traits<typename linalg_traits<M>::value_type>
   ::magnitude_type
   mat_euclidean_norm_sqr(const M &m, col_major) {
    typename number_traits<typename linalg_traits<M>::value_type>
      ::magnitude_type res(0);

    for (size_type i = 0; i < mat_ncols(m); ++i)
      res += vect_norm2_sqr(mat_const_col(m, i));
    return res;
  }


Yves.


On jeudi 14 janvier 2010, Umut Tabak wrote:
> Dear all,
>
> I was trying to use gmm++ library to interface some of my matrices that
> are exported from a commercial FE code. I have these matrices in matrix
> market format and thanks to the gmm++ library that you can directly
> interface this matrix into csr matrix with the code below:
>
> #include <iostream>
> #include <gmm/gmm.h>
> #include <gmm/gmm_inoutput.h>
> #include <gmm/gmm_def.h>
>
> int main()
> {
>   gmm::col_matrix< gmm::wsvector<double> > M1;  // M1
>   MatrixMarket_load("mm5by5.mm", M1);
>   gmm::csr_matrix<double> M2;
>   gmm::copy(M1, M2);                            // M1 -> M2
>   // output the vector
>   std::cout << M2 << std::endl;
>   std::cout << "Number of nonzeros: " << gmm::nnz(M2) << std::endl;
>   //
>   for(int i=0;i<5;++i)
>     std::cout << gmm::mat_row(M2,i) << std::endl;
>   //
>



>
>   return 0;
> }
>
> What I would like to do is to iterate over the non-zero on each row in a
> loop. I can see that standard output is overloaded for
>
> std::cout << gmm::mat_row(M2,i) << std::endl;
>
> which results in
>
> vector(5) [ (r0,1) (r3,6) ]
> vector(5) [ (r1,10.5) ]
> vector(5) [ (r2,0.015) ]
> vector(5) [ (r1,250.5) (r3,-280) (r4,33.32) ]
> vector(5) [ (r4,12) ]
>
> How can I reach these non zeros elements in my matrix, I am a bit
> confused, I read the deeper inside gmm++ section but could not find my
> way there?
>
>
> Any pointers are appreciated.
>
> Umut
>
> _______________________________________________
> Getfem-users mailing list
> address@hidden
> https://mail.gna.org/listinfo/getfem-users



-- 

  Yves Renard (address@hidden)       tel : (33) 04.72.43.87.08
  Pole de Mathematiques, INSA-Lyon             fax : (33) 04.72.43.85.29
  20, rue Albert Einstein
  69621 Villeurbanne Cedex, FRANCE
  http://math.univ-lyon1.fr/~renard

---------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]