/************************************************************************* * * * Vega FEM Simulation Library Version 3.1 * * * * "matrix" library , Copyright (C) 2007 CMU, 2009 MIT * * All rights reserved. * * * * Code author: Jernej Barbic * * http://www.jernejbarbic.com/code * * Research: Jernej Barbic, Doug L. James, Jovan Popovic * * Funding: NSF, Link Foundation, Singapore-MIT GAMBIT Game Lab * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the BSD-style license that is * * included with this library in the file LICENSE.txt * * * * 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 file * * LICENSE.TXT for more details. * * * *************************************************************************/ #include #include #include #include #define CBLAS #ifdef CBLAS #include "lapack-headers.h" #endif #include "matrixIO.h" #include "matrixMacros.h" #include "matrixProjection.h" #ifdef CBLAS // if-then-else template choosing template class _cblas_xgemv {}; template<> class _cblas_xgemv { public: inline static void f (const CBLAS_ORDER order, const CBLAS_TRANSPOSE trans, const int m, const int n, const float alpha, const float * a, const int lda, const float * x, const int incx, float beta, float * y, const int incy) { cblas_sgemv(order, trans, m, n, alpha, a, lda, x, incx, beta, y, incy);} }; template<> class _cblas_xgemv { public: inline static void f (const CBLAS_ORDER order, const CBLAS_TRANSPOSE trans, const int m, const int n, const double alpha, const double * a, const int lda, const double * x, const int incx, double beta, double * y, const int incy) { cblas_dgemv(order, trans, m, n, alpha, a, lda, x, incx, beta, y, incy);} }; #endif // construct vector f, using the equation f = U q // matrix U is of size n x r, and is given in the column-major order // vector q is of length r // vector f is of length n template void SynthesizeVector(int n_inp, int r_inp, real * U_inp, real * q_inp, real * f_inp) { #ifdef CBLAS CBLAS_ORDER order= CblasColMajor; CBLAS_TRANSPOSE trans= CblasNoTrans; int m = n_inp; int n = r_inp; real alpha = 1; real * a = U_inp; int lda = m; real * x = q_inp; int incx = 1; real beta = 0; real * y = f_inp; // holds the result int incy = 1; _cblas_xgemv::f(order, trans, m, n, alpha, a, lda, x, incx, beta, y, incy); #else int i,j; for (i=0; i void SynthesizeSparseVector(int n, int r, real * U, real * q, real * f, int * i_buffer, int k) { int i,j; for (i=0; i void ProjectVector(int n_inp, int r_inp, real * U_inp, real * q_inp, real * f_inp) { // has to make inner product of vector f will all the columns of U // i.e. multiply U^T * f = q #ifdef CBLAS CBLAS_ORDER order= CblasColMajor; CBLAS_TRANSPOSE trans= CblasTrans; int m = n_inp; int n = r_inp; real alpha = 1; real * a = U_inp; int lda = m; real * x = f_inp; int incx = 1; real beta = 0; real * y = q_inp; // will hold the result int incy = 1; _cblas_xgemv::f(order, trans, m, n, alpha, a, lda, x, incx, beta, y, incy); #else int i,j; for (j=0; j void ProjectSparseVector(int n, int r, real * U, real * q, real * f_buffer, int * i_buffer, int k) { // has to make inner product of vector f will all the columns of U int i,j; for (j=0; j(int n, int r, double * U, double * q, double * f); template void SynthesizeVector(int n, int r, float * U, float * q, float * f); template void SynthesizeSparseVector(int n, int r, double * U, double * q, double * f, int * i_buffer, int k); template void SynthesizeSparseVector(int n, int r, float * U, float * q, float * f, int * i_buffer, int k); template void ProjectVector(int n, int r, double * U, double * q, double * f); template void ProjectVector(int n, int r, float * U, float * q, float * f); template void ProjectSparseVector(int n, int r, double * U, double * q, double * f_buffer, int * i_buffer, int k); template void ProjectSparseVector(int n, int r, float * U, float * q, float * f_buffer, int * i_buffer, int k);