OSDN Git Service

new file: Integration/Tomography/Makefile.recent
[eos/hostdependX86LINUX64.git] / util / X86MAC64 / cuda / samples / 6_Advanced / eigenvalues / matlab.h
1 /*
2  * Copyright 1993-2013 NVIDIA Corporation.  All rights reserved.
3  *
4  * Please refer to the NVIDIA end user license agreement (EULA) associated
5  * with this source code for terms and conditions that govern your use of
6  * this software. Any use, reproduction, disclosure, or distribution of
7  * this software and related documentation outside the terms of the EULA
8  * is strictly prohibited.
9  *
10  */
11
12 /* Header for utility functionality.
13 * Host code.
14 */
15
16 #ifndef _MATLAB_H_
17 #define _MATLAB_H_
18
19 // includes, system
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
23 #include <math.h>
24
25 // includes, project
26
27 ///////////////////////////////////////////////////////////////////////////////
28 //! Write a tridiagonal, symmetric matrix in vector representation and
29 //! it's eigenvalues
30 //! @param  filename  name of output file
31 //! @param  d  diagonal entries of the matrix
32 //! @param  s  superdiagonal entries of the matrix (len = n - 1)
33 //! @param  eigenvals  eigenvalues of the matrix
34 //! @param  indices  vector of len n containing the position of the eigenvalues
35 //!                  if these are sorted in ascending order
36 //! @param  n  size of the matrix
37 ///////////////////////////////////////////////////////////////////////////////
38 extern "C"
39 void
40 writeTridiagSymMatlab(const char *filename,
41                       float *d, float *s,
42                       float *eigenvals,
43                       const unsigned int n);
44
45 ///////////////////////////////////////////////////////////////////////////////
46 //! Write matrix to a file in Matlab format
47 //! @param  file  file handle to which to write he matrix
48 //! @param  mat_name  name of matrix in Matlab
49 //! @param  mat  matrix to write to the file
50 //! @param  mat_size  size of the (square) matrix \a mat
51 ///////////////////////////////////////////////////////////////////////////////
52 template<class T, class S>
53 void
54 writeMatrixMatlab(T &file,  const char *mat_name,
55                   S *&mat, const unsigned int mat_size);
56
57 ///////////////////////////////////////////////////////////////////////////////
58 //! Write vector to a file in Matlab format
59 //! @param  file  file handle to which to write he matrix
60 //! @param  vec_name  name of vector in Matlab
61 //! @param  vec  matrix to write to the file
62 //! @param  vec_len  length of the vector
63 ///////////////////////////////////////////////////////////////////////////////
64 template<class T, class S>
65 void
66 writeVectorMatlab(T &file,  const char *vec_name,
67                   S *&vec, const unsigned int vec_len);
68
69 // implementations
70
71 ///////////////////////////////////////////////////////////////////////////////
72 //! Write matrix to a file in Matlab format
73 //! @param  file  file handle to which to write he matrix
74 //! @param  mat_name  name of matrix in Matlab
75 //! @param  mat  matrix to write to the file
76 //! @param  mat_size  size of the (square) matrix \a mat
77 ///////////////////////////////////////////////////////////////////////////////
78 template<class T, class S>
79 void
80 writeMatrixMatlab(T &file,  const char *mat_name,
81                   S *&mat, const unsigned int mat_size)
82 {
83
84     const unsigned int pitch = sizeof(S) * mat_size;
85
86     file << mat_name << " = [";
87
88     for (unsigned int i = 0; i < mat_size; ++i)
89     {
90         for (unsigned int j = 0; j < mat_size; ++j)
91         {
92
93             file << getMatrix(mat, pitch, i, j)  << " ";
94         }
95
96         if (i != mat_size - 1)
97         {
98             file << "; ";
99         }
100     }
101
102     file << "];\n";
103 }
104
105 ///////////////////////////////////////////////////////////////////////////////
106 //! Write vector to a file in Matlab format
107 //! @param  file  file handle to which to write he matrix
108 //! @param  vec_name  name of vector in Matlab
109 //! @param  vec  matrix to write to the file
110 //! @param  vec_len  length of the vector
111 ///////////////////////////////////////////////////////////////////////////////
112 template<class T, class S>
113 void
114 writeVectorMatlab(T &file,  const char *vec_name,
115                   S *&vec, const unsigned int vec_len)
116 {
117     file << vec_name << " = [";
118
119     for (unsigned int i = 0; i < vec_len; ++i)
120     {
121         file << vec[i] << " ";
122     }
123
124     file << "];\n";
125 }
126
127 #endif // _MATLAB_H_
128
129