Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Functions/builtin/meshgrid.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: 14.7 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.Misc;
44using ILNumerics.Exceptions;
45
46
47namespace ILNumerics {
48
49    public partial class ILMath {
50
51        /// <summary>
52        /// Create two matrices for evaluation and visualization of 2 dimensional functions
53        /// </summary>
54        /// <param name="X">Vector of x values</param>
55        /// <param name="Y">Vector of y values</param>
56        /// <param name="outY">[Output, Optional]: if on entry outY is not null, on return it will hold the values for the Y dimension</param>
57        /// <returns>X values matrix along the values of the X input array. Corresponding values for Y are returned in outY</returns>
58        /// <remarks>The matrices returned can be utilize to evaluate and visualize functions of 2 variables X and Y.</remarks>
59        public static ILRetArray< double > meshgrid(ILInArray< double > X, ILInArray< double > Y
60                                                                  , ILOutArray< double > outY = null)
61        {
62            using (ILScope.Enter(X,Y)) {
63                if (!X.IsVector || !Y.IsVector)
64                {
65                    throw new ILArgumentException("inputs must be vectors");
66                }
67                if (!X.IsRowVector) X = X.T;
68                if (!Y.IsColumnVector) Y = Y.T;
69                ILArray< double > ret = repmat(X,Y.Length,1);
70                if (!isnull(outY))
71                    outY.a = repmat(Y,1,X.Length);
72                return ret;
73            }
74        }
75
76        /// <summary>
77        /// Create 3d arrays for evaluation and visualization of 3 dimensional functions
78        /// </summary>
79        /// <param name="X">Vector of x values</param>
80        /// <param name="Y">Vector of y values</param>
81        /// <param name="Z">Vector of z values</param>
82        /// <param name="outY">[Output, Optional] If on entry outY is not null, on return it will hold the values for the y dimension</param>
83        /// <param name="outZ">[Output, Optional] If on entry outZ is not null, on return it will hold the values for the z dimension</param>
84        /// <returns>X value array along the values of the X input vector, arrays for y and z dimensions are returned in outY and outZ respectively</returns>
85        /// <remarks>The arrays returned can be used to evaluate and visualize functions of 3 variables X, Y and Z.</remarks>
86        public static ILRetArray< double > meshgrid(ILInArray< double > X, ILInArray< double > Y, ILInArray< double > Z
87                                                                ,ILOutArray< double > outY = null, ILOutArray< double > outZ = null)
88        {
89            using (ILScope.Enter()) {
90                if (!X.IsVector || !Y.IsVector || !Z.IsVector)
91                {
92                    throw new ILArgumentException("inputs must be vectors");
93                }
94                if (!X.IsRowVector) X = X.T;
95                if (!Y.IsColumnVector) Y = Y.T; 
96                Z = Z[full].Reshape(new ILSize(1,1,Z.Size.NumberOfElements));
97
98                ILArray< double > ret = repmat(X,Y.Length,1,Z.Length);
99                if (!isnull(outY)) outY.a = repmat(Y,1,X.Length,Z.Length);
100                if (!isnull(outZ)) outZ.a = repmat(Z, Y.Length, X.Length, 1);
101                return ret;
102            }
103        }
104
105#region HYCALPER AUTO GENERATED CODE
106
107        /// <summary>
108        /// Create two matrices for evaluation and visualization of 2 dimensional functions
109        /// </summary>
110        /// <param name="X">Vector of x values</param>
111        /// <param name="Y">Vector of y values</param>
112        /// <param name="outY">[Output, Optional]: if on entry outY is not null, on return it will hold the values for the Y dimension</param>
113        /// <returns>X values matrix along the values of the X input array. Corresponding values for Y are returned in outY</returns>
114        /// <remarks>The matrices returned can be utilize to evaluate and visualize functions of 2 variables X and Y.</remarks>
115        public static ILRetArray< Int64 > meshgrid(ILInArray< Int64 > X, ILInArray< Int64 > Y
116                                                                  , ILOutArray< Int64 > outY = null)
117        {
118            using (ILScope.Enter(X,Y)) {
119                if (!X.IsVector || !Y.IsVector)
120                {
121                    throw new ILArgumentException("inputs must be vectors");
122                }
123                if (!X.IsRowVector) X = X.T;
124                if (!Y.IsColumnVector) Y = Y.T;
125                ILArray< Int64 > ret = repmat(X,Y.Length,1);
126                if (!isnull(outY))
127                    outY.a = repmat(Y,1,X.Length);
128                return ret;
129            }
130        }
131
132        /// <summary>
133        /// Create 3d arrays for evaluation and visualization of 3 dimensional functions
134        /// </summary>
135        /// <param name="X">Vector of x values</param>
136        /// <param name="Y">Vector of y values</param>
137        /// <param name="Z">Vector of z values</param>
138        /// <param name="outY">[Output, Optional] If on entry outY is not null, on return it will hold the values for the y dimension</param>
139        /// <param name="outZ">[Output, Optional] If on entry outZ is not null, on return it will hold the values for the z dimension</param>
140        /// <returns>X value array along the values of the X input vector, arrays for y and z dimensions are returned in outY and outZ respectively</returns>
141        /// <remarks>The arrays returned can be used to evaluate and visualize functions of 3 variables X, Y and Z.</remarks>
142        public static ILRetArray< Int64 > meshgrid(ILInArray< Int64 > X, ILInArray< Int64 > Y, ILInArray< Int64 > Z
143                                                                ,ILOutArray< Int64 > outY = null, ILOutArray< Int64 > outZ = null)
144        {
145            using (ILScope.Enter()) {
146                if (!X.IsVector || !Y.IsVector || !Z.IsVector)
147                {
148                    throw new ILArgumentException("inputs must be vectors");
149                }
150                if (!X.IsRowVector) X = X.T;
151                if (!Y.IsColumnVector) Y = Y.T; 
152                Z = Z[full].Reshape(new ILSize(1,1,Z.Size.NumberOfElements));
153
154                ILArray< Int64 > ret = repmat(X,Y.Length,1,Z.Length);
155                if (!isnull(outY)) outY.a = repmat(Y,1,X.Length,Z.Length);
156                if (!isnull(outZ)) outZ.a = repmat(Z, Y.Length, X.Length, 1);
157                return ret;
158            }
159        }
160        /// <summary>
161        /// Create two matrices for evaluation and visualization of 2 dimensional functions
162        /// </summary>
163        /// <param name="X">Vector of x values</param>
164        /// <param name="Y">Vector of y values</param>
165        /// <param name="outY">[Output, Optional]: if on entry outY is not null, on return it will hold the values for the Y dimension</param>
166        /// <returns>X values matrix along the values of the X input array. Corresponding values for Y are returned in outY</returns>
167        /// <remarks>The matrices returned can be utilize to evaluate and visualize functions of 2 variables X and Y.</remarks>
168        public static ILRetArray< Int32 > meshgrid(ILInArray< Int32 > X, ILInArray< Int32 > Y
169                                                                  , ILOutArray< Int32 > outY = null)
170        {
171            using (ILScope.Enter(X,Y)) {
172                if (!X.IsVector || !Y.IsVector)
173                {
174                    throw new ILArgumentException("inputs must be vectors");
175                }
176                if (!X.IsRowVector) X = X.T;
177                if (!Y.IsColumnVector) Y = Y.T;
178                ILArray< Int32 > ret = repmat(X,Y.Length,1);
179                if (!isnull(outY))
180                    outY.a = repmat(Y,1,X.Length);
181                return ret;
182            }
183        }
184
185        /// <summary>
186        /// Create 3d arrays for evaluation and visualization of 3 dimensional functions
187        /// </summary>
188        /// <param name="X">Vector of x values</param>
189        /// <param name="Y">Vector of y values</param>
190        /// <param name="Z">Vector of z values</param>
191        /// <param name="outY">[Output, Optional] If on entry outY is not null, on return it will hold the values for the y dimension</param>
192        /// <param name="outZ">[Output, Optional] If on entry outZ is not null, on return it will hold the values for the z dimension</param>
193        /// <returns>X value array along the values of the X input vector, arrays for y and z dimensions are returned in outY and outZ respectively</returns>
194        /// <remarks>The arrays returned can be used to evaluate and visualize functions of 3 variables X, Y and Z.</remarks>
195        public static ILRetArray< Int32 > meshgrid(ILInArray< Int32 > X, ILInArray< Int32 > Y, ILInArray< Int32 > Z
196                                                                ,ILOutArray< Int32 > outY = null, ILOutArray< Int32 > outZ = null)
197        {
198            using (ILScope.Enter()) {
199                if (!X.IsVector || !Y.IsVector || !Z.IsVector)
200                {
201                    throw new ILArgumentException("inputs must be vectors");
202                }
203                if (!X.IsRowVector) X = X.T;
204                if (!Y.IsColumnVector) Y = Y.T; 
205                Z = Z[full].Reshape(new ILSize(1,1,Z.Size.NumberOfElements));
206
207                ILArray< Int32 > ret = repmat(X,Y.Length,1,Z.Length);
208                if (!isnull(outY)) outY.a = repmat(Y,1,X.Length,Z.Length);
209                if (!isnull(outZ)) outZ.a = repmat(Z, Y.Length, X.Length, 1);
210                return ret;
211            }
212        }
213        /// <summary>
214        /// Create two matrices for evaluation and visualization of 2 dimensional functions
215        /// </summary>
216        /// <param name="X">Vector of x values</param>
217        /// <param name="Y">Vector of y values</param>
218        /// <param name="outY">[Output, Optional]: if on entry outY is not null, on return it will hold the values for the Y dimension</param>
219        /// <returns>X values matrix along the values of the X input array. Corresponding values for Y are returned in outY</returns>
220        /// <remarks>The matrices returned can be utilize to evaluate and visualize functions of 2 variables X and Y.</remarks>
221        public static ILRetArray< float > meshgrid(ILInArray< float > X, ILInArray< float > Y
222                                                                  , ILOutArray< float > outY = null)
223        {
224            using (ILScope.Enter(X,Y)) {
225                if (!X.IsVector || !Y.IsVector)
226                {
227                    throw new ILArgumentException("inputs must be vectors");
228                }
229                if (!X.IsRowVector) X = X.T;
230                if (!Y.IsColumnVector) Y = Y.T;
231                ILArray< float > ret = repmat(X,Y.Length,1);
232                if (!isnull(outY))
233                    outY.a = repmat(Y,1,X.Length);
234                return ret;
235            }
236        }
237
238        /// <summary>
239        /// Create 3d arrays for evaluation and visualization of 3 dimensional functions
240        /// </summary>
241        /// <param name="X">Vector of x values</param>
242        /// <param name="Y">Vector of y values</param>
243        /// <param name="Z">Vector of z values</param>
244        /// <param name="outY">[Output, Optional] If on entry outY is not null, on return it will hold the values for the y dimension</param>
245        /// <param name="outZ">[Output, Optional] If on entry outZ is not null, on return it will hold the values for the z dimension</param>
246        /// <returns>X value array along the values of the X input vector, arrays for y and z dimensions are returned in outY and outZ respectively</returns>
247        /// <remarks>The arrays returned can be used to evaluate and visualize functions of 3 variables X, Y and Z.</remarks>
248        public static ILRetArray< float > meshgrid(ILInArray< float > X, ILInArray< float > Y, ILInArray< float > Z
249                                                                ,ILOutArray< float > outY = null, ILOutArray< float > outZ = null)
250        {
251            using (ILScope.Enter()) {
252                if (!X.IsVector || !Y.IsVector || !Z.IsVector)
253                {
254                    throw new ILArgumentException("inputs must be vectors");
255                }
256                if (!X.IsRowVector) X = X.T;
257                if (!Y.IsColumnVector) Y = Y.T; 
258                Z = Z[full].Reshape(new ILSize(1,1,Z.Size.NumberOfElements));
259
260                ILArray< float > ret = repmat(X,Y.Length,1,Z.Length);
261                if (!isnull(outY)) outY.a = repmat(Y,1,X.Length,Z.Length);
262                if (!isnull(outZ)) outZ.a = repmat(Z, Y.Length, X.Length, 1);
263                return ret;
264            }
265        }
266
267#endregion HYCALPER AUTO GENERATED CODE
268   }
269}
Note: See TracBrowser for help on using the repository browser.