NEURON
zhessen.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  File containing routines for determining Hessenberg
30  factorisations.
31 
32  Complex version
33 */
34 
35 static char rcsid[] = "zhessen.c,v 1.1 1997/12/04 17:56:07 hines Exp";
36 
37 #include <stdio.h>
38 #include "zmatrix.h"
39 #include "zmatrix2.h"
40 
41 
42 /* zHfactor -- compute Hessenberg factorisation in compact form.
43  -- factorisation performed in situ
44  -- for details of the compact form see zQRfactor.c and zmatrix2.doc */
46 ZMAT *A;
47 ZVEC *diag;
48 {
49  static ZVEC *tmp1 = ZVNULL;
50  Real beta;
51  int k, limit;
52 
53  if ( ! A || ! diag )
54  error(E_NULL,"zHfactor");
55  if ( diag->dim < A->m - 1 )
56  error(E_SIZES,"zHfactor");
57  if ( A->m != A->n )
58  error(E_SQUARE,"zHfactor");
59  limit = A->m - 1;
60 
61  tmp1 = zv_resize(tmp1,A->m);
62  MEM_STAT_REG(tmp1,TYPE_ZVEC);
63 
64  for ( k = 0; k < limit; k++ )
65  {
66  zget_col(A,k,tmp1);
67  zhhvec(tmp1,k+1,&beta,tmp1,&A->me[k+1][k]);
68  diag->ve[k] = tmp1->ve[k+1];
69  /* printf("zHfactor: k = %d, beta = %g, tmp1 =\n",k,beta);
70  zv_output(tmp1); */
71 
72  zhhtrcols(A,k+1,k+1,tmp1,beta);
73  zhhtrrows(A,0 ,k+1,tmp1,beta);
74  /* printf("# at stage k = %d, A =\n",k); zm_output(A); */
75  }
76 
77  return (A);
78 }
79 
80 /* zHQunpack -- unpack the compact representation of H and Q of a
81  Hessenberg factorisation
82  -- if either H or Q is NULL, then it is not unpacked
83  -- it can be in situ with HQ == H
84  -- returns HQ
85 */
87 ZMAT *HQ, *Q, *H;
88 ZVEC *diag;
89 {
90  int i, j, limit;
91  Real beta, r_ii, tmp_val;
92  static ZVEC *tmp1 = ZVNULL, *tmp2 = ZVNULL;
93 
94  if ( HQ==ZMNULL || diag==ZVNULL )
95  error(E_NULL,"zHQunpack");
96  if ( HQ == Q || H == Q )
97  error(E_INSITU,"zHQunpack");
98  limit = HQ->m - 1;
99  if ( diag->dim < limit )
100  error(E_SIZES,"zHQunpack");
101  if ( HQ->m != HQ->n )
102  error(E_SQUARE,"zHQunpack");
103 
104 
105  if ( Q != ZMNULL )
106  {
107  Q = zm_resize(Q,HQ->m,HQ->m);
108  tmp1 = zv_resize(tmp1,H->m);
109  tmp2 = zv_resize(tmp2,H->m);
110  MEM_STAT_REG(tmp1,TYPE_ZVEC);
111  MEM_STAT_REG(tmp2,TYPE_ZVEC);
112 
113  for ( i = 0; i < H->m; i++ )
114  {
115  /* tmp1 = i'th basis vector */
116  for ( j = 0; j < H->m; j++ )
117  tmp1->ve[j].re = tmp1->ve[j].im = 0.0;
118  tmp1->ve[i].re = 1.0;
119 
120  /* apply H/h transforms in reverse order */
121  for ( j = limit-1; j >= 0; j-- )
122  {
123  zget_col(HQ,j,tmp2);
124  r_ii = zabs(tmp2->ve[j+1]);
125  tmp2->ve[j+1] = diag->ve[j];
126  tmp_val = (r_ii*zabs(diag->ve[j]));
127  beta = ( tmp_val == 0.0 ) ? 0.0 : 1.0/tmp_val;
128  /* printf("zHQunpack: j = %d, beta = %g, tmp2 =\n",
129  j,beta);
130  zv_output(tmp2); */
131  zhhtrvec(tmp2,beta,j+1,tmp1,tmp1);
132  }
133 
134  /* insert into Q */
135  zset_col(Q,i,tmp1);
136  }
137  }
138 
139  if ( H != ZMNULL )
140  {
141  H = zm_copy(HQ,zm_resize(H,HQ->m,HQ->n));
142 
143  limit = H->m;
144  for ( i = 1; i < limit; i++ )
145  for ( j = 0; j < i-1; j++ )
146  H->me[i][j].re = H->me[i][j].im = 0.0;
147  }
148 
149  return HQ;
150 }
151 
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_INSITU
Definition: err.h:106
#define E_SIZES
Definition: err.h:95
#define diag(s)
Definition: fmenu.cpp:192
#define Real
Definition: machine.h:189
#define i
Definition: md1redef.h:12
#define MEM_STAT_REG(var, type)
Definition: meminfo.h:133
#define A(i)
Definition: multisplit.cpp:63
for(i=0;i< n;i++)
size_t j
static philox4x32_key_t k
Definition: nrnran123.cpp:11
Definition: zmatrix.h:50
Definition: zmatrix.h:44
complex * ve
Definition: zmatrix.h:46
Real re
Definition: zmatrix.h:40
Real im
Definition: zmatrix.h:40
double zabs(complex z)
Definition: zfunc.c:65
ZMAT * zHfactor(ZMAT *A, ZVEC *diag)
Definition: zhessen.c:45
ZMAT * zHQunpack(ZMAT *HQ, ZVEC *diag, ZMAT *Q, ZMAT *H)
Definition: zhessen.c:86
static char rcsid[]
Definition: zhessen.c:35
ZVEC * zhhvec(ZVEC *vec, int i0, Real *beta, ZVEC *out, complex *newval)
Definition: zhsehldr.c:49
ZMAT * zhhtrrows(ZMAT *M, int i0, int j0, ZVEC *hh, double beta)
Definition: zhsehldr.c:120
ZMAT * zhhtrcols(ZMAT *M, int i0, int j0, ZVEC *hh, double beta)
Definition: zhsehldr.c:169
ZVEC * zhhtrvec(ZVEC *hh, double beta, int i0, ZVEC *in, ZVEC *out)
Definition: zhsehldr.c:89
ZMAT * zset_col(ZMAT *mat, int col, ZVEC *vec)
Definition: zmatop.c:565
ZVEC * zget_col(ZMAT *mat, int col, ZVEC *vec)
Definition: zmatop.c:520
#define zm_copy(A, B)
Definition: zmatrix.h:264
ZVEC * zv_resize(ZVEC *x, int new_dim)
Definition: zmemory.c:362
ZMAT * zm_resize(ZMAT *A, int new_m, int new_n)
Definition: zmemory.c:227
#define ZVNULL
Definition: zmatrix.h:57
#define ZMNULL
Definition: zmatrix.h:58