test_svd2.c
Go to the documentation of this file.
00001 
00006 /*
00007  Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
00008  All rights reserved.
00009 
00010  This file is part of the VLFeat library and is made available under
00011  the terms of the BSD license (see the COPYING file).
00012  */
00013 
00014 #include <vl/mathop.h>
00015 #include <stdio.h>
00016 
00017 void
00018 print_matrix(char const * name, double *M)
00019 {
00020   printf("%s = \n[ %10f %10f ]\n[ %10f %10f ]\n", name, M[0], M[2], M[1], M[3]) ;
00021 }
00022 
00023 void
00024 prod2 (double R [4], double A [4], double B [4])
00025 {
00026   R[0] = A[0]*B[0] + A[2]*B[1] ;
00027   R[1] = A[1]*B[0] + A[3]*B[1] ;
00028   R[2] = A[0]*B[2] + A[2]*B[3] ;
00029   R[3] = A[1]*B[2] + A[3]*B[3] ;
00030 }
00031 
00032 void
00033 transp2 (double R [4], double A [4])
00034 {
00035   R[0] = A[0] ;
00036   R[1] = A[2] ;
00037   R[2] = A[1] ;
00038   R[3] = A[3] ;
00039 }
00040 
00041 double
00042 det2 (double A [4])
00043 {
00044   return A[0]*A[3] - A[1]*A[2];
00045 }
00046 
00047 void
00048 check_svd (double *M , double * U, double * S, double *V)
00049 {
00050   double T1 [4] ;
00051   double T2 [4] ;
00052 
00053   print_matrix("M",M) ;
00054   print_matrix("U",U) ;
00055   print_matrix("S",S) ;
00056   print_matrix("V",V) ;
00057 
00058   transp2(T1, V) ;
00059   prod2(T2, S, T1) ;
00060   prod2(T1, U, T2) ;
00061   print_matrix("USV'",T1) ;
00062 
00063   transp2(T1, U) ;
00064   prod2(T2, T1, U) ;
00065   print_matrix("U'U",T2) ;
00066 
00067   transp2(T1, V) ;
00068   prod2(T2, T1, V) ;
00069   print_matrix("V'V",T2) ;
00070 
00071   printf("det(M) = %f\n", det2(M)) ;
00072   printf("det(U) = %f\n", det2(U)) ;
00073   printf("det(V) = %f\n", det2(V)) ;
00074   printf("det(S) = %f\n", det2(S)) ;
00075   printf("\n") ;
00076 }
00077 
00078 int
00079 main (int argc VL_UNUSED, char ** argv VL_UNUSED)
00080 {
00081   double M [] = {
00082     0.864397318249258,
00083     0.094202610858281,
00084     -0.851909224508774,
00085     0.873504449150106 } ;
00086   double S [4] ;
00087   double U [4] ;
00088   double V [4] ;
00089 
00090   vl_svd2(S, U, V, M) ;
00091   check_svd(M, U, S, V) ;
00092 
00093   M[1] = 0 ;
00094 
00095   vl_svd2(S, U, V, M) ;
00096   check_svd(M, U, S, V) ;
00097 
00098   vl_lapack_dlasv2(S+3, S,
00099                    V+1, V,
00100                    U+1, U,
00101                    M[0], M[2], M[3]) ;
00102   V[2] = -V[1] ;
00103   V[3] = V[0] ;
00104   U[2] = -U[1] ;
00105   U[3] = U[0] ;
00106   check_svd(M, U, S, V) ;
00107   return 0 ;
00108 }


libvlfeat
Author(s): Andrea Vedaldi
autogenerated on Thu Jun 6 2019 20:25:51