1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
|
/* $Id: vmmatrix.h,v 1.2 2013-03-25 11:43:04 cgarcia Exp $
*
* This file is part of the VIMOS Pipeline
* Copyright (C) 2002-2004 European Southern Observatory
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
* $Author: cgarcia $
* $Date: 2013-03-25 11:43:04 $
* $Revision: 1.2 $
* $Name: not supported by cvs2svn $
*/
#ifndef VM_MATRIX_H
#define VM_MATRIX_H
#include <pilmacros.h>
#include <vmtypes.h>
PIL_BEGIN_DECLS
#define NullMatrix NULL
#define _(b,i,j) (*((b)->data+(i)*(b)->nc+(j))) /* b(i,j)*/
typedef struct _VIMOS_FLOAT_ARRAY_ {
float *data;
int len;
} VimosFloatArray;
typedef struct _VIMOS_MATRIX_ {
double *data;
int nr;
int nc;
} VimosMatrix;
VimosFloatArray *newFloatArray(int nels);
void deleteFloatArray(VimosFloatArray *array);
typedef struct _VIMOS_INT_ARRAY_ {
int *data;
int len;
} VimosIntArray;
VimosIntArray *newIntArray(int nels);
void deleteIntArray(VimosIntArray *array);
/*---------------------------------------------------------------------------
* Function : create_mx()
* In : number of rows, number of columns
* Out : Matrix
* Job : allocates memory for a matrix
* Notice : returns Nulmat if cannot allocate
*--------------------------------------------------------------------------*/
VimosMatrix *newMatrix(int nr, int nc) ;
/*---------------------------------------------------------------------------
* Function : copy_mx()
* In : Matrix
* Out : Matrix
* Job : copy a matrix
* Notice : returns Nulmat if cannot allocate
*--------------------------------------------------------------------------*/
VimosMatrix *copyMatrix(VimosMatrix *m) ;
/*---------------------------------------------------------------------------
* Function : close_mx()
* In : Matrix
* Out : void
* Job : free memory associated to a matrix
* Notice :
*--------------------------------------------------------------------------*/
void deleteMatrix(VimosMatrix *m) ;
/*---------------------------------------------------------------------------
* Function : mul_mx()
* In : 2 Matrix
* Out : Matrix
* Job : Multiplies 2 Matrixes
* Notice :
*--------------------------------------------------------------------------*/
VimosMatrix *mulMatrix(VimosMatrix *a, VimosMatrix *b) ;
/*---------------------------------------------------------------------------
* Function : invert_mx()
* In : (square) Matrix
* Out : Matrix
* Job : invert a matrix
* Notice : Hardcoded for 1x1, 2x2, 3x3 matrices
*--------------------------------------------------------------------------*/
VimosMatrix *invertMatrix(VimosMatrix *aa) ;
/*---------------------------------------------------------------------------
* Function : transp_mx()
* In : Matrix
* Out : Matrix
* Job : transposition of a Matrix
* Notice :
*--------------------------------------------------------------------------*/
VimosMatrix *transpMatrix(VimosMatrix *a) ;
/*---------------------------------------------------------------------------
* Function : gauss_pivot()
* In : 2 matrix lines, number of rows in line
* Out : error code: 1 if Ok, 0 else
* Job : line simplification with Gauss method
* Notice : should be private to invert_mx()
*--------------------------------------------------------------------------*/
int gaussPivot(double *ptra, double *ptrc, int n) ;
/*---------------------------------------------------------------------------
Function : least_sq_mx()
In : 2 matrices A, B
Out : 1 matrix
Job : from the set XA = B, compute the matrix P defined by
P = B.tA.inv(A.tA)
P solves X by a least-squares criterion
Notice :
---------------------------------------------------------------------------*/
VimosMatrix *lsqMatrix(VimosMatrix *A, VimosMatrix *B) ;
/*
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Description:
Some mathematical functions for "compatibility" with NR-like routines.
These can handle different ranges for array indexes (not necessarilily
starting from 0)
Updates:
15 Jun 00: Created (AZ)
------------------------------------------------------------------------------
*/
/*
allocate and free a vector of integers with subscript range v[nlow..nhigh]
*/
int *intVector(int nl, int nh);
void freeIntVector(int *v, int nl, int nh);
/*
allocate and free a vector of floats with subscript range v[nlow..nhigh]
*/
float *floatVector(int nl, int nh);
void freeFloatVector(float *v, int nl, int nh);
/*
allocate and free a vector of doubles with subscript range v[nlow..nhigh]
*/
double *doubleVector(int nl, int nh);
void freeDoubleVector(double *v, int nl, int nh);
/*
allocate and free a floating point matrix with subscript range
m[nrl..nrh][ncl..nch]
*/
float **Matrix(int nrl, int nrh, int ncl, int nch);
void freeMatrix(float **m, int nrl, int nrh, int ncl, int nch);
/*
allocate and free a double matrix with subscript range
m[nrl..nrh][ncl..nch]
*/
double **doubleMatrix(long nrl, long nrh, long ncl, long nch);
void freeDoubleMatrix(double **m, long nrl, long nrh, long ncl, long nch);
/*
allocate a floating point matrix m[nrl..nrh][ncl..nch] that points to the
matrix declared in the standard C manner as a[nrow][ncol], where
nrow=nrh-nrl+1 and ncol=nch-ncl+1. The routine should be called with the
address &a[0][0] as the first argument.
*/
float **convertMatrix(float *a, int nrl, int nrh, int ncl, int nch);
void freeConvertedMatrix(float **b, int nrl, int nrh, int ncl, int nch);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
These functions define the VimosFloat2DArray type
THESE HAVE BEEN ADDED TO VIMOSMATRIX
------------------------------------------------------------------------------
*/
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
structure VimosFloat2DArray
Description:
Structure similar to VimosFloatArray, but 2-dimanesional. It is used
to compute histograms, for instance.
Layout:
float x;
float y;
int len;
Updates:
01 Aug 00: Created (AZ)
------------------------------------------------------------------------------
*/
typedef struct _VIMOS_FLOAT_2D_ARRAY_ {
float *x;
float *y;
int len;
} VimosFloat2DArray;
VimosFloat2DArray *newFloat2DArray(int len);
void deleteFloat2DArray(VimosFloat2DArray *array);
/*
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
End of functions to define the VimosFloat2DArray type
------------------------------------------------------------------------------
*/
PIL_END_DECLS
#endif /* VM_MATRIX_H */
|