Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Functions/builtin/real2fcomplex.cs @ 11316

Last change on this file since 11316 was 9102, checked in by gkronber, 12 years ago

#1967: ILNumerics source for experimentation

File size: 13.6 KB
Line 
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
40using System;
41using System.Collections.Generic;
42using System.Text;
43using ILNumerics.Storage;
44using ILNumerics.Misc;
45using ILNumerics.Exceptions;
46
47
48
49namespace ILNumerics  {
50   
51    public partial class ILMath {
52   
53
54        /// <summary>
55        /// Convert real array to fcomplex array
56        /// </summary>
57        /// <param name="A">Input array</param>
58        /// <returns>fcomplex array with A as real part, imaginary part is zero</returns>
59        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< double > A) {
60            using (ILScope.Enter(A)) {
61                int nrX = A.Size.NumberOfElements;
62                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
63                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, A.Size);
64               
65                double[] inArr = A.GetArrayForRead();
66                for (int i = 0; i < nrX; i++) {
67                    retArr[i] = new fcomplex((float)inArr[i], 0f);
68                }
69                return ret;
70            }
71        }
72        /// <summary>
73        /// Create fcomplex array out of real and imaginary parts
74        /// </summary>
75        /// <param name="real">Real array for real part</param>
76        /// <param name="imag">Real array for imaginary part</param>
77        /// <returns>fcomplex array having the real- and part imaginary parts constructed out of
78        /// real and imag.</returns>
79        /// <remarks>real and imag must have the same number of elements.
80        /// The array returned will have the same size as the input arrays.</remarks>
81        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< double > real, ILInArray< double > imag) {
82            using (ILScope.Enter(real, imag)) {
83                int nrX = real.Size.NumberOfElements;
84                if (nrX != imag.Size.NumberOfElements)
85                    throw new ILArgumentSizeException("size of real and imag input arrays must match!");
86                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
87                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, real.Size);
88               
89                double[] inArrReal = real.GetArrayForRead();
90               
91                double[] inArrImag = imag.GetArrayForRead();
92                for (int i = 0; i < nrX; i++) {
93                    retArr[i].real = (float)inArrReal[i];
94                    retArr[i].imag = (float)inArrImag[i];
95                }
96                return ret;
97            }
98        }
99
100
101#region HYCALPER AUTO GENERATED CODE
102
103        /// <summary>
104        /// Convert real array to fcomplex array
105        /// </summary>
106        /// <param name="A">Input array</param>
107        /// <returns>fcomplex array with A as real part, imaginary part is zero</returns>
108        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< byte > A) {
109            using (ILScope.Enter(A)) {
110                int nrX = A.Size.NumberOfElements;
111                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
112                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, A.Size);
113               
114                byte[] inArr = A.GetArrayForRead();
115                for (int i = 0; i < nrX; i++) {
116                    retArr[i] = new fcomplex((float)inArr[i], 0f);
117                }
118                return ret;
119            }
120        }
121        /// <summary>
122        /// Create fcomplex array out of real and imaginary parts
123        /// </summary>
124        /// <param name="real">Real array for real part</param>
125        /// <param name="imag">Real array for imaginary part</param>
126        /// <returns>fcomplex array having the real- and part imaginary parts constructed out of
127        /// real and imag.</returns>
128        /// <remarks>real and imag must have the same number of elements.
129        /// The array returned will have the same size as the input arrays.</remarks>
130        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< byte > real, ILInArray< byte > imag) {
131            using (ILScope.Enter(real, imag)) {
132                int nrX = real.Size.NumberOfElements;
133                if (nrX != imag.Size.NumberOfElements)
134                    throw new ILArgumentSizeException("size of real and imag input arrays must match!");
135                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
136                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, real.Size);
137               
138                byte[] inArrReal = real.GetArrayForRead();
139               
140                byte[] inArrImag = imag.GetArrayForRead();
141                for (int i = 0; i < nrX; i++) {
142                    retArr[i].real = (float)inArrReal[i];
143                    retArr[i].imag = (float)inArrImag[i];
144                }
145                return ret;
146            }
147        }
148
149        /// <summary>
150        /// Convert real array to fcomplex array
151        /// </summary>
152        /// <param name="A">Input array</param>
153        /// <returns>fcomplex array with A as real part, imaginary part is zero</returns>
154        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< Int64 > A) {
155            using (ILScope.Enter(A)) {
156                int nrX = A.Size.NumberOfElements;
157                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
158                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, A.Size);
159               
160                Int64[] inArr = A.GetArrayForRead();
161                for (int i = 0; i < nrX; i++) {
162                    retArr[i] = new fcomplex((float)inArr[i], 0f);
163                }
164                return ret;
165            }
166        }
167        /// <summary>
168        /// Create fcomplex array out of real and imaginary parts
169        /// </summary>
170        /// <param name="real">Real array for real part</param>
171        /// <param name="imag">Real array for imaginary part</param>
172        /// <returns>fcomplex array having the real- and part imaginary parts constructed out of
173        /// real and imag.</returns>
174        /// <remarks>real and imag must have the same number of elements.
175        /// The array returned will have the same size as the input arrays.</remarks>
176        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< Int64 > real, ILInArray< Int64 > imag) {
177            using (ILScope.Enter(real, imag)) {
178                int nrX = real.Size.NumberOfElements;
179                if (nrX != imag.Size.NumberOfElements)
180                    throw new ILArgumentSizeException("size of real and imag input arrays must match!");
181                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
182                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, real.Size);
183               
184                Int64[] inArrReal = real.GetArrayForRead();
185               
186                Int64[] inArrImag = imag.GetArrayForRead();
187                for (int i = 0; i < nrX; i++) {
188                    retArr[i].real = (float)inArrReal[i];
189                    retArr[i].imag = (float)inArrImag[i];
190                }
191                return ret;
192            }
193        }
194
195        /// <summary>
196        /// Convert real array to fcomplex array
197        /// </summary>
198        /// <param name="A">Input array</param>
199        /// <returns>fcomplex array with A as real part, imaginary part is zero</returns>
200        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< Int32 > A) {
201            using (ILScope.Enter(A)) {
202                int nrX = A.Size.NumberOfElements;
203                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
204                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, A.Size);
205               
206                Int32[] inArr = A.GetArrayForRead();
207                for (int i = 0; i < nrX; i++) {
208                    retArr[i] = new fcomplex((float)inArr[i], 0f);
209                }
210                return ret;
211            }
212        }
213        /// <summary>
214        /// Create fcomplex array out of real and imaginary parts
215        /// </summary>
216        /// <param name="real">Real array for real part</param>
217        /// <param name="imag">Real array for imaginary part</param>
218        /// <returns>fcomplex array having the real- and part imaginary parts constructed out of
219        /// real and imag.</returns>
220        /// <remarks>real and imag must have the same number of elements.
221        /// The array returned will have the same size as the input arrays.</remarks>
222        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< Int32 > real, ILInArray< Int32 > imag) {
223            using (ILScope.Enter(real, imag)) {
224                int nrX = real.Size.NumberOfElements;
225                if (nrX != imag.Size.NumberOfElements)
226                    throw new ILArgumentSizeException("size of real and imag input arrays must match!");
227                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
228                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, real.Size);
229               
230                Int32[] inArrReal = real.GetArrayForRead();
231               
232                Int32[] inArrImag = imag.GetArrayForRead();
233                for (int i = 0; i < nrX; i++) {
234                    retArr[i].real = (float)inArrReal[i];
235                    retArr[i].imag = (float)inArrImag[i];
236                }
237                return ret;
238            }
239        }
240
241        /// <summary>
242        /// Convert real array to fcomplex array
243        /// </summary>
244        /// <param name="A">Input array</param>
245        /// <returns>fcomplex array with A as real part, imaginary part is zero</returns>
246        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< float > A) {
247            using (ILScope.Enter(A)) {
248                int nrX = A.Size.NumberOfElements;
249                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
250                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, A.Size);
251               
252                float[] inArr = A.GetArrayForRead();
253                for (int i = 0; i < nrX; i++) {
254                    retArr[i] = new fcomplex((float)inArr[i], 0f);
255                }
256                return ret;
257            }
258        }
259        /// <summary>
260        /// Create fcomplex array out of real and imaginary parts
261        /// </summary>
262        /// <param name="real">Real array for real part</param>
263        /// <param name="imag">Real array for imaginary part</param>
264        /// <returns>fcomplex array having the real- and part imaginary parts constructed out of
265        /// real and imag.</returns>
266        /// <remarks>real and imag must have the same number of elements.
267        /// The array returned will have the same size as the input arrays.</remarks>
268        public static ILRetArray<fcomplex> real2fcomplex (ILInArray< float > real, ILInArray< float > imag) {
269            using (ILScope.Enter(real, imag)) {
270                int nrX = real.Size.NumberOfElements;
271                if (nrX != imag.Size.NumberOfElements)
272                    throw new ILArgumentSizeException("size of real and imag input arrays must match!");
273                fcomplex[] retArr = ILMemoryPool.Pool.New<fcomplex>(nrX);
274                ILRetArray<fcomplex> ret = new ILRetArray<fcomplex>(retArr, real.Size);
275               
276                float[] inArrReal = real.GetArrayForRead();
277               
278                float[] inArrImag = imag.GetArrayForRead();
279                for (int i = 0; i < nrX; i++) {
280                    retArr[i].real = (float)inArrReal[i];
281                    retArr[i].imag = (float)inArrImag[i];
282                }
283                return ret;
284            }
285        }
286
287
288#endregion HYCALPER AUTO GENERATED CODE
289
290    }
291
292}
Note: See TracBrowser for help on using the repository browser.