getfem-users
[Top][All Lists]
Advanced

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

Re: [Getfem-users] Question about Hadamard product


From: Kayhan Batmanghelich
Subject: Re: [Getfem-users] Question about Hadamard product
Date: Fri, 22 May 2009 15:21:13 -0700 (PDT)

Thank you Yves,

It seems that Hadamrd modules (SHAD, DHAD, CHAD and ZHAD) are available only through one of vendors (SGI SCSL ). I implemented element-wise matrix-matrix multiplication and it apears to me the naivest implementation (below). I don't know how I can improve the performance any better. Please let me knwo if you know you have any idea:

int  gmmElementwiseMatrixMultiply(gmm::dense_matrix<double> *A, gmm::dense_matrix<double> *B, gmm::dense_matrix<double> *C)
{
   typedef  gmm::dense_matrix<double>  MatrixType ;

    unsigned long int A_rows =  gmm::mat_nrows(*A) ;
    unsigned long int A_cols =  gmm::mat_ncols(*A) ;
    unsigned long int B_rows =  gmm::mat_nrows(*B) ;
    unsigned long int B_cols =  gmm::mat_ncols(*B) ;
    unsigned long int C_rows =  gmm::mat_nrows(*C) ;
    unsigned long int C_cols =  gmm::mat_ncols(*C) ;

    if ( (A_cols != B_cols) || (A_rows!=B_rows) || (A_cols != C_cols) ||  (A_rows!=C_rows))
    {
       std::cout << "size of matrices should be the same!!" << std::endl ;
       return 0 ;
    }

    MatrixType::iterator    A_it  ;
    MatrixType::iterator    B_it = B->begin() ;
    MatrixType::iterator    C_it = C->begin() ;


    for (A_it = A->begin() ; A_it < A->end();A_it++)
    {
        (*C_it) = (*A_it)*(*B_it) ;
        C_it++;
        B_it++;
    }


}


Regards,
Kayhan


From: Renard Yves <address@hidden>
To: Kayhan Batmanghelich <address@hidden>; address@hidden
Sent: Friday, May 8, 2009 8:54:07 AM
Subject: Re: [Getfem-users] Question about Hadamard product


Dear Kayhan,

The Hadamard vector product is not implemented in gmm. Of course it should not be difficult to implement it at least for dense vectors. It is similar to a sum of two vectors. The interface with the blas routines (SHAD, DHAD, CHAD and ZHAD) can be made also similarly to the sum of to dense vector (see gmm_blas_interface.h).


Yves.





Kayhan Batmanghelich <address@hidden> a écrit :

> Hello Everybody,
>
> I have a question and I would be thankful if anybody answer:
> Part of my program needs efficient vector element-wise mutiplication. I was wondering whether there is any command/function implemented in gmm or getfem to interface with Hadamard vector product (element-wise vector product) in the blas? If such module does not exist in las or gmm, what is the most efficient way to do that?
>
>
> Regards,
> Kayhan
>
>
>
>





reply via email to

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