cta_usr_matrix.h

Go to the documentation of this file.
00001 /*
00002 COSTA: Problem solving environment for data assimilation
00003 Copyright (C) 2005  Nils van Velzen
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 /**
00021 \file  cta_usr_matrix.h
00022 
00023 \brief In this file a description is given of the interface of user matrix functions.
00024 When creating your own user matrix class use the following as template.
00025 
00026 The Usr_Matrix to which is being referred in this template can be substituted by your own user matrix.
00027 
00028 <b>Step 1</b>: for creating your own user matrix class call the function CTA_Matrix_DefineClass().
00029 
00030 Example:
00031 
00032 \code
00033 typedef CTA_Handle CTA_MatrixClass;
00034 
00035 CTA_Func h_func[CTA_MATRIX_NUMFUNC];
00036 CTA_MatrixClass my_own_matrix_class;
00037 
00038 ierr=CTA_Func_Create(" ",&usr_matrix_create_size, hintf, &h_func[CTA_MATRIX_CREATE_SIZE]);
00039 //...for all implementation functions...
00040 
00041 CTA_Matrix_DefineClass("classname", h_func, &my_own_matrix_class);\endcode
00042 
00043 
00044 
00045 Making a user matrix class involves the implementation of the following functions:
00046 
00047 CTA_MATRIX_CREATE_SIZE \n
00048 CTA_MATRIX_CREATE_INIT \n
00049 CTA_MATRIX_GETVALS     \n
00050 CTA_MATRIX_GETVAL      \n
00051 CTA_MATRIX_SETCOL      \n
00052 CTA_MATRIX_SETVALS     \n
00053 CTA_MATRIX_SETVAL      \n
00054 CTA_MATRIX_SETCONST    \n
00055 CTA_MATRIX_FREE        \n
00056 CTA_MATRIX_EXPORT      \n
00057 CTA_MATRIX_GER         \n
00058 CTA_MATRIX_INV         \n
00059 CTA_MATRIX_GEMV        \n
00060 CTA_MATRIX_GEMM        \n
00061 CTA_MATRIX_AXPY        \n
00062 CTA_MATRIX_NUMFUNC     
00063 
00064 For creating an implementation function see documentation of CTA_Func_Create().
00065 
00066 <b>Step 2</b>: to create an object of the newly defined matrix class call CTA_Matrix_Create() in the
00067 same way as creating a CTA_Matrix but with a different class handle, i.e. the user class handle from step 1 above.
00068 
00069 Example:
00070 
00071 \code
00072 Usr_Matrix usrmat; //user matrix object
00073 int n = 10;
00074 int m = 10;
00075 CTA_Datatype datatype = CTAI_String2Type("CTA_STRING");
00076 CTA_Handle userdata = CTA_NULL;
00077 CTA_Matrix_Create(my_own_matrix_class, m, n, datatype, &userdata, &usrmat);
00078 \endcode
00079 \n
00080 <b>Note 1: </b> with object data is meant only the object itself including pointer(s) to its contents, but
00081 not the contents of the matrix.\n\n
00082 <b>Note 2: </b> matrix indices start from 1, m and n for rows and columns respectively.\n\n
00083 */
00084 
00085 /* parameters for different functions */
00086 //#define CTA_MATRIX_CREATE_SIZE ( 1)
00087 //#define CTA_MATRIX_CREATE_INIT ( 2)
00088 //#define CTA_MATRIX_GETVALS     ( 4)
00089 //#define CTA_MATRIX_GETVAL      ( 5)
00090 //#define CTA_MATRIX_SETCOL      ( 6)
00091 //#define CTA_MATRIX_SETVALS     ( 7)
00092 //#define CTA_MATRIX_SETVAL      ( 8)
00093 //#define CTA_MATRIX_SETCONST    ( 9)
00094 //#define CTA_MATRIX_FREE        (10)
00095 //#define CTA_MATRIX_EXPORT      (11)
00096 //#define CTA_MATRIX_GER         (12)
00097 //#define CTA_MATRIX_INV         (13)
00098 //#define CTA_MATRIX_GEMV        (14)
00099 //#define CTA_MATRIX_GEMM        (15)
00100 //#define CTA_MATRIX_AXPY        (16)
00101 //#define CTA_MATRIX_NUMFUNC     (17)
00102 
00103 
00104 
00105 
00106 //#define CTA_MATRIX_CREATE_SIZE ( 1)
00107 
00108 #ifdef __cplusplus
00109 extern "C" {
00110 #endif
00111 
00112 
00113 /** \brief Implementation that forms part of the create process.
00114  * 
00115  * Must give the memory size of a new user matrix object.
00116  *
00117  * Example: 
00118  *  \code
00119 //in header file:
00120 typedef struct {
00121    //your own user object data goes here...
00122 }USR_MATRIX;
00123 
00124 //user implementation:
00125 void usr_matrix_create_size(...){
00126    *memsize = sizeof(USR_MATRIX);
00127    *retval = CTA_OK;
00128 }
00129  \endcode
00130  * \note At index CTA_MATRIX_CREATE_SIZE in the function list of the class descriptor.
00131  *
00132  * \param m        I  dimension, m (rows)
00133  * \param n        I  dimension, n (columns)
00134  * \param datatype I  data type of matrix elements
00135  * \param userdata IO user data
00136  * \param retval   O  must receive return value of user implementation function
00137  * \param memsize  O  must receive the number of bytes which are necessary to store one
00138                       user matrix class, with a pointer to the contents (data), but without the
00139                       contents themselves
00140  * \return no return value
00141  */
00142 void usr_matrix_create_size(
00143    int *m,
00144    int *n,
00145    CTA_Datatype *datatype,
00146    void *userdata,
00147    int *retval,
00148    int *memsize
00149    );
00150 
00151 
00152 //#define CTA_MATRIX_CREATE_INIT ( 2)
00153 /** \brief Implementation that forms part of the create process.
00154  *
00155  * The user matrix object needs to be made ready for use.
00156  *
00157  * \note At index CTA_MATRIX_CREATE_INIT in the function list of the class descriptor.
00158  *
00159  * \param objectdata IO pointer to object data of user matrix
00160  * \param m          I  dimension, m (rows)
00161  * \param n          I  dimension, n (columns)
00162  * \param datatype   I  data type of the matrix elements
00163  * \param *userdata   IO user data
00164  * \param retval     O  must receive return value of user implementation function
00165  * \return no return value
00166  */
00167 void usr_matrix_create_init(
00168    Usr_Matrix *objectdata,
00169    int *m,
00170    int *n,
00171    CTA_Datatype *datatype,
00172    void *userdata,
00173    int *retval
00174    );
00175 
00176 
00177 //#define CTA_MATRIX_GETVALS     ( 4)
00178 /** \brief Implementation for getting all values from the user matrix.
00179  *
00180  * \note At index CTA_MATRIX_GETVALS in the function list of the class descriptor.
00181  *
00182  * \param objectdata I  pointer to object data of user matrix
00183  * \param vals       O  must receive values; must exist before calling
00184  * \param m          I  number of rows of *vals, must be the same as number of rows in matrix
00185  * \param n          I  number of columns of *vals, must be the same as number of columns in matrix
00186  * \param datatype   I  data type of value; must be the same as data type of matrix elements
00187  * \param *userdata   IO user data
00188  * \param retval     O  must receive return value of user implementation function
00189  * \return no return value
00190  */
00191 void usr_matrix_getvals(
00192    Usr_Matrix *objectdata,
00193    void *vals,
00194    int *m,
00195    int *n,
00196    CTA_Datatype *datatype,
00197    void *userdata,
00198    int *retval
00199    );
00200 
00201 
00202 //#define CTA_MATRIX_GETVAL      ( 5)
00203 /** \brief Implementation for getting a single value from the user matrix.
00204  *
00205  * \note At index CTA_MATRIX_GETVAL in the function list of the class descriptor.
00206  *
00207  * \param objectdata I  pointer to object data of user matrix
00208  * \param val        O  must receive value; must exist before calling
00209  * \param m          I  row index of matrix value to get
00210  * \param n          I  column index of matrix value to get
00211  * \param datatype   I  data type of val; must be the same as data type of matrix elements
00212  * \param *userdata   IO user data
00213  * \param retval     O  must receive return value of user implementation function
00214  * \return no return value
00215  */
00216 void usr_matrix_getval(
00217    Usr_Matrix *objectdata,
00218    void *val,
00219    int *m,
00220    int *n,
00221    CTA_Datatype *datatype,
00222    void *userdata,
00223    int *retval
00224    );
00225 
00226 
00227 //#define CTA_MATRIX_SETCOL      ( 6)
00228 /** \brief Implementation for setting column of user matrix.
00229  *
00230  * \note At index CTA_MATRIX_SETCOL in the function list of the class descriptor.
00231  *
00232  * \param objectdata IO pointer to object data of user matrix
00233  * \param n          I  index of column to set
00234  * \param hvec       I  handle of sending column; dimensions must be compatible
00235  * \param retval     O  must receive return value of user implementation function
00236  * \return no return value
00237  */
00238 void usr_matrix_setcol(
00239    Usr_Matrix *objectdata,
00240    int *n,
00241    CTA_Vector *hvec,
00242    int *retval
00243   );
00244 
00245 
00246 //#define CTA_MATRIX_SETVALS     ( 7)
00247 /** \brief Implementation for setting all values of user matrix.
00248  *
00249  * \note At index CTA_MATRIX_SETVALS in the function list of the class descriptor.
00250  *
00251  * \param objectdata IO pointer to object data of user matrix
00252  * \param vals       I  values to set to
00253  * \param m          I  number of rows of *vals, must be the same as number of rows in matrix
00254  * \param n          I  number of columns of *vals, must be the same as number of columns in matrix
00255  * \param datatype   I  data type of value; must be the same as data type of matrix elements
00256  * \param *userdata   IO user data
00257  * \param retval     O  must receive return value of user implementation function
00258  * \return no return value
00259  */
00260 void usr_matrix_setvals(
00261    Usr_Matrix *objectdata,
00262    void *vals,
00263    int *m,
00264    int *n,
00265    CTA_Datatype *datatype,
00266    void *userdata,
00267    int *retval
00268   );
00269   
00270 
00271 //#define CTA_MATRIX_SETVAL      ( 8)
00272 /** \brief Implementation for setting a single value of user matrix.
00273  *
00274  * \note At index CTA_MATRIX_SETVAL in the function list of the class descriptor.
00275  *
00276  * \param objectdata IO pointer to object data of user matrix
00277  * \param val        I  value to set to
00278  * \param m          I  row index of matrix value to set
00279  * \param n          I  column index of matrix value to set
00280  * \param datatype   I  data type of val; must be the same as data type of matrix elements
00281  * \param *userdata   IO user data
00282  * \param retval     O  must receive return value of user implementation function
00283  * \return no return value
00284  */
00285 void usr_matrix_setval(
00286    Usr_Matrix *objectdata,
00287    void *val,
00288    int *m,
00289    int *n,
00290    CTA_Datatype *datatype,
00291    void *userdata,
00292    int *retval
00293   );
00294 
00295 //#define CTA_MATRIX_SETCONST    ( 9)
00296 /** \brief Implementation for setting all user matrix elements to constant value.
00297  *
00298  * \note At index CTA_MATRIX_SETCONST in the function list of the class descriptor.
00299  *
00300  * \param objectdata IO pointer to object data of user matrix
00301  * \param val        I  constant value to set to
00302  * \param datatype   I  data type of val; must be the same as data type of matrix elements
00303  * \param *userdata   IO user data
00304  * \param retval     O  must receive return value of user implementation function
00305  * \return no return value
00306  */
00307 void usr_matrix_setconst(
00308    Usr_Matrix *objectdata,
00309    void *val,
00310    CTA_Datatype *datatype,
00311    void *userdata,
00312    int *retval
00313   );
00314 
00315 //#define CTA_MATRIX_FREE        (10)
00316 /** \brief Implementation for freeing the object data and associated resources.
00317  *
00318  * \note At index CTA_MATRIX_FREE in the function list of the class descriptor.
00319  *
00320  * \param objectdata IO pointer to object data of user matrix
00321  * \param *userdata   IO user data
00322  * \param retval     O  must receive return value of user implementation function
00323  * \return no return value
00324  */
00325 void usr_matrix_free(
00326    Usr_Matrix *objectdata,
00327    CTA_Handle *userdata,
00328    int *retval
00329    );
00330 
00331 //#define CTA_MATRIX_EXPORT      (11)
00332 /** \brief Implementation for exporting user matrix.
00333  *
00334  * \note At index CTA_MATRIX_EXPORT in the function list of the class descriptor.
00335  *
00336  * \param objectdata I  pointer to object data of user matrix
00337  * \param *userdata   IO user data
00338  * \param retval     O  must receive return value of user implementation function
00339  * \return no return value
00340  */
00341 void usr_matrix_export(
00342          Usr_Matrix *objectdata,
00343          CTA_Handle *userdata,
00344          int *retval);
00345          
00346 
00347 //#define CTA_MATRIX_GER         (12)
00348 /** \brief Implementation for applying the BLAS operation GER: A=A+(alpha)x(y(T))
00349  * 
00350  * i.e. for matrix A, vectors x and y and scalar alpha
00351  *
00352  * \note At index CTA_MATRIX_GER in the function list of the class descriptor.
00353  *
00354  * \param A           IO pointer to object data of user matrix A; must exist before calling
00355  * \param alpha       I  scalar
00356  * \param vx          I  handle of vector x
00357  * \param vy          I  handle of vector y
00358  * \param retval      O  must receive return value of user implementation function
00359  * \return no return value
00360  */
00361 void usr_matrix_ger(
00362          Usr_Matrix *A,
00363          double *alpha,
00364          CTA_Vector *vx,
00365          CTA_Vector *vy,
00366          int *retval);
00367 
00368 //#define         (13)
00369 /** \brief Implementation for inverting user matrix.
00370  *
00371  * \note At index CTA_MATRIX_INV in the function list of the class descriptor.
00372  *
00373  * \param A        IO pointer to object data of user matrix
00374  * \param retval   O  must receive return value of user implementation function
00375  * \return no return value
00376  */
00377 void usr_matrix_inv(
00378    Usr_Matrix *A,
00379    int *retval
00380    );
00381 
00382 //#define CTA_MATRIX_GEMV        (14)
00383 /** \brief Implementation for applying the BLAS operation GEMV: A=(alpha)Ax+(beta)y
00384  *
00385  * i.e. for matrix A, vectors x (optionally transposed) and y and scalars alpha and beta
00386  *
00387  * \note At index CTA_MATRIX_GEMV in the function list of the class descriptor.
00388  *
00389  * \param A        IO pointer to object data of user matrix
00390  * \param trans    I  transpose flag CTA_TRUE/CTA_FALSE for matrix A
00391  * \param alpha    I  scalar
00392  * \param vx       I  handle of vector x
00393  * \param beta     I  scalar
00394  * \param vy       I  handle of vector y
00395  * \param retval   O  must receive return value of user implementation function
00396  * \return no return value
00397  */
00398 void usr_matrix_gemv(
00399          Usr_Matrix *A,
00400          int *trans,
00401          double *alpha,
00402          CTA_Vector *vx,
00403          double *beta,
00404          CTA_Vector *vy,
00405          int *retval);
00406 
00407 //#define CTA_MATRIX_GEMM        (15)
00408 /** \brief Implementation for applying the BLAS operation GEMM: C=(alpha)AB+(beta)C
00409  *
00410  * i.e. for matrices A,B (both optionally transposed) and C, scalars alpha and beta
00411  *
00412  * \note At index CTA_MATRIX_GEMM in the function list of the class descriptor.
00413  *
00414  * \param C        IO pointer to object data of user matrix C
00415  * \param transa   I  transpose flag for matrix A (CTA_TRUE for transposing or CTA_FALSE otherwise)
00416  * \param transb   I  transpose flag for matrix B (CTA_TRUE for transposing or CTA_FALSE otherwise)
00417  * \param alpha    I  scalar
00418  * \param A        I  pointer to object data of user matrix A
00419  * \param B        I  pointer to object data of user matrix B
00420  * \param beta     I  scalar
00421  * \param retval   O  must receive return value of user implementation function
00422  * \return no return value
00423  */
00424 void usr_matrix_gemm(
00425          Usr_Matrix *C,
00426          int *transa,
00427          int *transb,
00428          double *alpha,
00429          Usr_Matrix *A,
00430          Usr_Matrix *B,
00431          double *beta,
00432          int *retval);
00433 
00434 //#define CTA_MATRIX_AXPY        (16)
00435 /** \brief Implementation for applying the BLAS operation AXPY: Y=Y+(alpha)X
00436  *
00437  * i.e. for matrices X and Y, scalar alpha
00438  *
00439  * \note At index CTA_MATRIX_AXPY in the function list of the class descriptor.
00440  *
00441  * \param y        IO pointer to object data of user matrix y
00442  * \param alpha    I  scalar
00443  * \param x        I  pointer to object data of user matrix x
00444  * \param retval   O  must receive return value of user implementation function
00445  * \return no return value
00446  */
00447 void usr_matrix_axpy(
00448    Usr_Matrix *y,
00449    double *alpha,
00450    Usr_Matrix *x,
00451    int *retval
00452   );
00453 
00454 #ifdef __cplusplus
00455 }
00456 #endif

Generated on Mon Apr 6 14:05:58 2009 for COSTA by  doxygen 1.5.2