Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GaussianProcessTuning/ILNumerics.2.14.4735.573/Functions/builtin/cell.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: 7.3 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.Linq;
43using System.Text;
44using ILNumerics.Misc;
45using ILNumerics.Storage;
46
47namespace ILNumerics {
48    // ToDo: DOKU two overloads undocumented
49    public partial class ILMath {
50
51        /// <summary>
52        /// Create a cell row vector from given arrays
53        /// </summary>
54        /// <param name="arrays">Arrays to be copied inside the cell</param>
55        /// <returns>Cell vector</returns>
56        /// <remarks><para>The new cell will be created as vector, having the array 'values' given as parameter as cell elements. Those elements will
57        /// be protected by changes from outside the cell.</para>
58        /// <para>Visit the <a href="http://ilnumerics.net/$Cells.html" target="ILMain">online documentation</a> for cell.</para></remarks>
59        /// <example>
60        /// <para>A common use of the <c>cell</c> function is the concatenation of arrays and constants for subarray definitions, as shown in the following example:</para>
61        /// <code>
62        /// ILArray&lt;double> A = counter(4,3,2);
63        /// A
64        /// //&lt;Double> [4,3]
65        /// // 1          5          9
66        /// // 2          6         10
67        /// // 3          7         11
68        /// // 4          8         12
69        ///
70        /// // extract 1st, 2nd and last row:
71        /// ILArray&lt;double> B = A[cell(0,1,end),full];
72        /// B
73        /// //&lt;Double> [3,3]
74        /// // 1          5          9
75        /// // 2          6         10
76        /// // 4          8         12
77        /// </code>
78        /// <para>Here, <c>cell</c> is used to concatenate individual indices determining the rows to select for the subarray. Using a cell here is convenient, because arbitrary types
79        /// can be stored in cells - integer, floating point types or special placeholders, like expressions (<see cref="ILNumerics.ILMath.end"/> and <see cref="ILNumerics.ILMath.full"/>).</para>
80        /// </example>
81        public static ILRetCell cell(params ILBaseArray[] arrays) {
82            using (ILScope.Enter(arrays)) {
83                if (arrays == null)
84                    return cell(ILSize.Empty00);
85                if (Settings.CreateRowVectorsByDefault) {
86                    return cell(new ILSize(1, arrays.Length), arrays);
87                } else {
88                    return cell(new ILSize(arrays.Length, 1), arrays);
89                }
90            }
91        }
92        /// <summary>
93        /// Create cell, initialize with arrays and size
94        /// </summary>
95        /// <param name="size">Size of the new cell</param>
96        /// <param name="arrays">List of arrays for the cell elements, column major order</param>
97        /// <returns>Cell of specified size, initialized with arrays</returns>
98        /// <remarks>If number of arrays given is smaller than the number of elements given by <paramref name="size"/>, trailing
99        /// elements in the cell returned will be set to null.
100        /// <para>The <see cref="M:ILNumerics_ILMath_size(params int[])"/> function is convenient for the specification of size descriptors.</para>
101        /// <para>Visit the <a href="http://ilnumerics.net/$Cells.html" target="ILMain">online documentation</a> for cell.</para></remarks>
102        /// <example>
103        /// <code>
104        /// ILArray&lt;double> A = rand(10,20,30);
105        /// ILCell C = cell(size(3,2),A, A+1, zeros(2,3));
106        /// C
107        /// //Cell [3,2]
108        /// // &lt;Double> [10,20,30]          &lt;String>        4th element 
109        /// // &lt;Double> [10,20,30]                                 (null)
110        /// // &lt;Double> [2,3]                                      (null)
111        /// </code>
112        /// </example>
113        public static ILRetCell cell(ILSize size, params ILBaseArray[] arrays) {
114            using (ILScope.Enter(arrays)) {
115                if (object.Equals(arrays, null) || arrays.Length == 0) {
116                    return new ILRetCell(new ILCellStorage(size));
117                }
118                return new ILRetCell(new ILCellStorage(arrays, size));
119            }
120        }
121        /// <summary>
122        /// Create cell, initialize with arrays and size
123        /// </summary>
124        /// <param name="arrays">Predefined array with arrays, directly be used as new cell element storage</param>
125        /// <param name="size">Size of newly created cell</param>
126        /// <returns>Cell with size of <paramref name="size"/> and elements from <paramref name="arrays"/></returns>
127        /// <remarks>The array given in <paramref name="arrays"/> is directly be used for the newly created cell. Make sure, not
128        /// to reference the system array afterwards. However, arrays  referenced from within the parameter <paramref name="arrays"/>
129        /// are stored as clone into the new cell. Therefore, those arrays are properly protected from changes by altering any array outside the cell.
130        /// <para>Visit the <a href="http://ilnumerics.net/$Cells.html" target="ILMain">online documentation</a> for cell.</para></remarks>
131        /// <seealso cref="ILNumerics.ILMath.cell(ILNumerics.ILBaseArray[])"/>
132        public static ILRetCell cell(ILBaseArray[] arrays, params int[] size) {
133            using (ILScope.Enter(arrays)) {
134                return cell(new ILSize(size), arrays);
135            }
136        }
137    }
138}
Note: See TracBrowser for help on using the repository browser.