/usr/include/fflas-ffpack/fflas/fflas_fger.inl is in fflas-ffpack-common 2.2.2-4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | /* -*- mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
// vim:sts=8:sw=8:ts=8:noet:sr:cino=>s,f0,{0,g0,(0,\:0,t0,+0,=s
/* fflas/fflas_fger.inl
* Copyright (C) 2005 Clement Pernet
*
* Written by Clement Pernet <Clement.Pernet@imag.fr>
*
*
* ========LICENCE========
* This file is part of the library FFLAS-FFPACK.
*
* FFLAS-FFPACK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* ========LICENCE========
*.
*/
#ifndef __FFLASFFPACK_fger_INL
#define __FFLASFFPACK_fger_INL
namespace FFLAS {
template<class Field>
inline void
fger (const Field& F, const size_t M, const size_t N,
const typename Field::Element alpha,
typename Field::ConstElement_ptr x, const size_t incx,
typename Field::ConstElement_ptr y, const size_t incy,
typename Field::Element_ptr A, const size_t lda)
{
MMHelper<Field, MMHelperAlgo::Classic> H(F,0);
fger (F, M, N, alpha, x, incx, y, incy, A, lda, H);
freduce (F, M, N, A, lda);
}
} //FFLAS
namespace FFLAS { namespace Protected {
template<class FloatElement, class Field>
inline void
fger_convert (const Field& F, const size_t M, const size_t N,
const typename Field::Element alpha,
typename Field::ConstElement_ptr x, const size_t incx,
typename Field::ConstElement_ptr y, const size_t incy,
typename Field::Element_ptr A, const size_t lda)
{
Givaro::ModularBalanced<FloatElement> G((FloatElement) F.characteristic());
FloatElement alphaf;
F.convert (alphaf, alpha);
FloatElement* Af = fflas_new (G,M,N);
FloatElement* Xf = fflas_new (G,M,1);
FloatElement* Yf = fflas_new (G,N,1);
fconvert(F, M, N, Af, N, A, lda);
freduce(G, M, N, Af, N);
fconvert(F, M, Xf, 1, x, incx);
freduce(G, M, Xf, 1);
fconvert(F, N, Yf, 1, y, incy);
freduce(G, N, Yf, 1);
fger (G, M, N, alphaf, Xf, 1, Yf, 1, Af, N);
finit (F, M, N, Af, N, A, lda);
fflas_delete (Af);
fflas_delete (Xf);
fflas_delete (Yf);
}
}// Protected
}// FFLAS
namespace FFLAS{
template<class Field>
inline void
fger (const Field& F, const size_t M, const size_t N,
const typename Field::Element alpha,
typename Field::ConstElement_ptr x, const size_t incx,
typename Field::ConstElement_ptr y, const size_t incy,
typename Field::Element_ptr A, const size_t lda,
MMHelper<Field, MMHelperAlgo::Classic, ModeCategories::ConvertTo<ElementCategories::MachineFloatTag> > & H)
{
if (F.isZero(alpha)) { return ; }
if (F.cardinality() < DOUBLE_TO_FLOAT_CROSSOVER){
return Protected::fger_convert<float,Field>(F,M,N,alpha,x, incx, y,incy, A, lda);
} else if (16*F.cardinality() < Givaro::ModularBalanced<double>::maxCardinality()){
return Protected::fger_convert<double,Field>(F,M,N,alpha,x, incx, y,incy, A, lda);
} else {
FFPACK::failure()(__func__,__LINE__,"Invalid ConvertTo Mode for this field");
}
}
template<class Field>
inline void
fger (const Field& F, const size_t M, const size_t N,
const typename Field::Element alpha,
typename Field::ConstElement_ptr x, const size_t incx,
typename Field::ConstElement_ptr y, const size_t incy,
typename Field::Element_ptr A, const size_t lda,
MMHelper<Field, MMHelperAlgo::Classic, ModeCategories::DefaultTag> & H)
{
if (F.isZero(alpha)) { return ; }
typename Field::Element tmp;
typename Field::ConstElement_ptr xi=x, yj=y;
typename Field::Element_ptr Ai=A;
if ( M < N ){
if ( F.isOne( alpha ) )
for ( ; Ai < A+M*lda; Ai+=lda, xi+=incx ){
yj = y;
for (size_t j = 0; j < N; ++j, yj+=incy )
F.axpyin( *(Ai+j), *xi, *yj );
}
else if ( F.isMOne( alpha ) )
for ( ; Ai < A+M*lda; Ai+=lda, xi+=incx ){
F.neg( tmp, *xi );
yj = y;
for (size_t j = 0; j < N; ++j, yj+=incy )
F.axpyin( *(Ai+j), tmp, *yj );
}
else
for ( ; Ai < A+M*lda; Ai+=lda, xi+=incx ){
F.mul( tmp, alpha, *xi );
yj = y;
for (size_t j = 0; j < N; ++j, yj+=incy )
F.axpyin( *(Ai+j), tmp, *yj );
}
} else {
if ( F.isOne( alpha ) ){
for ( ; Ai < A+N; ++Ai, yj+=incy ){
xi = x;
for (size_t i = 0; i < M; ++i, xi+=incx )
F.axpyin( *(Ai+i*lda), *xi, *yj );
}
}
else if ( F.isMOne( alpha ) )
for ( ; Ai < A+N; ++Ai, yj+=incy ){
F.neg( tmp, *yj );
xi = x;
for (size_t i = 0; i < M; ++i, xi+=incx )
F.axpyin( *(Ai+i*lda), *xi, tmp );
}
else
for ( ; Ai < A+N; ++Ai, yj+=incy ){
F.mul( tmp, alpha, *yj );
xi = x;
for (size_t i = 0; i < M; ++i, xi+=incx )
F.axpyin( *(Ai+i*lda), *xi, tmp );
}
}
}
inline void
fger( const Givaro::DoubleDomain& F, const size_t M, const size_t N,
const Givaro::DoubleDomain::Element alpha,
const Givaro::DoubleDomain::ConstElement_ptr x, const size_t incx,
const Givaro::DoubleDomain::ConstElement_ptr y, const size_t incy,
Givaro::DoubleDomain::Element_ptr A, const size_t lda,
MMHelper<Givaro::DoubleDomain, MMHelperAlgo::Classic, ModeCategories::DefaultTag> & H)
{
if (F.isZero(alpha)) { return ; }
FFLASFFPACK_check(lda);
cblas_dger( CblasRowMajor, (int)M, (int)N, alpha, x, (int)incx, y, (int)incy, A, (int)lda );
}
template<class Field>
inline void
fger(const Field& F, const size_t M, const size_t N,
const typename Field::Element alpha,
const typename Field::ConstElement_ptr x, const size_t incx,
const typename Field::ConstElement_ptr y, const size_t incy,
typename Field::Element_ptr A, const size_t lda,
MMHelper<Field, MMHelperAlgo::Classic, ModeCategories::DefaultBoundedTag> & H)
{
H.setOutBounds (1, alpha, 1.0);
MMHelper<Field, MMHelperAlgo::Classic, ModeCategories::DefaultTag> Hd(F,0);
fger (F, M, N, alpha, x, incx, y, incy, A, lda, Hd);
}
inline void
fger( const Givaro::FloatDomain& F, const size_t M, const size_t N,
const Givaro::FloatDomain::Element alpha,
const Givaro::FloatDomain::ConstElement_ptr x, const size_t incx,
const Givaro::FloatDomain::ConstElement_ptr y, const size_t incy,
Givaro::FloatDomain::Element_ptr A, const size_t lda,
MMHelper<Givaro::FloatDomain, MMHelperAlgo::Classic, ModeCategories::DefaultTag> & H)
{
if (F.isZero(alpha)) { return ; }
FFLASFFPACK_check(lda);
cblas_sger( CblasRowMajor, (int)M, (int)N, alpha, x, (int)incx, y, (int)incy, A, (int)lda );
}
template<class Field>
inline void
fger (const Field& F, const size_t M, const size_t N,
const typename Field::Element alpha,
typename Field::ConstElement_ptr x, const size_t incx,
typename Field::ConstElement_ptr y, const size_t incy,
typename Field::Element_ptr A, const size_t lda,
MMHelper<Field, MMHelperAlgo::Classic, ModeCategories::LazyTag> & H)
{
if (F.isZero(alpha)) { return ; }
typedef MMHelper<Field, MMHelperAlgo::Classic, ModeCategories::LazyTag> HelperType;
typedef typename HelperType::DelayedField delayedField;
typedef typename HelperType::DelayedField::Element DFElt;
typedef typename HelperType::DelayedField::ConstElement_ptr DFCElt_ptr;
typedef typename HelperType::DelayedField::Element_ptr DFElt_ptr;
typedef typename Field::Element Element;
typedef typename Field::Element_ptr Element_ptr;
typedef MMHelper<delayedField, MMHelperAlgo::Classic, ModeCategories::DefaultBoundedTag> DelayedHelperType;
DelayedHelperType Hfp(H);
if (Hfp.MaxDelayedDim(1.0) < 1){
if (Hfp.Amin < H.FieldMin || Hfp.Amax>H.FieldMax){
Hfp.initA();
freduce_constoverride (F, M, x, incx);
}
if (Hfp.Bmin < H.FieldMin || Hfp.Bmax>H.FieldMax){
Hfp.initB();
freduce_constoverride (F, N, y, incy);
}
if (Hfp.Cmin < H.FieldMin || Hfp.Cmax>H.FieldMax){
Hfp.initC();
freduce (F, M, N, A, lda);
}
}
Hfp.Outmin = Hfp.FieldMin;
Hfp.Outmax = Hfp.FieldMax;
if (F.isOne(alpha) || F.isMOne(alpha)){
DFElt alphadf;
if (F.isMOne( alpha)) alphadf = -F.one;
else alphadf = F.one;
fger (H.delayedField, M, N, alphadf, (DFCElt_ptr)x, incx, (DFCElt_ptr)y, incy, (DFElt_ptr)A, lda, Hfp);
H.Outmin = Hfp.Outmin;
H.Outmax = Hfp.Outmax;
} else {
Element_ptr sY = FFLAS::fflas_new<Element> (N);
fscal(F, N, alpha, y, incy, sY, 1);
fger (H.delayedField, M, N, 1.0, (DFCElt_ptr)x, incx, (DFCElt_ptr) sY, 1, (DFElt_ptr)A, lda, Hfp);
FFLAS::fflas_delete(sY);
H.setOutBounds (1, alpha, 1.0);
}
}
template<class Field>
inline void
fger (const Field& F, const size_t M, const size_t N,
const typename Field::Element alpha,
typename Field::ConstElement_ptr x, const size_t incx,
typename Field::ConstElement_ptr y, const size_t incy,
typename Field::Element_ptr A, const size_t lda,
MMHelper<Field, MMHelperAlgo::Classic, ModeCategories::DelayedTag> & H)
{
if (F.isZero(alpha)) { return ; }
if (Protected::AreEqual<Field, Givaro::Modular<int64_t> >::value ||
Protected::AreEqual<Field, Givaro::ModularBalanced<int64_t> >::value){
if (F.cardinality() < Givaro::ModularBalanced<double>::maxCardinality())
return Protected::fger_convert<double,Field>(F,M,N,alpha,x,incx,y,incy, A,lda);
else{
// Stay over int64_t
MMHelper<Field, MMHelperAlgo::Classic, ModeCategories::LazyTag, ParSeqHelper::Sequential> HG(H);
HG.recLevel = 0;
fgemm(F,FflasNoTrans,FflasNoTrans,M,N,1,alpha,x,incx,y,incy,F.one,A,lda,HG);
freduce(F,M,N,A,lda);
H.initOut();
return;
}
}
typedef MMHelper<Field, MMHelperAlgo::Classic, ModeCategories::DelayedTag> ModularHelperType;
typedef typename ModularHelperType::DelayedField delayedField;
typedef typename delayedField::Element DFElt;
typedef typename delayedField::ConstElement_ptr DFCElt_ptr;
typedef typename delayedField::Element_ptr DFElt_ptr;
typedef typename Field::Element Element;
typedef typename Field::Element_ptr Element_ptr;
typedef MMHelper<delayedField, MMHelperAlgo::Classic, ModeCategories::DefaultBoundedTag> DelayedHelperType;
DelayedHelperType Hfp(H);
if (F.isOne(alpha) || F.isMOne(alpha)){
DFElt alphadf;
if (F.isMOne( alpha)) alphadf = -F.one;
else alphadf = F.one;
fger (H.delayedField, M, N, alphadf, (DFCElt_ptr)x, incx, (DFCElt_ptr)y, incy, (DFElt_ptr)A, lda, Hfp);
} else {
Element_ptr sY = FFLAS::fflas_new<Element> (N);
fscal(F, N, alpha, y, incy, sY, 1);
fger (H.delayedField, M, N, H.delayedField.one, (DFCElt_ptr)x, incx, (DFCElt_ptr)sY, (size_t)1, (DFElt_ptr)A, lda, Hfp);
FFLAS::fflas_delete(sY);
}
H.initOut();
}
} // FFLAS
//#include "fflas-ffpack/fflas/fflas_fger_mp.inl" moved to fflas.h
#endif // __FFLASFFPACK_fger_INL
|