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 System.Runtime.InteropServices;
|
---|
44 | using ILNumerics.Storage;
|
---|
45 | using ILNumerics.Misc;
|
---|
46 | using ILNumerics.Native;
|
---|
47 | using ILNumerics.Exceptions;
|
---|
48 |
|
---|
49 | namespace ILNumerics {
|
---|
50 |
|
---|
51 | public partial class ILMath {
|
---|
52 |
|
---|
53 | /// <summary>
|
---|
54 | /// Create double array with all elements initialized to 0
|
---|
55 | /// </summary>
|
---|
56 | /// <param name="size">Size description</param>
|
---|
57 | /// <returns>Zeros-filled array.</returns>
|
---|
58 | public static ILRetArray<double> zeros(params int[] size) {
|
---|
59 | return (ILRetArray<double>)zeros(NumericType.Double, new ILSize(size));
|
---|
60 | }
|
---|
61 | /// <summary>
|
---|
62 | /// Create double array with all elements initialized to 0
|
---|
63 | /// </summary>
|
---|
64 | /// <param name="size">Size descriptor</param>
|
---|
65 | /// <returns>Zeros-filled array.</returns>
|
---|
66 | public static ILRetArray<double> zeros(ILSize size) {
|
---|
67 | return (ILRetArray<double>)zeros(NumericType.Double, size);
|
---|
68 | }
|
---|
69 | /// <summary>
|
---|
70 | /// Create array with all elements initialized to default(T)
|
---|
71 | /// </summary>
|
---|
72 | /// <typeparam name="T">Element type</typeparam>
|
---|
73 | /// <param name="size">Size descriptor</param>
|
---|
74 | /// <returns>New array, initialized to default(T)</returns>
|
---|
75 | public static ILRetArray<T> zeros<T>(ILSize size) {
|
---|
76 | return array<T>(default(T), size);
|
---|
77 | }
|
---|
78 | /// <summary>
|
---|
79 | /// Create new array of arbitrary element type, initialized to '0'
|
---|
80 | /// </summary>
|
---|
81 | /// <typeparam name="T">Element type</typeparam>
|
---|
82 | /// <param name="size">Size description</param>
|
---|
83 | /// <returns>New array having the size determined by 'dims', initialized to '0'</returns>
|
---|
84 | /// <remarks>For T deriving from Sytem.ValueType elements will be '0'. All other element types
|
---|
85 | /// will be initialized to default(T).</remarks>
|
---|
86 | public static ILRetArray<T> zeros<T>(params int[] size) {
|
---|
87 | return array<T>(default(T), new ILSize(size));
|
---|
88 | }
|
---|
89 | /// <summary>
|
---|
90 | /// Create array initialized with all elements set to zero
|
---|
91 | /// </summary>
|
---|
92 | /// <param name="type">Numeric type specification. One value out of the types listed in the <see cred="ILNumerics.NumericType"/>
|
---|
93 | /// enum.</param>
|
---|
94 | /// <param name="size">Size descriptor</param>
|
---|
95 | /// <returns>Array of inner type corresponding to <paramref name="type"/> argument.</returns>
|
---|
96 | /// <remarks>The array returned may be casted to the appropriate actual type afterwards.
|
---|
97 | /// <para>
|
---|
98 | /// <list type="number">
|
---|
99 | /// <listheader>The following types are supported: </listheader>
|
---|
100 | /// <item>Double</item>
|
---|
101 | /// <item>Single</item>
|
---|
102 | /// <item>Complex</item>
|
---|
103 | /// <item>FComplex</item>
|
---|
104 | /// <item>Byte</item>
|
---|
105 | /// <item>Int32</item>
|
---|
106 | /// <item>Int64</item>
|
---|
107 | /// </list>
|
---|
108 | /// </para>
|
---|
109 | /// <para>This function is provided for downward compatibility reasons only and will be removed in a future update. It is recommended to use the <see cref="zeros{T}(ILSize)"/> or <see cref="zeros{T}(int[])"/> overloads instead.</para>
|
---|
110 | /// <para>The interface of this function does not confirm to the rules of functions in ILNumerics. Therefore, in order to prevent for potential memory issues, the return value should be converted to
|
---|
111 | /// a concrete array type explicitely: </para>
|
---|
112 | /// <example>
|
---|
113 | /// <code>
|
---|
114 | /// ILArray<double> A = todouble(zeros(NumericType.double, size(10,20)));
|
---|
115 | ///
|
---|
116 | /// // better and easier would be:
|
---|
117 | /// ILArray<double> B = zeros<double>(10,20);
|
---|
118 | /// </code>
|
---|
119 | /// </example>
|
---|
120 | /// </remarks>
|
---|
121 | [Obsolete("Use overload ILMath.zeros<T> instead!")]
|
---|
122 | public static ILBaseArray zeros(NumericType type, ILSize size) {
|
---|
123 | switch (type) {
|
---|
124 | case NumericType.Double:
|
---|
125 | return zeros<double>(size);
|
---|
126 | case NumericType.Single:
|
---|
127 | return zeros<float>(size);
|
---|
128 | case NumericType.Complex:
|
---|
129 | return zeros<complex>(size);
|
---|
130 | case NumericType.FComplex:
|
---|
131 | return zeros<fcomplex>(size);
|
---|
132 | case NumericType.Byte:
|
---|
133 | return zeros<byte>(size);
|
---|
134 | case NumericType.Int32:
|
---|
135 | return zeros<int>(size);
|
---|
136 | case NumericType.Int64:
|
---|
137 | return zeros<Int64>(size);
|
---|
138 | default:
|
---|
139 | return zeros<double>(size);
|
---|
140 | }
|
---|
141 | }
|
---|
142 |
|
---|
143 | }
|
---|
144 | }
|
---|