1 | ///
|
---|
2 | /// This file is part of ILNumerics Community Edition.
|
---|
3 | ///
|
---|
4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
6 | ///
|
---|
7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
9 | /// the Free Software Foundation.
|
---|
10 | ///
|
---|
11 | /// ILNumerics Community Edition 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 ILNumerics Community Edition. See the file License.txt in the root
|
---|
18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | ///
|
---|
20 | /// In addition this software uses the following components and/or licenses:
|
---|
21 | ///
|
---|
22 | /// =================================================================================
|
---|
23 | /// The Open Toolkit Library License
|
---|
24 | ///
|
---|
25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
26 | ///
|
---|
27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
29 | /// in the Software without restriction, including without limitation the rights to
|
---|
30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
32 | /// so, subject to the following conditions:
|
---|
33 | ///
|
---|
34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
35 | /// copies or substantial portions of the Software.
|
---|
36 | ///
|
---|
37 | /// =================================================================================
|
---|
38 | ///
|
---|
39 |
|
---|
40 | using System;
|
---|
41 | using System.Collections.Generic;
|
---|
42 | using System.Text;
|
---|
43 | using ILNumerics.Storage;
|
---|
44 | using ILNumerics.Misc;
|
---|
45 | using ILNumerics.Exceptions;
|
---|
46 |
|
---|
47 |
|
---|
48 |
|
---|
49 | namespace ILNumerics {
|
---|
50 | public partial class ILMath {
|
---|
51 | |
---|
52 | /// <summary>
|
---|
53 | /// Convert real array to complex array
|
---|
54 | /// </summary>
|
---|
55 | /// <param name="A">Input array</param>
|
---|
56 | /// <returns>Complex array with A as real part, imaginary part is zero</returns>
|
---|
57 | public static ILRetArray<complex> real2complex( ILInArray< double> A ) {
|
---|
58 | using (ILScope.Enter(A)) {
|
---|
59 | int nrX = A.Size.NumberOfElements;
|
---|
60 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
61 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, A.Size);
|
---|
62 |
|
---|
63 | double[] inArr = A.GetArrayForRead();
|
---|
64 | for (int i = 0; i < nrX; i++) {
|
---|
65 | retArr[i] = new complex((double)inArr[i], 0.0);
|
---|
66 | }
|
---|
67 | return ret;
|
---|
68 | }
|
---|
69 | }
|
---|
70 | /// <summary>
|
---|
71 | /// Create complex array out of real and imaginary parts
|
---|
72 | /// </summary>
|
---|
73 | /// <param name="real">Real array for real part</param>
|
---|
74 | /// <param name="imag">Real array for imaginary part</param>
|
---|
75 | /// <returns>Complex array having the real- and part imaginary parts constructed out of
|
---|
76 | /// real and imag.</returns>
|
---|
77 | /// <remarks>Real and imag must have the same number of elements.
|
---|
78 | /// The array returned will have the same size as the input arrays.</remarks>
|
---|
79 | public static ILRetArray<complex> real2complex( ILInArray< double> real, ILInArray< double> imag ) {
|
---|
80 | using (ILScope.Enter(real, imag)) {
|
---|
81 | int nrX = real.Size.NumberOfElements;
|
---|
82 | if (nrX != imag.Size.NumberOfElements)
|
---|
83 | throw new ILArgumentSizeException("size of real and imag input arrays must match!");
|
---|
84 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
85 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, real.Size);
|
---|
86 |
|
---|
87 | double[] inArrReal = real.GetArrayForRead();
|
---|
88 |
|
---|
89 | double[] inArrImag = imag.GetArrayForRead();
|
---|
90 | for (int i = 0; i < nrX; i++) {
|
---|
91 | retArr[i].real = (double)inArrReal[i];
|
---|
92 | retArr[i].imag = (double)inArrImag[i];
|
---|
93 | }
|
---|
94 | return ret;
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | |
---|
99 | #region HYCALPER AUTO GENERATED CODE
|
---|
100 | |
---|
101 | /// <summary>
|
---|
102 | /// Convert real array to complex array
|
---|
103 | /// </summary>
|
---|
104 | /// <param name="A">Input array</param>
|
---|
105 | /// <returns>Complex array with A as real part, imaginary part is zero</returns>
|
---|
106 | public static ILRetArray<complex> real2complex( ILInArray< byte> A ) {
|
---|
107 | using (ILScope.Enter(A)) {
|
---|
108 | int nrX = A.Size.NumberOfElements;
|
---|
109 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
110 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, A.Size);
|
---|
111 |
|
---|
112 | byte[] inArr = A.GetArrayForRead();
|
---|
113 | for (int i = 0; i < nrX; i++) {
|
---|
114 | retArr[i] = new complex((double)inArr[i], 0.0);
|
---|
115 | }
|
---|
116 | return ret;
|
---|
117 | }
|
---|
118 | }
|
---|
119 | /// <summary>
|
---|
120 | /// Create complex array out of real and imaginary parts
|
---|
121 | /// </summary>
|
---|
122 | /// <param name="real">Real array for real part</param>
|
---|
123 | /// <param name="imag">Real array for imaginary part</param>
|
---|
124 | /// <returns>Complex array having the real- and part imaginary parts constructed out of
|
---|
125 | /// real and imag.</returns>
|
---|
126 | /// <remarks>Real and imag must have the same number of elements.
|
---|
127 | /// The array returned will have the same size as the input arrays.</remarks>
|
---|
128 | public static ILRetArray<complex> real2complex( ILInArray< byte> real, ILInArray< byte> imag ) {
|
---|
129 | using (ILScope.Enter(real, imag)) {
|
---|
130 | int nrX = real.Size.NumberOfElements;
|
---|
131 | if (nrX != imag.Size.NumberOfElements)
|
---|
132 | throw new ILArgumentSizeException("size of real and imag input arrays must match!");
|
---|
133 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
134 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, real.Size);
|
---|
135 |
|
---|
136 | byte[] inArrReal = real.GetArrayForRead();
|
---|
137 |
|
---|
138 | byte[] inArrImag = imag.GetArrayForRead();
|
---|
139 | for (int i = 0; i < nrX; i++) {
|
---|
140 | retArr[i].real = (double)inArrReal[i];
|
---|
141 | retArr[i].imag = (double)inArrImag[i];
|
---|
142 | }
|
---|
143 | return ret;
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | /// <summary>
|
---|
148 | /// Convert real array to complex array
|
---|
149 | /// </summary>
|
---|
150 | /// <param name="A">Input array</param>
|
---|
151 | /// <returns>Complex array with A as real part, imaginary part is zero</returns>
|
---|
152 | public static ILRetArray<complex> real2complex( ILInArray< Int64> A ) {
|
---|
153 | using (ILScope.Enter(A)) {
|
---|
154 | int nrX = A.Size.NumberOfElements;
|
---|
155 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
156 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, A.Size);
|
---|
157 |
|
---|
158 | Int64[] inArr = A.GetArrayForRead();
|
---|
159 | for (int i = 0; i < nrX; i++) {
|
---|
160 | retArr[i] = new complex((double)inArr[i], 0.0);
|
---|
161 | }
|
---|
162 | return ret;
|
---|
163 | }
|
---|
164 | }
|
---|
165 | /// <summary>
|
---|
166 | /// Create complex array out of real and imaginary parts
|
---|
167 | /// </summary>
|
---|
168 | /// <param name="real">Real array for real part</param>
|
---|
169 | /// <param name="imag">Real array for imaginary part</param>
|
---|
170 | /// <returns>Complex array having the real- and part imaginary parts constructed out of
|
---|
171 | /// real and imag.</returns>
|
---|
172 | /// <remarks>Real and imag must have the same number of elements.
|
---|
173 | /// The array returned will have the same size as the input arrays.</remarks>
|
---|
174 | public static ILRetArray<complex> real2complex( ILInArray< Int64> real, ILInArray< Int64> imag ) {
|
---|
175 | using (ILScope.Enter(real, imag)) {
|
---|
176 | int nrX = real.Size.NumberOfElements;
|
---|
177 | if (nrX != imag.Size.NumberOfElements)
|
---|
178 | throw new ILArgumentSizeException("size of real and imag input arrays must match!");
|
---|
179 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
180 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, real.Size);
|
---|
181 |
|
---|
182 | Int64[] inArrReal = real.GetArrayForRead();
|
---|
183 |
|
---|
184 | Int64[] inArrImag = imag.GetArrayForRead();
|
---|
185 | for (int i = 0; i < nrX; i++) {
|
---|
186 | retArr[i].real = (double)inArrReal[i];
|
---|
187 | retArr[i].imag = (double)inArrImag[i];
|
---|
188 | }
|
---|
189 | return ret;
|
---|
190 | }
|
---|
191 | }
|
---|
192 |
|
---|
193 | /// <summary>
|
---|
194 | /// Convert real array to complex array
|
---|
195 | /// </summary>
|
---|
196 | /// <param name="A">Input array</param>
|
---|
197 | /// <returns>Complex array with A as real part, imaginary part is zero</returns>
|
---|
198 | public static ILRetArray<complex> real2complex( ILInArray< Int32> A ) {
|
---|
199 | using (ILScope.Enter(A)) {
|
---|
200 | int nrX = A.Size.NumberOfElements;
|
---|
201 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
202 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, A.Size);
|
---|
203 |
|
---|
204 | Int32[] inArr = A.GetArrayForRead();
|
---|
205 | for (int i = 0; i < nrX; i++) {
|
---|
206 | retArr[i] = new complex((double)inArr[i], 0.0);
|
---|
207 | }
|
---|
208 | return ret;
|
---|
209 | }
|
---|
210 | }
|
---|
211 | /// <summary>
|
---|
212 | /// Create complex array out of real and imaginary parts
|
---|
213 | /// </summary>
|
---|
214 | /// <param name="real">Real array for real part</param>
|
---|
215 | /// <param name="imag">Real array for imaginary part</param>
|
---|
216 | /// <returns>Complex array having the real- and part imaginary parts constructed out of
|
---|
217 | /// real and imag.</returns>
|
---|
218 | /// <remarks>Real and imag must have the same number of elements.
|
---|
219 | /// The array returned will have the same size as the input arrays.</remarks>
|
---|
220 | public static ILRetArray<complex> real2complex( ILInArray< Int32> real, ILInArray< Int32> imag ) {
|
---|
221 | using (ILScope.Enter(real, imag)) {
|
---|
222 | int nrX = real.Size.NumberOfElements;
|
---|
223 | if (nrX != imag.Size.NumberOfElements)
|
---|
224 | throw new ILArgumentSizeException("size of real and imag input arrays must match!");
|
---|
225 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
226 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, real.Size);
|
---|
227 |
|
---|
228 | Int32[] inArrReal = real.GetArrayForRead();
|
---|
229 |
|
---|
230 | Int32[] inArrImag = imag.GetArrayForRead();
|
---|
231 | for (int i = 0; i < nrX; i++) {
|
---|
232 | retArr[i].real = (double)inArrReal[i];
|
---|
233 | retArr[i].imag = (double)inArrImag[i];
|
---|
234 | }
|
---|
235 | return ret;
|
---|
236 | }
|
---|
237 | }
|
---|
238 |
|
---|
239 | /// <summary>
|
---|
240 | /// Convert real array to complex array
|
---|
241 | /// </summary>
|
---|
242 | /// <param name="A">Input array</param>
|
---|
243 | /// <returns>Complex array with A as real part, imaginary part is zero</returns>
|
---|
244 | public static ILRetArray<complex> real2complex( ILInArray< float> A ) {
|
---|
245 | using (ILScope.Enter(A)) {
|
---|
246 | int nrX = A.Size.NumberOfElements;
|
---|
247 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
248 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, A.Size);
|
---|
249 |
|
---|
250 | float[] inArr = A.GetArrayForRead();
|
---|
251 | for (int i = 0; i < nrX; i++) {
|
---|
252 | retArr[i] = new complex((double)inArr[i], 0.0);
|
---|
253 | }
|
---|
254 | return ret;
|
---|
255 | }
|
---|
256 | }
|
---|
257 | /// <summary>
|
---|
258 | /// Create complex array out of real and imaginary parts
|
---|
259 | /// </summary>
|
---|
260 | /// <param name="real">Real array for real part</param>
|
---|
261 | /// <param name="imag">Real array for imaginary part</param>
|
---|
262 | /// <returns>Complex array having the real- and part imaginary parts constructed out of
|
---|
263 | /// real and imag.</returns>
|
---|
264 | /// <remarks>Real and imag must have the same number of elements.
|
---|
265 | /// The array returned will have the same size as the input arrays.</remarks>
|
---|
266 | public static ILRetArray<complex> real2complex( ILInArray< float> real, ILInArray< float> imag ) {
|
---|
267 | using (ILScope.Enter(real, imag)) {
|
---|
268 | int nrX = real.Size.NumberOfElements;
|
---|
269 | if (nrX != imag.Size.NumberOfElements)
|
---|
270 | throw new ILArgumentSizeException("size of real and imag input arrays must match!");
|
---|
271 | complex[] retArr = ILMemoryPool.Pool.New<complex>(nrX);
|
---|
272 | ILRetArray<complex> ret = new ILRetArray<complex>(retArr, real.Size);
|
---|
273 |
|
---|
274 | float[] inArrReal = real.GetArrayForRead();
|
---|
275 |
|
---|
276 | float[] inArrImag = imag.GetArrayForRead();
|
---|
277 | for (int i = 0; i < nrX; i++) {
|
---|
278 | retArr[i].real = (double)inArrReal[i];
|
---|
279 | retArr[i].imag = (double)inArrImag[i];
|
---|
280 | }
|
---|
281 | return ret;
|
---|
282 | }
|
---|
283 | }
|
---|
284 |
|
---|
285 |
|
---|
286 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
287 | }
|
---|
288 |
|
---|
289 | }
|
---|