NEURON
hessen.c
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 
3 /**************************************************************************
4 **
5 ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
6 **
7 ** Meschach Library
8 **
9 ** This Meschach Library is provided "as is" without any express
10 ** or implied warranty of any kind with respect to this software.
11 ** In particular the authors shall not be liable for any direct,
12 ** indirect, special, incidental or consequential damages arising
13 ** in any way from use of the software.
14 **
15 ** Everyone is granted permission to copy, modify and redistribute this
16 ** Meschach Library, provided:
17 ** 1. All copies contain this copyright notice.
18 ** 2. All modified copies shall carry a notice stating who
19 ** made the last modification and the date of such modification.
20 ** 3. No charge is made for this software or works derived from it.
21 ** This clause shall not be construed as constraining other software
22 ** distributed on the same medium as this software, nor is a
23 ** distribution fee considered a charge.
24 **
25 ***************************************************************************/
26 
27 
28 
29 /*
30  File containing routines for determining Hessenberg
31  factorisations.
32 */
33 
34 static char rcsid[] = "hessen.c,v 1.1 1997/12/04 17:55:23 hines Exp";
35 
36 #include <stdio.h>
37 #include "matrix.h"
38 #include "matrix2.h"
39 
40 
41 
42 /* Hfactor -- compute Hessenberg factorisation in compact form.
43  -- factorisation performed in situ
44  -- for details of the compact form see QRfactor.c and matrix2.doc */
45 MAT *Hfactor(A, diag, beta)
46 MAT *A;
47 VEC *diag, *beta;
48 {
49  static VEC *tmp1 = VNULL;
50  int k, limit;
51 
52  if ( ! A || ! diag || ! beta )
53  error(E_NULL,"Hfactor");
54  if ( diag->dim < A->m - 1 || beta->dim < A->m - 1 )
55  error(E_SIZES,"Hfactor");
56  if ( A->m != A->n )
57  error(E_SQUARE,"Hfactor");
58  limit = A->m - 1;
59 
60  tmp1 = v_resize(tmp1,A->m);
61  MEM_STAT_REG(tmp1,TYPE_VEC);
62 
63  for ( k = 0; k < limit; k++ )
64  {
65  get_col(A,(u_int)k,tmp1);
66  /* printf("the %d'th column = "); v_output(tmp1); */
67  hhvec(tmp1,k+1,&beta->ve[k],tmp1,&A->me[k+1][k]);
68  /* diag->ve[k] = tmp1->ve[k+1]; */
69  v_set_val(diag,k,v_entry(tmp1,k+1));
70  /* printf("H/h vector = "); v_output(tmp1); */
71  /* printf("from the %d'th entry\n",k+1); */
72  /* printf("beta = %g\n",beta->ve[k]); */
73 
74  /* hhtrcols(A,k+1,k+1,tmp1,beta->ve[k]); */
75  /* hhtrrows(A,0 ,k+1,tmp1,beta->ve[k]); */
76  hhtrcols(A,k+1,k+1,tmp1,v_entry(beta,k));
77  hhtrrows(A,0 ,k+1,tmp1,v_entry(beta,k));
78  /* printf("A = "); m_output(A); */
79  }
80 
81  return (A);
82 }
83 
84 /* makeHQ -- construct the Hessenberg orthogonalising matrix Q;
85  -- i.e. Hess M = Q.M.Q' */
86 MAT *makeHQ(H, diag, beta, Qout)
87 MAT *H, *Qout;
88 VEC *diag, *beta;
89 {
90  int i, j, limit;
91  static VEC *tmp1 = VNULL, *tmp2 = VNULL;
92 
93  if ( H==(MAT *)NULL || diag==(VEC *)NULL || beta==(VEC *)NULL )
94  error(E_NULL,"makeHQ");
95  limit = H->m - 1;
96  if ( diag->dim < limit || beta->dim < limit )
97  error(E_SIZES,"makeHQ");
98  if ( H->m != H->n )
99  error(E_SQUARE,"makeHQ");
100  Qout = m_resize(Qout,H->m,H->m);
101 
102  tmp1 = v_resize(tmp1,H->m);
103  tmp2 = v_resize(tmp2,H->m);
104  MEM_STAT_REG(tmp1,TYPE_VEC);
105  MEM_STAT_REG(tmp2,TYPE_VEC);
106 
107  for ( i = 0; i < H->m; i++ )
108  {
109  /* tmp1 = i'th basis vector */
110  for ( j = 0; j < H->m; j++ )
111  /* tmp1->ve[j] = 0.0; */
112  v_set_val(tmp1,j,0.0);
113  /* tmp1->ve[i] = 1.0; */
114  v_set_val(tmp1,i,1.0);
115 
116  /* apply H/h transforms in reverse order */
117  for ( j = limit-1; j >= 0; j-- )
118  {
119  get_col(H,(u_int)j,tmp2);
120  /* tmp2->ve[j+1] = diag->ve[j]; */
121  v_set_val(tmp2,j+1,v_entry(diag,j));
122  hhtrvec(tmp2,beta->ve[j],j+1,tmp1,tmp1);
123  }
124 
125  /* insert into Qout */
126  set_col(Qout,(u_int)i,tmp1);
127  }
128 
129  return (Qout);
130 }
131 
132 /* makeH -- construct actual Hessenberg matrix */
133 MAT *makeH(H,Hout)
134 MAT *H, *Hout;
135 {
136  int i, j, limit;
137 
138  if ( H==(MAT *)NULL )
139  error(E_NULL,"makeH");
140  if ( H->m != H->n )
141  error(E_SQUARE,"makeH");
142  Hout = m_resize(Hout,H->m,H->m);
143  Hout = m_copy(H,Hout);
144 
145  limit = H->m;
146  for ( i = 1; i < limit; i++ )
147  for ( j = 0; j < i-1; j++ )
148  /* Hout->me[i][j] = 0.0;*/
149  m_set_val(Hout,i,j,0.0);
150 
151  return (Hout);
152 }
153 
#define E_SQUARE
Definition: err.h:103
#define error(err_num, fn_name)
Definition: err.h:73
#define E_NULL
Definition: err.h:102
#define E_SIZES
Definition: err.h:95
#define diag(s)
Definition: fmenu.cpp:192
MAT * makeH(MAT *H, MAT *Hout)
Definition: hessen.c:133
MAT * makeHQ(MAT *H, VEC *diag, VEC *beta, MAT *Qout)
Definition: hessen.c:86
MAT * Hfactor(MAT *A, VEC *diag, VEC *beta)
Definition: hessen.c:45
static char rcsid[]
Definition: hessen.c:34
MAT * hhtrrows(MAT *M, u_int i0, u_int j0, VEC *hh, double beta)
Definition: hsehldr.c:100
MAT * hhtrcols(MAT *M, u_int i0, u_int j0, VEC *hh, double beta)
Definition: hsehldr.c:146
VEC * hhtrvec(VEC *hh, double beta, u_int i0, VEC *in, VEC *out)
Definition: hsehldr.c:72
VEC * hhvec(VEC *vec, u_int i0, Real *beta, VEC *out, Real *newval)
Definition: hsehldr.c:47
static Object ** v_resize(void *v)
Definition: ivocvect.cpp:1383
uint32_t u_int
Definition: machine.h:38
static Object ** m_resize(void *v)
Definition: matrix.cpp:191
#define m_set_val(A, i, j, val)
Definition: matrix.h:277
#define VNULL
Definition: matrix.h:631
#define m_copy(in, out)
Definition: matrix.h:403
#define set_col(mat, col, vec)
Definition: matrix.h:564
#define v_set_val(x, i, val)
Definition: matrix.h:265
VEC * get_col(MAT *, u_int, VEC *)
#define v_entry(x, i)
Definition: matrix.h:262
#define i
Definition: md1redef.h:12
#define TYPE_VEC
Definition: meminfo.h:52
#define MEM_STAT_REG(var, type)
Definition: meminfo.h:133
#define A(i)
Definition: multisplit.cpp:63
size_t j
static philox4x32_key_t k
Definition: nrnran123.cpp:11
#define NULL
Definition: sptree.h:16
Definition: matrix.h:73
Definition: matrix.h:67
u_int dim
Definition: matrix.h:68
Real * ve
Definition: matrix.h:69