Mercurial > hg > sv-dependency-builds
comparison src/fftw-3.3.8/genfft/complex.ml @ 167:bd3cc4d1df30
Add FFTW 3.3.8 source, and a Linux build
author | Chris Cannam <cannam@all-day-breakfast.com> |
---|---|
date | Tue, 19 Nov 2019 14:52:55 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
166:cbd6d7e562c7 | 167:bd3cc4d1df30 |
---|---|
1 (* | |
2 * Copyright (c) 1997-1999 Massachusetts Institute of Technology | |
3 * Copyright (c) 2003, 2007-14 Matteo Frigo | |
4 * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 * | |
20 *) | |
21 | |
22 (* abstraction layer for complex operations *) | |
23 open Littlesimp | |
24 open Expr | |
25 | |
26 (* type of complex expressions *) | |
27 type expr = CE of Expr.expr * Expr.expr | |
28 | |
29 let two = CE (makeNum Number.two, makeNum Number.zero) | |
30 let one = CE (makeNum Number.one, makeNum Number.zero) | |
31 let i = CE (makeNum Number.zero, makeNum Number.one) | |
32 let zero = CE (makeNum Number.zero, makeNum Number.zero) | |
33 let make (r, i) = CE (r, i) | |
34 | |
35 let uminus (CE (a, b)) = CE (makeUminus a, makeUminus b) | |
36 | |
37 let inverse_int n = CE (makeNum (Number.div Number.one (Number.of_int n)), | |
38 makeNum Number.zero) | |
39 | |
40 let inverse_int_sqrt n = | |
41 CE (makeNum (Number.div Number.one (Number.sqrt (Number.of_int n))), | |
42 makeNum Number.zero) | |
43 let int_sqrt n = | |
44 CE (makeNum (Number.sqrt (Number.of_int n)), | |
45 makeNum Number.zero) | |
46 | |
47 let nan x = CE (NaN x, makeNum Number.zero) | |
48 | |
49 let half = inverse_int 2 | |
50 | |
51 let times3x3 (CE (a, b)) (CE (c, d)) = | |
52 CE (makePlus [makeTimes (c, makePlus [a; makeUminus (b)]); | |
53 makeTimes (b, makePlus [c; makeUminus (d)])], | |
54 makePlus [makeTimes (a, makePlus [c; d]); | |
55 makeUminus(makeTimes (c, makePlus [a; makeUminus (b)]))]) | |
56 | |
57 let times (CE (a, b)) (CE (c, d)) = | |
58 if not !Magic.threemult then | |
59 CE (makePlus [makeTimes (a, c); makeUminus (makeTimes (b, d))], | |
60 makePlus [makeTimes (a, d); makeTimes (b, c)]) | |
61 else if is_constant c && is_constant d then | |
62 times3x3 (CE (a, b)) (CE (c, d)) | |
63 else (* hope a and b are constant expressions *) | |
64 times3x3 (CE (c, d)) (CE (a, b)) | |
65 | |
66 let ctimes (CE (a, _)) (CE (c, _)) = | |
67 CE (CTimes (a, c), makeNum Number.zero) | |
68 | |
69 let ctimesj (CE (a, _)) (CE (c, _)) = | |
70 CE (CTimesJ (a, c), makeNum Number.zero) | |
71 | |
72 (* complex exponential (of root of unity); returns exp(2*pi*i/n * m) *) | |
73 let exp n i = | |
74 let (c, s) = Number.cexp n i | |
75 in CE (makeNum c, makeNum s) | |
76 | |
77 (* various trig functions evaluated at (2*pi*i/n * m) *) | |
78 let sec n m = | |
79 let (c, s) = Number.cexp n m | |
80 in CE (makeNum (Number.div Number.one c), makeNum Number.zero) | |
81 let csc n m = | |
82 let (c, s) = Number.cexp n m | |
83 in CE (makeNum (Number.div Number.one s), makeNum Number.zero) | |
84 let tan n m = | |
85 let (c, s) = Number.cexp n m | |
86 in CE (makeNum (Number.div s c), makeNum Number.zero) | |
87 let cot n m = | |
88 let (c, s) = Number.cexp n m | |
89 in CE (makeNum (Number.div c s), makeNum Number.zero) | |
90 | |
91 (* complex sum *) | |
92 let plus a = | |
93 let rec unzip_complex = function | |
94 [] -> ([], []) | |
95 | ((CE (a, b)) :: s) -> | |
96 let (r,i) = unzip_complex s | |
97 in | |
98 (a::r), (b::i) in | |
99 let (c, d) = unzip_complex a in | |
100 CE (makePlus c, makePlus d) | |
101 | |
102 (* extract real/imaginary *) | |
103 let real (CE (a, b)) = CE (a, makeNum Number.zero) | |
104 let imag (CE (a, b)) = CE (b, makeNum Number.zero) | |
105 let iimag (CE (a, b)) = CE (makeNum Number.zero, b) | |
106 let conj (CE (a, b)) = CE (a, makeUminus b) | |
107 | |
108 | |
109 (* abstraction of sum_{i=0}^{n-1} *) | |
110 let sigma a b f = plus (List.map f (Util.interval a b)) | |
111 | |
112 (* store and assignment operations *) | |
113 let store_real v (CE (a, b)) = Expr.Store (v, a) | |
114 let store_imag v (CE (a, b)) = Expr.Store (v, b) | |
115 let store (vr, vi) x = (store_real vr x, store_imag vi x) | |
116 | |
117 let assign_real v (CE (a, b)) = Expr.Assign (v, a) | |
118 let assign_imag v (CE (a, b)) = Expr.Assign (v, b) | |
119 let assign (vr, vi) x = (assign_real vr x, assign_imag vi x) | |
120 | |
121 | |
122 (************************ | |
123 shortcuts | |
124 ************************) | |
125 let (@*) = times | |
126 let (@+) a b = plus [a; b] | |
127 let (@-) a b = plus [a; uminus b] | |
128 | |
129 (* type of complex signals *) | |
130 type signal = int -> expr | |
131 | |
132 (* make a finite signal infinite *) | |
133 let infinite n signal i = if ((0 <= i) && (i < n)) then signal i else zero | |
134 | |
135 let hermitian n a = | |
136 Util.array n (fun i -> | |
137 if (i = 0) then real (a 0) | |
138 else if (i < n - i) then (a i) | |
139 else if (i > n - i) then conj (a (n - i)) | |
140 else real (a i)) | |
141 | |
142 let antihermitian n a = | |
143 Util.array n (fun i -> | |
144 if (i = 0) then iimag (a 0) | |
145 else if (i < n - i) then (a i) | |
146 else if (i > n - i) then uminus (conj (a (n - i))) | |
147 else iimag (a i)) |