NEURON
zmachine.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  This file contains basic routines which are used by the functions
30  involving complex vectors.
31  These are the routines that should be modified in order to take
32  full advantage of specialised architectures (pipelining, vector
33  processors etc).
34  */
35 static char *rcsid = "zmachine.c,v 1.1 1997/12/04 17:56:10 hines Exp";
36 
37 #include "machine.h"
38 #include "zmatrix.h"
39 #include <math.h>
40 
41 
42 /* __zconj__ -- complex conjugate */
43 void __zconj__(zp,len)
44 complex *zp;
45 int len;
46 {
47  int i;
48 
49  for ( i = 0; i < len; i++ )
50  zp[i].im = - zp[i].im;
51 }
52 
53 /* __zip__ -- inner product
54  -- computes sum_i zp1[i].zp2[i] if flag == 0
55  sum_i zp1[i]*.zp2[i] if flag != 0 */
56 complex __zip__(zp1,zp2,len,flag)
57 complex *zp1, *zp2;
58 int flag, len;
59 {
60  complex sum;
61  int i;
62 
63  sum.re = sum.im = 0.0;
64  if ( flag )
65  {
66  for ( i = 0; i < len; i++ )
67  {
68  sum.re += zp1[i].re*zp2[i].re + zp1[i].im*zp2[i].im;
69  sum.im += zp1[i].re*zp2[i].im - zp1[i].im*zp2[i].re;
70  }
71  }
72  else
73  {
74  for ( i = 0; i < len; i++ )
75  {
76  sum.re += zp1[i].re*zp2[i].re - zp1[i].im*zp2[i].im;
77  sum.im += zp1[i].re*zp2[i].im + zp1[i].im*zp2[i].re;
78  }
79  }
80 
81  return sum;
82 }
83 
84 /* __zmltadd__ -- scalar multiply and add i.e. complex saxpy
85  -- computes zp1[i] += s.zp2[i] if flag == 0
86  -- computes zp1[i] += s.zp2[i]* if flag != 0 */
87 void __zmltadd__(zp1,zp2,s,len,flag)
88 complex *zp1, *zp2, s;
89 int flag, len;
90 {
91  int i;
92  LongReal t_re, t_im;
93 
94  if ( ! flag )
95  {
96  for ( i = 0; i < len; i++ )
97  {
98  t_re = zp1[i].re + s.re*zp2[i].re - s.im*zp2[i].im;
99  t_im = zp1[i].im + s.re*zp2[i].im + s.im*zp2[i].re;
100  zp1[i].re = t_re;
101  zp1[i].im = t_im;
102  }
103  }
104  else
105  {
106  for ( i = 0; i < len; i++ )
107  {
108  t_re = zp1[i].re + s.re*zp2[i].re + s.im*zp2[i].im;
109  t_im = zp1[i].im - s.re*zp2[i].im + s.im*zp2[i].re;
110  zp1[i].re = t_re;
111  zp1[i].im = t_im;
112  }
113  }
114 }
115 
116 /* __zmlt__ scalar complex multiply array c.f. sv_mlt() */
117 void __zmlt__(zp,s,out,len)
118 complex *zp, s, *out;
119 register int len;
120 {
121  int i;
122  LongReal t_re, t_im;
123 
124  for ( i = 0; i < len; i++ )
125  {
126  t_re = s.re*zp[i].re - s.im*zp[i].im;
127  t_im = s.re*zp[i].im + s.im*zp[i].re;
128  out[i].re = t_re;
129  out[i].im = t_im;
130  }
131 }
132 
133 /* __zadd__ -- add complex arrays c.f. v_add() */
134 void __zadd__(zp1,zp2,out,len)
135 complex *zp1, *zp2, *out;
136 int len;
137 {
138  int i;
139  for ( i = 0; i < len; i++ )
140  {
141  out[i].re = zp1[i].re + zp2[i].re;
142  out[i].im = zp1[i].im + zp2[i].im;
143  }
144 }
145 
146 /* __zsub__ -- subtract complex arrays c.f. v_sub() */
147 void __zsub__(zp1,zp2,out,len)
148 complex *zp1, *zp2, *out;
149 int len;
150 {
151  int i;
152  for ( i = 0; i < len; i++ )
153  {
154  out[i].re = zp1[i].re - zp2[i].re;
155  out[i].im = zp1[i].im - zp2[i].im;
156  }
157 }
158 
159 /* __zzero__ -- zeros an array of complex numbers */
160 void __zzero__(zp,len)
161 complex *zp;
162 int len;
163 {
164  /* if a Real precision zero is equivalent to a string of nulls */
165  MEM_ZERO((char *)zp,len*sizeof(complex));
166  /* else, need to zero the array entry by entry */
167  /******************************
168  while ( len-- )
169  {
170  zp->re = zp->im = 0.0;
171  zp++;
172  }
173  ******************************/
174 }
175 
void MEM_ZERO(char *ptr, int len)
Definition: extras.c:58
#define LongReal
Definition: machine.h:190
#define i
Definition: md1redef.h:12
Real re
Definition: zmatrix.h:40
Real im
Definition: zmatrix.h:40
void __zsub__(complex *zp1, complex *zp2, complex *out, int len)
Definition: zmachine.c:147
void __zadd__(complex *zp1, complex *zp2, complex *out, int len)
Definition: zmachine.c:134
void __zzero__(complex *zp, int len)
Definition: zmachine.c:160
void __zconj__(complex *zp, int len)
Definition: zmachine.c:43
complex __zip__(complex *zp1, complex *zp2, int len, int flag)
Definition: zmachine.c:56
void __zmltadd__(complex *zp1, complex *zp2, complex s, int len, int flag)
Definition: zmachine.c:87
void __zmlt__(complex *zp, complex s, complex *out, int len)
Definition: zmachine.c:117
static char * rcsid
Definition: zmachine.c:35