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.Linq;
|
---|
43 | using System.Text;
|
---|
44 | using ILNumerics.Misc;
|
---|
45 | using ILNumerics.Storage;
|
---|
46 |
|
---|
47 | namespace ILNumerics {
|
---|
48 | public partial class ILMath {
|
---|
49 |
|
---|
50 | /// <summary>
|
---|
51 | /// Region creator for subarray specifications
|
---|
52 | /// </summary>
|
---|
53 | /// <param name="start">Begin of region, index of first element</param>
|
---|
54 | /// <param name="end">End of region, last element</param>
|
---|
55 | /// <returns>An array which specifies all indices of the region</returns>
|
---|
56 | /// <remarks>The r function provides a shorter way to specify regions in subarray
|
---|
57 | /// expressions. Other than alternatives like <see cref="ILNumerics.ILMath.vec"/>,
|
---|
58 | /// it also enables the use of the <see cref="ILNumerics.ILMath.end"/> keyword - even in
|
---|
59 | /// conjunction with simple mathematical expressions.</remarks>
|
---|
60 | /// <example><code>ILArray<double> A = counter(5,4,3), B;
|
---|
61 | ///
|
---|
62 | /// // the following subarrays will all create the same B:
|
---|
63 | /// B = A[full,r(1,end-1),full];
|
---|
64 | /// B = A[r(0,end),"1,2",":"];
|
---|
65 | /// B = A[":;1:2;0:end"];
|
---|
66 | ///
|
---|
67 | /// // however, these expression will <b>not</b> work:
|
---|
68 | /// B = A[":;0:end-1,:"]; // 'end' expression evaluation is not supported in strings.
|
---|
69 | /// </code></example>
|
---|
70 | public static ILBaseArray r(ILBaseArray start, ILBaseArray end) {
|
---|
71 | return r(start,1,end);
|
---|
72 | }
|
---|
73 | /// <summary>
|
---|
74 | /// Stepped region creator for subarray specifications
|
---|
75 | /// </summary>
|
---|
76 | /// <param name="start">Begin of region, index of first element</param>
|
---|
77 | /// <param name="end">End of region, last element</param>
|
---|
78 | /// <param name="step">Increment, distance between created indices</param>
|
---|
79 | /// <returns>An array which specifies the indices of the region</returns>
|
---|
80 | /// <remarks>The r function provides a shorter way to specify regions in subarray
|
---|
81 | /// expressions. Other than alternatives like <see cref="ILNumerics.ILMath.vec"/>,
|
---|
82 | /// it also enables the use of the <see cref="ILNumerics.ILMath.end"/> keyword - even in
|
---|
83 | /// conjunction with simple mathematical expressions.</remarks>
|
---|
84 | /// <example><code>ILArray<double> A = counter(5,4,3), B;
|
---|
85 | ///
|
---|
86 | /// // the following subarrays will all create the same B:
|
---|
87 | /// B = A[full,r(1,end-1),full];
|
---|
88 | /// B = A[r(0,end),"1,2",":"];
|
---|
89 | /// B = A[":;1:2;0:end"];
|
---|
90 | ///
|
---|
91 | /// // however, these expression will <b>not</b> work:
|
---|
92 | /// B = A[":;0:end-1,:"]; // 'end' expression evaluation is not supported in strings.
|
---|
93 | /// </code></example>
|
---|
94 | public static ILBaseArray r(ILBaseArray start, ILBaseArray step, ILBaseArray end) {
|
---|
95 | ILRegularRange retRange = new ILRegularRange (start, step, end);
|
---|
96 | return new ILRetArray<ILRegularRange>(new ILDenseStorage<ILRegularRange>(
|
---|
97 | new ILRegularRange[]{ retRange},ILSize.Scalar1_1));
|
---|
98 | }
|
---|
99 |
|
---|
100 | private static ILArray<ILFullRange> s_fullRange = null;
|
---|
101 | /// <summary>
|
---|
102 | /// Address the whole dimension for subarray access
|
---|
103 | /// </summary>
|
---|
104 | public static ILBaseArray full {
|
---|
105 | get {
|
---|
106 | if (object.Equals(s_fullRange, null))
|
---|
107 | s_fullRange = returnType<ILFullRange>();
|
---|
108 | return s_fullRange;
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|