diff options
author | Abhinav Dronamraju | 2017-07-10 22:08:27 +0530 |
---|---|---|
committer | Abhinav Dronamraju | 2017-07-10 22:08:27 +0530 |
commit | d2c00f5343785085bcfefb62cbc041a5cffa8f31 (patch) | |
tree | 3d4fc371c30f2340af2def6dcabeb4fd4821eaf8 /src/c/linearAlgebra/rowcomp/drowcompa.c | |
parent | c7d123014c05daaa6c7ce32bc5e86e5f3e7e4692 (diff) | |
parent | 49d8281d2da2f4c6bf0e62d148a8a7328d3bf970 (diff) | |
download | Scilab2C_fossee_old-d2c00f5343785085bcfefb62cbc041a5cffa8f31.tar.gz Scilab2C_fossee_old-d2c00f5343785085bcfefb62cbc041a5cffa8f31.tar.bz2 Scilab2C_fossee_old-d2c00f5343785085bcfefb62cbc041a5cffa8f31.zip |
Pulled from upstream master
Diffstat (limited to 'src/c/linearAlgebra/rowcomp/drowcompa.c')
-rw-r--r-- | src/c/linearAlgebra/rowcomp/drowcompa.c | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/src/c/linearAlgebra/rowcomp/drowcompa.c b/src/c/linearAlgebra/rowcomp/drowcompa.c new file mode 100644 index 0000000..3161a2d --- /dev/null +++ b/src/c/linearAlgebra/rowcomp/drowcompa.c @@ -0,0 +1,79 @@ +/* Copyright (C) 2017 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Sandeep Gupta + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in + */ + +/* This function is used to find row compression, range */ + +#include "rowcomp.h" +#include <stdio.h> +#include <stdlib.h> +#include <math.h> +#include "svd.h" +#include "norm.h" +#include "eye.h" +#include "matrixTranspose.h" +#include "qr.h" + +/* All variable names, are in consideration of scilab documentation. for reference please check the scilab code.*/ + +double drowcompa(int ninp,double *A,int row,int col,char *flag,double tol,double *w){ + double rk; + double *U; + double *S; + double *V; + double *q,*r,*e; + if(row == 0 || col == 0){ + w = NULL; + return 0; + } + + double nA1 = dnorma(A,row,col,1); + if(nA1 < sqrt(pow(2,-52))/10){ + deyea(w,row,col); + return 0; + } + if(ninp == 1){ + flag = "svd"; + tol = sqrt(pow(2,-52))*nA1; + } + else if(ninp == 2){ + tol = sqrt(pow(2,-52))*nA1; + } + else{ + if(tol < 0){ /* if tolerance is negative */ + printf(" Wrong values for input argument #: Non-negative scalar expected"); + } + } + int M = row,N=col; + int minMN = min(M,N); + char check[3]="qr"; + //printf(" %s ",flag); + if(strcmp(check,flag) == 0){ + /* calling qr function*/ + //printf(" * "); + q = (double *)malloc(M*min(M,N)*sizeof(double)); + r = (double *)malloc(minMN*N*sizeof(double)); + e = (double *)malloc(N*N*sizeof(double)); + rk = dqra(2,4,A,M,N,tol,q,r,e); + memcpy(w,q,row*col*sizeof(double)); + dtransposea(q,row,row,w); + return rk; + } + else{ + /* svd function type */ + U = (double *)malloc(row*row*sizeof(double)); + S = (double *)malloc(row*col*sizeof(double)); + V = (double *)malloc(col*col*sizeof(double)); + rk = dsvda(tol,A,row,col,0,4,U,S,V); + dtransposea(U,row,row,w); + return rk; + } +} |