source:branches/dev-cw-2658/RuntimeLibrary/src/jmi/jmi_linear_algebra.h@14000

Last change on this file since 14000 was 14000, checked in by Christian Andersson, 4 weeks ago

Minor cleanup. Related to ticket:5868

File size: 6.1 KB
Line
1/*
2    Copyright (C) 2017 Modelon AB
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License version 3 as published
6    by the Free Software Foundation, or optionally, under the terms of the
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License, or the Common Public License, for more details.
13
14    You should have received copies of the GNU General Public License
15    and the Common Public License along with this program.  If not,
17    <http://www.ibm.com/developerworks/library/os-cpl.html/> respectively.
18*/
19
20/** \file jmi_linear_algebra.h
21 *  \brief Linear algebra related methods and computational algorithms
22 **/
23
24#ifndef _JMI_LINEAR_ALGEBRA_H
25#define _JMI_LINEAR_ALGEBRA_H
26
27#include "jmi_types.h"
28
29/* Lapack functions */
30extern void dgetrf_(int* M, int* N, double* A, int* LDA, int* IPIV, int* INFO );
31extern void dgetrs_(char* TRANS, int* N, int* NRHS, double* A, int* LDA, int* IPIV, double* B, int* LDB, int* INFO);
32extern void dgecon_(char *NORM, int *N, double *A, int *LDA, double *anorm, double *rcond, double *work, int *iwork, int *INFO);
33extern double dlange_(char *NORM, int *M, int *N, double *A, int *LDA, double *WORK);
34
35/* Blas functions */
36extern void dger_(int* M, int* N, double* ALPHA, double* X, int* INCX, double* Y,int* INCY,double* A, int* LDA);
37extern void dgemv_(char* TRANS, int* M, int* N, double* ALPHA, double* A, int* LDA, double* X, int* INCX, double* BETA, double* Y, int* INCY);
38extern void daxpy_(int* N,double* DA,double* DX,int* INCX,double* DY, int* INCY);
39extern double ddot_(int* N, double* DX, int* INCX, double* Y, int* INCY);
40/* extern int idamax_(int *N, double* X, int *INC); */
41extern double dnrm2_(int* N, double* X, int *INC);
42
43/**
44 * \brief Computes the weighted residual mean square
45 *
46 * sum( (w_i*x_i)^2 )^0.5 / N.
47 *
48 * @param jmi_real_t* A real pointer to the weights.
49 * @param jmi_real_t* A pointer to values.
50 * @param jmi_int_t The number of elements.
51 * @return The WRMS.
52 */
53jmi_real_t jmi_linear_algebra_wrms(jmi_real_t* weights, jmi_real_t* x, jmi_int_t N);
54
55/**
56 * \brief Computes y:= ax + y
57 *
58 * @param jmi_real_t A real constant a.
59 * @param jmi_real_t* A real pointer to the x vector.
60 * @param jmi_real_t* A real pointer to the y vector.
61 * @param jmi_int_t The number of elements.
62 */
63void jmi_linear_algebra_daxpy(jmi_real_t a, jmi_real_t* x, jmi_real_t* y, jmi_int_t N);
64
65/**
66 * \brief Computes the dot product, x^T y
67 *
68 * @param jmi_real_t* A real pointer to the x vector.
69 * @param jmi_real_t* A real pointer to the y vector.
70 * @param jmi_int_t The number of elements.
71 * @return The dot product.
72 */
73jmi_real_t jmi_linear_algebra_ddot(jmi_real_t* x, jmi_real_t* y, jmi_int_t N);
74
75/**
76 * \brief Computes the matrix-vector operation, y := alpha*A*x + beta*y
77 *
78 * @param jmi_real_t A real constant a.
79 * @param jmi_real_t* A real pointer to the matrix A.
80 * @param jmi_real_t* A real pointer to the x vector.
81 * @param jmi_real_t A real constant b.
82 * @param jmi_real_t* A real pointer to the y vector.
83 * @param jmi_int_t The number of elements.
84 * @param jmi_int_t Boolean flag indicating if matrix A should be transposed.
85 * @return The dot product.
86 */
87void jmi_linear_algebra_dgemv(jmi_real_t a, jmi_real_t* A, jmi_real_t* x, jmi_real_t b, jmi_real_t* y, jmi_int_t N, jmi_int_t trans);
88
89/**
90 * \brief Computes the rank-1 operation, A := alpha*x*y**T + A
91 *
92 * @param jmi_real_t A real constant a.
93 * @param jmi_real_t* A real pointer to the x vector.
94 * @param jmi_real_t* A real pointer to the y vector.
95 * @param jmi_real_t* A real pointer to the matrix A.
96 * @param jmi_int_t The number of elements.
97 * @return The dot product.
98 */
99void jmi_linear_algebra_dger(jmi_real_t a, jmi_real_t* x, jmi_real_t *y, jmi_real_t *A, jmi_int_t N);
100
101/**
102 * \brief Computes z:= ax + by
103 *
104 * @param jmi_real_t A real constant a.
105 * @param jmi_real_t* A real pointer to the x vector.
106 * @param jmi_real_t A real constant b.
107 * @param jmi_real_t* A real pointer to the y vector.
108 * @param jmi_real_t* A real pointer to the z vector (output).
109 * @param jmi_int_t The number of elements.
110 */
111void jmi_linear_algebra_daxpby(jmi_real_t a, jmi_real_t* x, jmi_real_t b, jmi_real_t* y, jmi_real_t* z, jmi_int_t N);
112jmi_int_t jmi_linear_algebra_LU_factorize(jmi_real_t* A, jmi_int_t* pivots, jmi_int_t N);
113jmi_int_t jmi_linear_algebra_LU_solve(jmi_real_t* LU, jmi_int_t* pivots, jmi_real_t* x, jmi_int_t N);
114
115/**
116 * \brief Finds the index of the absolute maximum value of a vector.
117 *
118 * @param jmi_real_t* A pointer to the vector.
119 * @param jmi_int_t The number of elements.
120 * @return The index of the maximum absolute value
121 */
122jmi_int_t jmi_linear_algebra_idamax(jmi_real_t *x, jmi_int_t N);
123
124/**
125 * \brief Computes the euclidean norm of a vector.
126 *
127 * @param jmi_real_t* A pointer to the vector.
128 * @param jmi_int_t The number of elements.
129 * @return The norm of the vector
130 */
131jmi_real_t jmi_linear_algebra_norm(jmi_real_t* x, jmi_int_t N);
132
133/**
134 * \brief Estimates the reciprocal condition number of a matrix
135 *
136 * @param jmi_real_t* The LU factorization of a matrix
137 * @param jmi_real_t The norm of the matrix
138 * @param jmi_int_t The number of elements.
139 * @param char The type of the norm.
140 */
141jmi_real_t jmi_linear_algebra_dgecon(jmi_real_t* LU, jmi_real_t A_norm, jmi_int_t N, char norm_type);
142
143/**
144 * \brief Computes the norm of a matrix
145 *
146 * @param jmi_real_t* The matrix
147 * @param jmi_int_t The number of elements.
148 * @param char The type of the norm.
149 */
150jmi_real_t jmi_linear_algebra_dlange(jmi_real_t* A, jmi_int_t N, char norm_type);
151
152/**
153 * \brief Computes the element-wise multiplication of two vectors
154 *
155 * @param jmi_real_t* A real pointer to the x vector.
156 * @param jmi_real_t* A real pointer to the y vector (result saved in this vector).
157 * @param jmi_int_t The number of elements.
158 */
159void jmi_linear_algebra_dxemy(jmi_real_t* x, jmi_real_t* y, jmi_int_t N);
160
161#endif
Note: See TracBrowser for help on using the repository browser.