amino
Lightweight Robot Utility Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
la_impl.h
1 /* -*- mode: C; c-basic-offset: 4 -*- */
2 /* ex: set shiftwidth=4 tabstop=4 expandtab: */
3 /*
4  * Copyright (c) 2011-2012, Georgia Tech Research Corporation
5  * All rights reserved.
6  *
7  * Author(s): Neil T. Dantam <ntd@gatech.edu>
8  * Georgia Tech Humanoid Robotics Lab
9  * Under Direction of Prof. Mike Stilman <mstilman@cc.gatech.edu>
10  *
11  *
12  * This file is provided under the following "BSD-style" License:
13  *
14  *
15  * Redistribution and use in source and binary forms, with or
16  * without modification, are permitted provided that the following
17  * conditions are met:
18  *
19  * * Redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer.
21  *
22  * * Redistributions in binary form must reproduce the above
23  * copyright notice, this list of conditions and the following
24  * disclaimer in the documentation and/or other materials provided
25  * with the distribution.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
28  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
29  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
32  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
35  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
36  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
38  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39  * POSSIBILITY OF SUCH DAMAGE.
40  *
41  */
42 
43 
44 #include "amino/def.h"
45 
55 AA_API void AA_NAME(la,transpose)
56 ( size_t m, size_t n,
57  const AA_TYPE *A, size_t lda,
58  AA_TYPE *B, size_t ldb );
59 
69 AA_FDEC(AA_TYPE, la, ssd,
70  size_t n,
71  const AA_TYPE *x, size_t incx,
72  const AA_TYPE *y, size_t incy )
73 
74 
84 AA_API void AA_NAME(la,lerp)
85 ( size_t n, AA_TYPE u,
86  const AA_TYPE *v1, size_t inc1,
87  const AA_TYPE *v2, size_t inc2,
88  AA_TYPE *vu, size_t incu );
89 
90 
91 
93 AA_API void AA_NAME(la,3spline_param)
94 ( size_t n, AA_TYPE tf,
95  const AA_TYPE *x1, size_t incx1,
96  const AA_TYPE *dx1, size_t incdx1,
97  const AA_TYPE *x2, size_t inc2,
98  const AA_TYPE *dx2, size_t incdx2,
99  AA_TYPE *a2, AA_TYPE *a3 );
100 
102 AA_API void AA_NAME(la,3spline)
103 ( size_t n, AA_TYPE tf,
104  const AA_TYPE *x1, size_t incx1,
105  const AA_TYPE *dx1, size_t incdx1,
106  const AA_TYPE *a2, const AA_TYPE *a3,
107  AA_TYPE *x, size_t incx,
108  AA_TYPE *dx, size_t incdx,
109  AA_TYPE *ddx, size_t incddx );
110 
112 AA_API void AA_NAME(la,5spline_param)
113 ( size_t n, AA_TYPE tf,
114  const AA_TYPE *x1, size_t incx1,
115  const AA_TYPE *dx1, size_t incdx1,
116  const AA_TYPE *ddx1, size_t incddx1,
117  const AA_TYPE *x2, size_t inc2,
118  const AA_TYPE *dx2, size_t incdx2,
119  const AA_TYPE *ddx2, size_t incddx2,
120  AA_TYPE *a3, AA_TYPE *a4, AA_TYPE *a5 );
121 
123 AA_API void AA_NAME(la,5spline)
124 ( size_t n, AA_TYPE tf,
125  const AA_TYPE *x1, size_t incx1,
126  const AA_TYPE *dx1, size_t incdx1,
127  const AA_TYPE *ddx1, size_t incddx1,
128  const AA_TYPE *a3, const AA_TYPE *a4, const AA_TYPE *a5,
129  AA_TYPE *x, size_t incx,
130  AA_TYPE *dx, size_t incdx,
131  AA_TYPE *ddx, size_t incddx );
132 
139 AA_FDEC(AA_TYPE, la, vecstd,
140  size_t n,
141  const AA_TYPE *x, size_t incx,
142  AA_TYPE mu);
143 
153 AA_FDEC(void, la, colmean,
154  size_t m, size_t n,
155  const AA_TYPE *A, size_t lda,
156  AA_TYPE *x);
157 
167 AA_FDEC(void, la, rowmean,
168  size_t m, size_t n,
169  const AA_TYPE *A, size_t lda,
170  AA_TYPE *x);
171 
172 /* AA_API void AA_NAME(la,_cmean) */
173 /* ( size_t m, size_t n, */
174 /* const AA_TYPE *A, size_t lda, */
175 /* AA_TYPE *x ); */
176 
188 AA_FDEC(void, la, colcov,
189  size_t m, size_t n,
190  const AA_TYPE *A, size_t lda,
191  const AA_TYPE *x,
192  AA_TYPE *E, size_t lde);
193 
194 /* AA_API void AA_NAME(la,_ccov) */
195 /* ( size_t m, size_t n, */
196 /* const AA_TYPE *A, size_t lda, */
197 /* const AA_TYPE *x, */
198 /* AA_TYPE *E, size_t lde ); */
199 
200 
201 
202 /* Hungarian algorithm to solve min assignment problem
203  * \param n rows and cols of A
204  * \param A cost matrix, column major, destroyed on exit
205  * \param[out] row_assign array of column assigned to row at index i,
206  * length m. Unmatched elements have the value of -1.
207  * \param col_assign mapping from col to matched row
208  * \param lda leading dimension of A
209  * \param row_assign array of column assigned to row at index i
210  * \param iwork array of size 3*n*n +2*n
211  */
212 /* AA_API void AA_NAME(la,opt_hungarian) */
213 /* ( size_t n, AA_TYPE *A, size_t lda, */
214 /* ssize_t *row_assign, */
215 /* ssize_t *col_assign, */
216 /* ssize_t *iwork); */
217 
218 
219 /* Compute minimum iwork size for hungarian algorithm
220  *
221  * \sa aa_la_d_opt_hungarian
222  */
223 /* static inline size_t AA_NAME(la,opt_hungarian_iworksize) */
224 /* ( size_t n ) { */
225 /* return 3*n*n + 2*n; */
226 /* } */
227 
228 /* Hungarian algorithm for rectangular distance matrix by padding with zeros.
229  *
230  * \param m rows of A
231  * \param n cols of A
232  * \param A distance matrix for minimization problem
233  * \param lda leading dimension of A
234  * \param[out] row_assign array of column assigned to row at index i,
235  * length m. Unmatched elements have the value of -1.
236  * \param[out] col_assign mapping from col to matched row
237  * \param work work array of length max(m,n)**2
238  * \param iwork integer work array of length (3*max(m,n)**2 + 4*max(m,n))
239  */
240 /* AA_API void AA_NAME(la,opt_hungarian_pad) */
241 /* ( size_t m, size_t n, const AA_TYPE *A, size_t lda, */
242 /* ssize_t *row_assign, */
243 /* ssize_t *col_assign, */
244 /* AA_TYPE *work, ssize_t *iwork); */
245 
246 /* Compute minimum iwork size for padded hungarian algorithm
247  *
248  * \sa aa_la_d_opt_hungarian_pad
249  */
250 /* static inline size_t AA_NAME(la,opt_hungarian_pad_iworksize) */
251 /* (size_t m,size_t n) { */
252 /* size_t p = AA_MAX(m,n); */
253 /* return AA_NAME(la,opt_hungarian_iworksize)(p) + 2*p; */
254 /* } */
255 
256 
257 /* Compute minimum work size for padded hungarian algorithm
258  *
259  * \sa aa_la_d_opt_hungarian_pad
260  */
261 /* static inline size_t AA_NAME(la,opt_hungarian_pad_worksize) */
262 /* (size_t m,size_t n) { */
263 /* size_t p = AA_MAX(m,n); */
264 /* return p*p; */
265 /* } */
266 
267 
268 /* Converts max assignment to min assignment for Hungarian algorithm.
269  * \param m rows of A
270  * \param n cols of A
271  * \param A cost matrix for max problem,
272  * converted to matrix for min proble on exit
273  * \param lda leading dimension of A
274  */
275 /* AA_API void AA_NAME(la,opt_hungarian_max2min) */
276 /* ( size_t m, size_t n, AA_TYPE *A, size_t lda ); */
277 
278 
288 AA_FDEC( void, la, assign_hungarian,
289  size_t m, size_t n,
290  const AA_TYPE *A, size_t lda,
291  ssize_t *row_assign, ssize_t *col_assign );
292 
301 AA_FDEC( void, la, assign_hungarian_max2min,
302  size_t m, size_t n,
303  AA_TYPE *A, size_t lda );
304 
305 
307 static inline size_t AA_NAME(la,minloc)
308 ( size_t n, AA_TYPE *x, size_t incx ) {
309  size_t imin = 0;
310  AA_TYPE xmin = *x;
311  for( size_t i = 1; i < n; i ++ ) {
312  if( x[i*incx] < xmin ) {
313  imin = i;
314  xmin = x[i*incx];
315  }
316  }
317  return imin;
318 }
319 
321 static inline AA_TYPE AA_NAME(la,mat_max)
322 ( size_t m, size_t n, AA_TYPE *A, size_t lda,
323  size_t *pi, size_t *pj ) {
324  size_t im = 0;
325  size_t jm = 0;
326  AA_TYPE xm = *A;
327  for( size_t i = 0; i < m; i++) {
328  for( size_t j = 0; j < n; j++) {
329  if( AA_MATREF(A, lda, i, j ) > xm ) {
330  im = i;
331  jm = j;
332  xm = AA_MATREF(A, lda, i, j );
333  }
334  }
335  }
336  if( pi ) *pi = im;
337  if( pj ) *pj = jm;
338  return xm;
339 }
340 
341 
343 static inline size_t AA_NAME(la,maxloc)
344 ( size_t n, AA_TYPE *x, size_t incx ) {
345  size_t imax = 0;
346  AA_TYPE xmax = *x;
347  for( size_t i = 1; i < n; i ++ ) {
348  if( x[i*incx] > xmax ) {
349  imax = i;
350  xmax = x[i*incx];
351  }
352  }
353  return imax;
354 }
355 
366 AA_FDEC(AA_TYPE, la, angle,
367  size_t n, const AA_TYPE *x, size_t incx,
368  const AA_TYPE *y, size_t incy)
369 
370 
371 
372 
385 AA_API int AA_NAME(la,lls)
386 ( size_t m, size_t n, size_t p,
387  const AA_TYPE *A, size_t lda,
388  const AA_TYPE *b, size_t ldb,
389  AA_TYPE *x, size_t ldx );
390 
391 
408 AA_API int AA_NAME(la,svd)
409 ( size_t m, size_t n, const AA_TYPE *A, size_t lda,
410  AA_TYPE *U, size_t ldu,
411  AA_TYPE *S,
412  AA_TYPE *Vt, size_t ldvt );
413 
414 
421 AA_API AA_TYPE AA_NAME(la,median)
422 ( size_t n, const AA_TYPE *x, size_t incx );
423 
432 AA_API AA_TYPE AA_NAME(la,nmedian)
433 ( size_t n, AA_TYPE *x );
434 
435 
438 static inline AA_TYPE AA_NAME(la,nmedian_pop)
439 ( size_t n, AA_TYPE *x )
440 {
441  AA_TYPE u = AA_NAME(la,nmedian)(n, x);
443  return u;
444 }
445 
453 AA_TYPE AA_NAME(la,mad)
454 ( size_t n, const AA_TYPE u, const AA_TYPE *x, size_t incx );
455 
465 AA_TYPE AA_NAME(la,mad2)
466 ( size_t m, size_t n, const AA_TYPE *u, const AA_TYPE *A, size_t lda );
467 
469 AA_API int AA_NAME(la,eev)
470 ( size_t n, const AA_TYPE *A, size_t lda,
471  AA_TYPE *wr,
472  AA_TYPE *wi,
473  AA_TYPE *Vl, size_t ldvl,
474  AA_TYPE *Vr, size_t ldvr );
475 
488 AA_FDEC( void, la, colfit,
489  size_t m, size_t n,
490  const AA_TYPE *A, size_t lda, AA_TYPE *x );
491 
492 
493 /* Ordering / Sort comparison function */
494 int AA_NAME(la,compar)( const void *a, const void *b );
495 
502 int AA_NAME(la, ls_duqu_cmat)
503 (const double *sigma, const double *theta, double *cm);
504 
505 
506 #include "amino/undef.h"
#define AA_MATREF(A, lda, row, col)
Reference an element in a column-major matrix.
Definition: math.h:347
AA_API void aa_mem_region_local_pop(void *ptr)
Pop ptr from thread-local memory region.
#define AA_API
calling and name mangling convention for functions
Definition: amino.h:95