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 new double array, set initial values to 1
|
---|
55 | /// </summary>
|
---|
56 | /// <returns>array</returns>
|
---|
57 | public static ILRetArray<double> ones(params int[] dimensions) {
|
---|
58 | return (ILRetArray<double>)ones(NumericType.Double, new ILSize(dimensions));
|
---|
59 | }
|
---|
60 | /// <summary>
|
---|
61 | /// Create array initialized with all elements set to one
|
---|
62 | /// </summary>
|
---|
63 | /// <param name="type">Numeric type specification. One value out of the types listed in the <see cred="ILNumerics.NumericType"/>
|
---|
64 | /// enum.</param>
|
---|
65 | /// <param name="size">Size descriptor</param>
|
---|
66 | /// <returns>Array of inner type corresponding to <paramref name="type"/> argument.</returns>
|
---|
67 | /// <remarks>The array returned must be casted to the appropriate actual type afterwards and assigned to a concrete array! Caution:
|
---|
68 | /// This overload is provided for compatibility reasons only! Use <see cref="ones{T}(ILSize)"/> instead.
|
---|
69 | /// <para>
|
---|
70 | /// <list type="number">
|
---|
71 | /// <listheader>The following types are supported: </listheader>
|
---|
72 | /// <item>Double</item>
|
---|
73 | /// <item>Single</item>
|
---|
74 | /// <item>Complex</item>
|
---|
75 | /// <item>FComplex</item>
|
---|
76 | /// <item>Byte</item>
|
---|
77 | /// <item>Int32</item>
|
---|
78 | /// <item>Int64</item>
|
---|
79 | /// </list>
|
---|
80 | /// </para>
|
---|
81 | /// </remarks>
|
---|
82 | public static ILBaseArray ones(NumericType type, ILSize size) {
|
---|
83 | switch (type) {
|
---|
84 | case NumericType.Double:
|
---|
85 | return array<double>(1.0, size);
|
---|
86 | case NumericType.Single:
|
---|
87 | return array<float>(1f, size);
|
---|
88 | case NumericType.Complex:
|
---|
89 | return array<complex>(new complex(1, 0), size);
|
---|
90 | case NumericType.FComplex:
|
---|
91 | return array<fcomplex>(new fcomplex(1f, 0f), size);
|
---|
92 | case NumericType.Byte:
|
---|
93 | return array<byte>(1, size);
|
---|
94 | case NumericType.Int32:
|
---|
95 | return array<int>(1, size).T;
|
---|
96 | case NumericType.Int64:
|
---|
97 | return array<long>(1, size);
|
---|
98 | }
|
---|
99 | return null;
|
---|
100 | }
|
---|
101 | /// <summary>
|
---|
102 | /// Create array initialized with all elements set to one
|
---|
103 | /// </summary>
|
---|
104 | /// <typeparam name="T">Numeric type specification.</typeparam>
|
---|
105 | /// <param name="size">Size descriptor</param>
|
---|
106 | /// <returns>Array of inner type corresponding to the given type.</returns>
|
---|
107 | /// <remarks>The array returned may be casted to the appropriate actual type afterwards.
|
---|
108 | /// <para>
|
---|
109 | /// <list type="number">
|
---|
110 | /// <listheader>The following types are supported: </listheader>
|
---|
111 | /// <item>Double</item>
|
---|
112 | /// <item>Single</item>
|
---|
113 | /// <item>complex</item>
|
---|
114 | /// <item>fcomplex</item>
|
---|
115 | /// <item>Byte</item>
|
---|
116 | /// <item>Int32</item>
|
---|
117 | /// <item>Int64</item>
|
---|
118 | /// </list>
|
---|
119 | /// </para>
|
---|
120 | /// </remarks>
|
---|
121 | public static ILRetArray<T> ones<T>(params int[] size) {
|
---|
122 | return ones<T>(new ILSize(size));
|
---|
123 | }
|
---|
124 | /// <summary>
|
---|
125 | /// Create array initialized with all elements set to one
|
---|
126 | /// </summary>
|
---|
127 | /// <typeparam name="T">Numeric type specification.</typeparam>
|
---|
128 | /// <param name="size">Size descriptor</param>
|
---|
129 | /// <returns>Array of inner type corresponding to the given type.</returns>
|
---|
130 | /// <remarks>The array returned may be casted to the appropriate actual type afterwards.
|
---|
131 | /// <para>
|
---|
132 | /// <list type="number">
|
---|
133 | /// <listheader>The following types are supported: </listheader>
|
---|
134 | /// <item>Double</item>
|
---|
135 | /// <item>Single</item>
|
---|
136 | /// <item>complex</item>
|
---|
137 | /// <item>fcomplex</item>
|
---|
138 | /// <item>Byte</item>
|
---|
139 | /// <item>Int32</item>
|
---|
140 | /// <item>Int64</item>
|
---|
141 | /// </list>
|
---|
142 | /// </para>
|
---|
143 | /// </remarks>
|
---|
144 | public static ILRetArray<T> ones<T>(ILSize size) {
|
---|
145 | using (ILScope.Enter()) {
|
---|
146 | if (typeof(T) == typeof(double)) {
|
---|
147 | return (ILRetArray<T>)(object)array<double>(1.0, size);
|
---|
148 | } else if (typeof(T) == typeof(float)) {
|
---|
149 | return (ILRetArray<T>)(object)array<float>(1f, size);
|
---|
150 | } else if (typeof(T) == typeof(int)) {
|
---|
151 | return (ILRetArray<T>)(object)array<int>(1, size);
|
---|
152 | } else if (typeof(T) == typeof(long)) {
|
---|
153 | return (ILRetArray<T>)(object)array<long>(1, size);
|
---|
154 | } else if (typeof(T) == typeof(complex)) {
|
---|
155 | return (ILRetArray<T>)(object)array<complex>(new complex(1, 0), size);
|
---|
156 | } else if (typeof(T) == typeof(fcomplex)) {
|
---|
157 | return (ILRetArray<T>)(object)array<fcomplex>(new fcomplex(1f, 0f), size);
|
---|
158 | } else if (typeof(T) == typeof(byte)) {
|
---|
159 | return (ILRetArray<T>)(object)array<byte>(1, size);
|
---|
160 | } else if (typeof(T) == typeof(short)) {
|
---|
161 | return (ILRetArray<T>)(object)array<short>(1, size);
|
---|
162 | }
|
---|
163 | return null;
|
---|
164 | }
|
---|
165 | }
|
---|
166 | /// <summary>
|
---|
167 | /// Create new double array, set initial values to 1
|
---|
168 | /// </summary>
|
---|
169 | /// <returns>Array</returns>
|
---|
170 | public static ILRetArray<double> ones(ILSize dimensions) {
|
---|
171 | return (ILRetArray<double>)ones(NumericType.Double, dimensions);
|
---|
172 | }
|
---|
173 |
|
---|
174 | }
|
---|
175 | }
|
---|