1/*
2 * Copyright (C) 2014 FFLAS-FFPACK group
3 *
4 * Written by Pascal Giorgi <pascal.giorgi@lirmm.fr>
5 *
6 *
7 * ========LICENCE========
8 * This file is part of the library FFLAS-FFPACK.
9 *
10 * FFLAS-FFPACK is free software: you can redistribute it and/or modify
11 * it under the terms of the  GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 * ========LICENCE========
24 *.
25 */
26
27#ifndef __FFLASFFPACK_fgemv_mp_INL
28#define __FFLASFFPACK_fgemv_mp_INL
29
30#include "fflas-ffpack/field/rns-integer-mod.h"
31
32namespace FFLAS {
33
34
35    // specialization of the fgemv function for the field RNSInteger<rns_double>
36    inline FFPACK::rns_double::Element_ptr
37    fgemv (const FFPACK::RNSInteger<FFPACK::rns_double>& F, const FFLAS_TRANSPOSE ta,
38           const size_t M, const size_t N,
39           const FFPACK::rns_double::Element alpha,
40           FFPACK::rns_double::ConstElement_ptr A, const size_t lda,
41           FFPACK::rns_double::ConstElement_ptr X, const size_t incX,
42           const FFPACK::rns_double::Element beta,
43           FFPACK::rns_double::Element_ptr Y, const size_t incY,
44           MMHelper<FFPACK::RNSInteger<FFPACK::rns_double>, MMHelperAlgo::Classic, ModeCategories::DefaultTag> & H)
45    {
46        if (M!=0 && N !=0){
47            for (size_t i=0;i<F.size();i++)
48                fgemv(F.rns()._field_rns[i], ta,
49                      M, N,
50                      alpha._ptr[i*alpha._stride],
51                      A._ptr+i*A._stride, lda,
52                      X._ptr+i*X._stride, incX,
53                      beta._ptr[i*beta._stride],
54                      Y._ptr+i*Y._stride, incY
55                     );
56        }
57        return Y;
58    }
59
60
61    // specialization of the fgemv function for the field RNSIntegerMod<rns_double>
62    inline FFPACK::rns_double::Element_ptr
63    fgemv (const FFPACK::RNSIntegerMod<FFPACK::rns_double>& F, const FFLAS_TRANSPOSE ta,
64           const size_t M, const size_t N,
65           const FFPACK::rns_double::Element alpha,
66           FFPACK::rns_double::ConstElement_ptr A, const size_t lda,
67           FFPACK::rns_double::ConstElement_ptr X, const size_t incX,
68           const FFPACK::rns_double::Element beta,
69           FFPACK::rns_double::Element_ptr Y, const size_t incY,
70           MMHelper<FFPACK::RNSIntegerMod<FFPACK::rns_double>, MMHelperAlgo::Classic, ModeCategories::DefaultTag> & H)
71    {
72        //std::cout<<"HERE 1"<<std::endl;
73        MMHelper<FFPACK::RNSInteger<FFPACK::rns_double>, MMHelperAlgo::Classic, ModeCategories::DefaultTag >  H2;
74        //std::cout<<"HERE 2"<<std::endl;
75        fgemv(F.delayed(),ta,M,N,alpha,A,lda,X,incX, beta,Y,incY,H2);
76        //std::cout<<"HERE 3"<<std::endl;
77        size_t Ydim = (ta == FflasNoTrans)?M:N;
78        freduce (F, Ydim, Y, incY);
79        return Y;
80    }
81
82
83    // BB hack. might not work.
84    // Calling fgemm, TODO: really specialize fgemv
85    // specialization of the fgemv function for the field Givaro::ZRing<Givaro::Integer>
86    inline Givaro::Integer* fgemv (const Givaro::ZRing<Givaro::Integer>& F,
87                                   const FFLAS_TRANSPOSE ta,
88                                   const size_t m, const size_t n,
89                                   const Givaro::Integer alpha,
90                                   Givaro::Integer* A, const size_t lda,
91                                   Givaro::Integer* X, const size_t ldx,
92                                   Givaro::Integer beta,
93                                   Givaro::Integer* Y, const size_t ldy,
94                                   MMHelper<Givaro::ZRing<Givaro::Integer>, MMHelperAlgo::Classic, ModeCategories::ConvertTo<ElementCategories::RNSElementTag> > & H)
95    {
96        MMHelper<Givaro::ZRing<Givaro::Integer>, MMHelperAlgo::Classic, ModeCategories::ConvertTo<ElementCategories::RNSElementTag>, ParSeqHelper::Sequential> H2;
97        fgemm(F,ta,FFLAS::FflasNoTrans, (ta==FFLAS::FflasNoTrans)?m:n, 1,(ta==FFLAS::FflasNoTrans)?n:m, alpha,A,lda,X,ldx,beta,Y,ldy,H2);
98        return Y;
99    }
100
101    // specialization of the fgemv function for the field Givaro::Modular<Givaro::Integer>
102    // Calling fgemm, TODO: really specialize fgemv
103    inline Givaro::Integer* fgemv (const Givaro::Modular<Givaro::Integer>& F,
104                                   const FFLAS_TRANSPOSE ta,
105                                   const size_t m, const size_t n,
106                                   const Givaro::Integer alpha,
107                                   Givaro::Integer* A, const size_t lda,
108                                   Givaro::Integer* X, const size_t ldx,
109                                   Givaro::Integer beta,
110                                   Givaro::Integer* Y, const size_t ldy,
111                                   MMHelper<Givaro::Modular<Givaro::Integer>, MMHelperAlgo::Classic, ModeCategories::ConvertTo<ElementCategories::RNSElementTag> > & H)
112    {
113        MMHelper<Givaro::Modular<Givaro::Integer>, MMHelperAlgo::Classic, ModeCategories::ConvertTo<ElementCategories::RNSElementTag>, ParSeqHelper::Sequential> H2;
114        fgemm(F,ta,FFLAS::FflasNoTrans,(ta==FFLAS::FflasNoTrans)?m:n,1,(ta==FFLAS::FflasNoTrans)?n:m,alpha,A,lda,X,ldx,beta,Y,ldy,H2);
115        return Y;
116    }
117
118    // specialization of the fgemv function for the field Givaro::Modular<RecInt::ruint<K>>
119    // Calling fgemm, TODO: really specialize fgemv
120    template <size_t K1, size_t K2, class ParSeq>
121    inline RecInt::ruint<K1>*
122    fgemv (const Givaro::Modular<RecInt::ruint<K1>,RecInt::ruint<K2> >& F,
123           const FFLAS_TRANSPOSE ta,
124           const size_t m, const size_t n,
125           const RecInt::ruint<K1> alpha,
126           const RecInt::ruint<K1>* A, const size_t lda,
127           const RecInt::ruint<K1>* X, const size_t incx,
128           RecInt::ruint<K1> beta,
129           RecInt::ruint<K1>* Y, const size_t incy,
130           MMHelper<Givaro::Modular<RecInt::ruint<K1>,RecInt::ruint<K2> >,
131           MMHelperAlgo::Classic,
132           ModeCategories::ConvertTo<ElementCategories::RNSElementTag>,
133           ParSeq >  & H) {
134        MMHelper<Givaro::Modular<RecInt::ruint<K1>,RecInt::ruint<K2> >, MMHelperAlgo::Classic, ModeCategories::ConvertTo<ElementCategories::RNSElementTag>, ParSeqHelper::Sequential> H2;
135        fgemm (F,ta,FflasNoTrans,(ta==FFLAS::FflasNoTrans)?m:n,1,(ta==FFLAS::FflasNoTrans)?n:m,alpha,A,lda,X,incx,beta,Y,incy,H2);
136        return Y;
137    }
138
139
140} // end namespace FFLAS
141
142#endif
143
144/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
145// vim:sts=4:sw=4:ts=4:et:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
146