[9102] | 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 ILNumerics;
|
---|
| 44 | using ILNumerics.Exceptions;
|
---|
| 45 | using ILNumerics.Storage;
|
---|
| 46 | using ILNumerics.Misc;
|
---|
| 47 |
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | namespace ILNumerics {
|
---|
| 51 |
|
---|
| 52 | public partial class ILMath {
|
---|
| 53 |
|
---|
| 54 | |
---|
| 55 |
|
---|
| 56 | |
---|
| 57 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 58 | |
---|
| 59 | /// <summary>Round towards zero</summary>
|
---|
| 60 | /// <param name="A">Input array</param>
|
---|
| 61 | /// <returns>Array of same size as A with elements rounded towards zero</returns>
|
---|
| 62 | /// <remarks><para>If the input array is empty, an empty array will be returned.</para>
|
---|
| 63 | /// <para>The array returned will be a dense array.</para></remarks>
|
---|
| 64 | public unsafe static ILRetArray<complex> fix (ILInArray< complex > A) {
|
---|
| 65 | using (ILScope.Enter(A)) {
|
---|
| 66 | if (A.IsEmpty)
|
---|
| 67 | return new ILRetArray<complex>(A.Size);
|
---|
| 68 | ILSize inDim = A.Size;
|
---|
| 69 | complex[] arrA = A.GetArrayForRead();
|
---|
| 70 | complex [] retArr;
|
---|
| 71 | int outLen = inDim.NumberOfElements;
|
---|
| 72 | bool inplace = true;
|
---|
| 73 |
|
---|
| 74 | if (!A.TryGetStorage4InplaceOp(out retArr)) {
|
---|
| 75 | retArr = ILMemoryPool.Pool.New<complex>(outLen);
|
---|
| 76 | inplace = false;
|
---|
| 77 | }
|
---|
| 78 | int i = 0, workItemCount = Settings.s_maxNumberThreads, workItemLength, workerCount = 1;
|
---|
| 79 | if (Settings.s_maxNumberThreads > 1 && outLen / 2 > Settings.s_minParallelElement1Count) {
|
---|
| 80 | if (outLen / workItemCount > Settings.s_minParallelElement1Count) {
|
---|
| 81 | workItemLength = outLen / workItemCount;
|
---|
| 82 | //workItemLength = (int)((double)outLen / workItemCount * 1.05);
|
---|
| 83 | } else {
|
---|
| 84 | workItemLength = outLen / 2;
|
---|
| 85 | workItemCount = 2;
|
---|
| 86 | }
|
---|
| 87 | } else {
|
---|
| 88 | workItemLength = outLen;
|
---|
| 89 | workItemCount = 1;
|
---|
| 90 | }
|
---|
| 91 | ILDenseStorage<complex> retStorage = new ILDenseStorage<complex>(retArr, inDim);
|
---|
| 92 |
|
---|
| 93 | Action<object> worker = data => {
|
---|
| 94 | Tuple<int, int, IntPtr, IntPtr, bool> range = (Tuple<int, int, IntPtr, IntPtr, bool>)data;
|
---|
| 95 |
|
---|
| 96 | complex* cp = ((complex*)range.Item4 + range.Item1);
|
---|
| 97 | int len = range.Item2;
|
---|
| 98 | if (range.Item5) {
|
---|
| 99 | // inplace
|
---|
| 100 | while (len > 20) {
|
---|
| 101 | cp[0] = complex.Truncate(cp[0] ) /*dummy*/;
|
---|
| 102 | cp[1] = complex.Truncate(cp[1] ) /*dummy*/;
|
---|
| 103 | cp[2] = complex.Truncate(cp[2] ) /*dummy*/;
|
---|
| 104 | cp[3] = complex.Truncate(cp[3] ) /*dummy*/;
|
---|
| 105 | cp[4] = complex.Truncate(cp[4] ) /*dummy*/;
|
---|
| 106 | cp[5] = complex.Truncate(cp[5] ) /*dummy*/;
|
---|
| 107 | cp[6] = complex.Truncate(cp[6] ) /*dummy*/;
|
---|
| 108 | cp[7] = complex.Truncate(cp[7] ) /*dummy*/;
|
---|
| 109 | cp[8] = complex.Truncate(cp[8] ) /*dummy*/;
|
---|
| 110 | cp[9] = complex.Truncate(cp[9] ) /*dummy*/;
|
---|
| 111 | cp[10] = complex.Truncate(cp[10] ) /*dummy*/;
|
---|
| 112 | cp[11] = complex.Truncate(cp[11] ) /*dummy*/;
|
---|
| 113 | cp[12] = complex.Truncate(cp[12] ) /*dummy*/;
|
---|
| 114 | cp[13] = complex.Truncate(cp[13] ) /*dummy*/;
|
---|
| 115 | cp[14] = complex.Truncate(cp[14] ) /*dummy*/;
|
---|
| 116 | cp[15] = complex.Truncate(cp[15] ) /*dummy*/;
|
---|
| 117 | cp[16] = complex.Truncate(cp[16] ) /*dummy*/;
|
---|
| 118 | cp[17] = complex.Truncate(cp[17] ) /*dummy*/;
|
---|
| 119 | cp[18] = complex.Truncate(cp[18] ) /*dummy*/;
|
---|
| 120 | cp[19] = complex.Truncate(cp[19] ) /*dummy*/;
|
---|
| 121 | cp[20] = complex.Truncate(cp[20] ) /*dummy*/;
|
---|
| 122 | cp+=21; len -= 21;
|
---|
| 123 | }
|
---|
| 124 | while (len-- > 0) {
|
---|
| 125 | *cp = complex.Truncate(*cp ) /*dummy*/;
|
---|
| 126 | cp++;
|
---|
| 127 | }
|
---|
| 128 | } else {
|
---|
| 129 | complex* ap = ((complex*)range.Item3 + range.Item1);
|
---|
| 130 | while (len > 20) {
|
---|
| 131 | cp[0] = complex.Truncate(ap[0] ) /*dummy*/;
|
---|
| 132 | cp[1] = complex.Truncate(ap[1] ) /*dummy*/;
|
---|
| 133 | cp[2] = complex.Truncate(ap[2] ) /*dummy*/;
|
---|
| 134 | cp[3] = complex.Truncate(ap[3] ) /*dummy*/;
|
---|
| 135 | cp[4] = complex.Truncate(ap[4] ) /*dummy*/;
|
---|
| 136 | cp[5] = complex.Truncate(ap[5] ) /*dummy*/;
|
---|
| 137 | cp[6] = complex.Truncate(ap[6] ) /*dummy*/;
|
---|
| 138 | cp[7] = complex.Truncate(ap[7] ) /*dummy*/;
|
---|
| 139 | cp[8] = complex.Truncate(ap[8] ) /*dummy*/;
|
---|
| 140 | cp[9] = complex.Truncate(ap[9] ) /*dummy*/;
|
---|
| 141 | cp[10] = complex.Truncate(ap[10] ) /*dummy*/;
|
---|
| 142 | cp[11] = complex.Truncate(ap[11] ) /*dummy*/;
|
---|
| 143 | cp[12] = complex.Truncate(ap[12] ) /*dummy*/;
|
---|
| 144 | cp[13] = complex.Truncate(ap[13] ) /*dummy*/;
|
---|
| 145 | cp[14] = complex.Truncate(ap[14] ) /*dummy*/;
|
---|
| 146 | cp[15] = complex.Truncate(ap[15] ) /*dummy*/;
|
---|
| 147 | cp[16] = complex.Truncate(ap[16] ) /*dummy*/;
|
---|
| 148 | cp[17] = complex.Truncate(ap[17] ) /*dummy*/;
|
---|
| 149 | cp[18] = complex.Truncate(ap[18] ) /*dummy*/;
|
---|
| 150 | cp[19] = complex.Truncate(ap[19] ) /*dummy*/;
|
---|
| 151 | cp[20] = complex.Truncate(ap[20] ) /*dummy*/;
|
---|
| 152 | ap += 21;
|
---|
| 153 | cp += 21;
|
---|
| 154 | len -= 21;
|
---|
| 155 | }
|
---|
| 156 | while (len-- > 0) {
|
---|
| 157 | *cp = complex.Truncate(*ap ) /*dummy*/;
|
---|
| 158 | ap++;
|
---|
| 159 | cp++;
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | System.Threading.Interlocked.Decrement(ref workerCount);
|
---|
| 163 | };
|
---|
| 164 |
|
---|
| 165 | fixed ( complex* arrAP = arrA)
|
---|
| 166 | fixed ( complex* retArrP = retArr) {
|
---|
| 167 | for (; i < workItemCount - 1; i++) {
|
---|
| 168 | Tuple<int, int, IntPtr, IntPtr, bool> range
|
---|
| 169 | = new Tuple<int, int, IntPtr, IntPtr, bool>
|
---|
| 170 | (i * workItemLength, workItemLength, (IntPtr)arrAP, (IntPtr)retArrP, inplace);
|
---|
| 171 | System.Threading.Interlocked.Increment(ref workerCount);
|
---|
| 172 | ILThreadPool.QueueUserWorkItem(i,worker, range);
|
---|
| 173 | }
|
---|
| 174 | // the last (or may the only) chunk is done right here
|
---|
| 175 | worker(new Tuple<int, int, IntPtr, IntPtr, bool>
|
---|
| 176 | (i * workItemLength, outLen - i * workItemLength, (IntPtr)arrAP, (IntPtr)retArrP, inplace));
|
---|
| 177 |
|
---|
| 178 | ILThreadPool.Wait4Workers(ref workerCount);
|
---|
| 179 | }
|
---|
| 180 | return new ILRetArray<complex>(retStorage);
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 | /// <summary>Round towards zero</summary>
|
---|
| 184 | /// <param name="A">Input array</param>
|
---|
| 185 | /// <returns>Array of same size as A with elements rounded towards zero</returns>
|
---|
| 186 | /// <remarks><para>If the input array is empty, an empty array will be returned.</para>
|
---|
| 187 | /// <para>The array returned will be a dense array.</para></remarks>
|
---|
| 188 | public unsafe static ILRetArray<fcomplex> fix (ILInArray< fcomplex > A) {
|
---|
| 189 | using (ILScope.Enter(A)) {
|
---|
| 190 | if (A.IsEmpty)
|
---|
| 191 | return new ILRetArray<fcomplex>(A.Size);
|
---|
| 192 | ILSize inDim = A.Size;
|
---|
| 193 | fcomplex[] arrA = A.GetArrayForRead();
|
---|
| 194 | fcomplex [] retArr;
|
---|
| 195 | int outLen = inDim.NumberOfElements;
|
---|
| 196 | bool inplace = true;
|
---|
| 197 |
|
---|
| 198 | if (!A.TryGetStorage4InplaceOp(out retArr)) {
|
---|
| 199 | retArr = ILMemoryPool.Pool.New<fcomplex>(outLen);
|
---|
| 200 | inplace = false;
|
---|
| 201 | }
|
---|
| 202 | int i = 0, workItemCount = Settings.s_maxNumberThreads, workItemLength, workerCount = 1;
|
---|
| 203 | if (Settings.s_maxNumberThreads > 1 && outLen / 2 > Settings.s_minParallelElement1Count) {
|
---|
| 204 | if (outLen / workItemCount > Settings.s_minParallelElement1Count) {
|
---|
| 205 | workItemLength = outLen / workItemCount;
|
---|
| 206 | //workItemLength = (int)((double)outLen / workItemCount * 1.05);
|
---|
| 207 | } else {
|
---|
| 208 | workItemLength = outLen / 2;
|
---|
| 209 | workItemCount = 2;
|
---|
| 210 | }
|
---|
| 211 | } else {
|
---|
| 212 | workItemLength = outLen;
|
---|
| 213 | workItemCount = 1;
|
---|
| 214 | }
|
---|
| 215 | ILDenseStorage<fcomplex> retStorage = new ILDenseStorage<fcomplex>(retArr, inDim);
|
---|
| 216 |
|
---|
| 217 | Action<object> worker = data => {
|
---|
| 218 | Tuple<int, int, IntPtr, IntPtr, bool> range = (Tuple<int, int, IntPtr, IntPtr, bool>)data;
|
---|
| 219 |
|
---|
| 220 | fcomplex* cp = ((fcomplex*)range.Item4 + range.Item1);
|
---|
| 221 | int len = range.Item2;
|
---|
| 222 | if (range.Item5) {
|
---|
| 223 | // inplace
|
---|
| 224 | while (len > 20) {
|
---|
| 225 | cp[0] = fcomplex.Truncate(cp[0] ) /*dummy*/;
|
---|
| 226 | cp[1] = fcomplex.Truncate(cp[1] ) /*dummy*/;
|
---|
| 227 | cp[2] = fcomplex.Truncate(cp[2] ) /*dummy*/;
|
---|
| 228 | cp[3] = fcomplex.Truncate(cp[3] ) /*dummy*/;
|
---|
| 229 | cp[4] = fcomplex.Truncate(cp[4] ) /*dummy*/;
|
---|
| 230 | cp[5] = fcomplex.Truncate(cp[5] ) /*dummy*/;
|
---|
| 231 | cp[6] = fcomplex.Truncate(cp[6] ) /*dummy*/;
|
---|
| 232 | cp[7] = fcomplex.Truncate(cp[7] ) /*dummy*/;
|
---|
| 233 | cp[8] = fcomplex.Truncate(cp[8] ) /*dummy*/;
|
---|
| 234 | cp[9] = fcomplex.Truncate(cp[9] ) /*dummy*/;
|
---|
| 235 | cp[10] = fcomplex.Truncate(cp[10] ) /*dummy*/;
|
---|
| 236 | cp[11] = fcomplex.Truncate(cp[11] ) /*dummy*/;
|
---|
| 237 | cp[12] = fcomplex.Truncate(cp[12] ) /*dummy*/;
|
---|
| 238 | cp[13] = fcomplex.Truncate(cp[13] ) /*dummy*/;
|
---|
| 239 | cp[14] = fcomplex.Truncate(cp[14] ) /*dummy*/;
|
---|
| 240 | cp[15] = fcomplex.Truncate(cp[15] ) /*dummy*/;
|
---|
| 241 | cp[16] = fcomplex.Truncate(cp[16] ) /*dummy*/;
|
---|
| 242 | cp[17] = fcomplex.Truncate(cp[17] ) /*dummy*/;
|
---|
| 243 | cp[18] = fcomplex.Truncate(cp[18] ) /*dummy*/;
|
---|
| 244 | cp[19] = fcomplex.Truncate(cp[19] ) /*dummy*/;
|
---|
| 245 | cp[20] = fcomplex.Truncate(cp[20] ) /*dummy*/;
|
---|
| 246 | cp+=21; len -= 21;
|
---|
| 247 | }
|
---|
| 248 | while (len-- > 0) {
|
---|
| 249 | *cp = fcomplex.Truncate(*cp ) /*dummy*/;
|
---|
| 250 | cp++;
|
---|
| 251 | }
|
---|
| 252 | } else {
|
---|
| 253 | fcomplex* ap = ((fcomplex*)range.Item3 + range.Item1);
|
---|
| 254 | while (len > 20) {
|
---|
| 255 | cp[0] = fcomplex.Truncate(ap[0] ) /*dummy*/;
|
---|
| 256 | cp[1] = fcomplex.Truncate(ap[1] ) /*dummy*/;
|
---|
| 257 | cp[2] = fcomplex.Truncate(ap[2] ) /*dummy*/;
|
---|
| 258 | cp[3] = fcomplex.Truncate(ap[3] ) /*dummy*/;
|
---|
| 259 | cp[4] = fcomplex.Truncate(ap[4] ) /*dummy*/;
|
---|
| 260 | cp[5] = fcomplex.Truncate(ap[5] ) /*dummy*/;
|
---|
| 261 | cp[6] = fcomplex.Truncate(ap[6] ) /*dummy*/;
|
---|
| 262 | cp[7] = fcomplex.Truncate(ap[7] ) /*dummy*/;
|
---|
| 263 | cp[8] = fcomplex.Truncate(ap[8] ) /*dummy*/;
|
---|
| 264 | cp[9] = fcomplex.Truncate(ap[9] ) /*dummy*/;
|
---|
| 265 | cp[10] = fcomplex.Truncate(ap[10] ) /*dummy*/;
|
---|
| 266 | cp[11] = fcomplex.Truncate(ap[11] ) /*dummy*/;
|
---|
| 267 | cp[12] = fcomplex.Truncate(ap[12] ) /*dummy*/;
|
---|
| 268 | cp[13] = fcomplex.Truncate(ap[13] ) /*dummy*/;
|
---|
| 269 | cp[14] = fcomplex.Truncate(ap[14] ) /*dummy*/;
|
---|
| 270 | cp[15] = fcomplex.Truncate(ap[15] ) /*dummy*/;
|
---|
| 271 | cp[16] = fcomplex.Truncate(ap[16] ) /*dummy*/;
|
---|
| 272 | cp[17] = fcomplex.Truncate(ap[17] ) /*dummy*/;
|
---|
| 273 | cp[18] = fcomplex.Truncate(ap[18] ) /*dummy*/;
|
---|
| 274 | cp[19] = fcomplex.Truncate(ap[19] ) /*dummy*/;
|
---|
| 275 | cp[20] = fcomplex.Truncate(ap[20] ) /*dummy*/;
|
---|
| 276 | ap += 21;
|
---|
| 277 | cp += 21;
|
---|
| 278 | len -= 21;
|
---|
| 279 | }
|
---|
| 280 | while (len-- > 0) {
|
---|
| 281 | *cp = fcomplex.Truncate(*ap ) /*dummy*/;
|
---|
| 282 | ap++;
|
---|
| 283 | cp++;
|
---|
| 284 | }
|
---|
| 285 | }
|
---|
| 286 | System.Threading.Interlocked.Decrement(ref workerCount);
|
---|
| 287 | };
|
---|
| 288 |
|
---|
| 289 | fixed ( fcomplex* arrAP = arrA)
|
---|
| 290 | fixed ( fcomplex* retArrP = retArr) {
|
---|
| 291 | for (; i < workItemCount - 1; i++) {
|
---|
| 292 | Tuple<int, int, IntPtr, IntPtr, bool> range
|
---|
| 293 | = new Tuple<int, int, IntPtr, IntPtr, bool>
|
---|
| 294 | (i * workItemLength, workItemLength, (IntPtr)arrAP, (IntPtr)retArrP, inplace);
|
---|
| 295 | System.Threading.Interlocked.Increment(ref workerCount);
|
---|
| 296 | ILThreadPool.QueueUserWorkItem(i,worker, range);
|
---|
| 297 | }
|
---|
| 298 | // the last (or may the only) chunk is done right here
|
---|
| 299 | worker(new Tuple<int, int, IntPtr, IntPtr, bool>
|
---|
| 300 | (i * workItemLength, outLen - i * workItemLength, (IntPtr)arrAP, (IntPtr)retArrP, inplace));
|
---|
| 301 |
|
---|
| 302 | ILThreadPool.Wait4Workers(ref workerCount);
|
---|
| 303 | }
|
---|
| 304 | return new ILRetArray<fcomplex>(retStorage);
|
---|
| 305 | }
|
---|
| 306 | }
|
---|
| 307 | /// <summary>Round towards zero</summary>
|
---|
| 308 | /// <param name="A">Input array</param>
|
---|
| 309 | /// <returns>Array of same size as A with elements rounded towards zero</returns>
|
---|
| 310 | /// <remarks><para>If the input array is empty, an empty array will be returned.</para>
|
---|
| 311 | /// <para>The array returned will be a dense array.</para></remarks>
|
---|
| 312 | public unsafe static ILRetArray<float> fix (ILInArray< float > A) {
|
---|
| 313 | using (ILScope.Enter(A)) {
|
---|
| 314 | if (A.IsEmpty)
|
---|
| 315 | return new ILRetArray<float>(A.Size);
|
---|
| 316 | ILSize inDim = A.Size;
|
---|
| 317 | float[] arrA = A.GetArrayForRead();
|
---|
| 318 | float [] retArr;
|
---|
| 319 | int outLen = inDim.NumberOfElements;
|
---|
| 320 | bool inplace = true;
|
---|
| 321 |
|
---|
| 322 | if (!A.TryGetStorage4InplaceOp(out retArr)) {
|
---|
| 323 | retArr = ILMemoryPool.Pool.New<float>(outLen);
|
---|
| 324 | inplace = false;
|
---|
| 325 | }
|
---|
| 326 | int i = 0, workItemCount = Settings.s_maxNumberThreads, workItemLength, workerCount = 1;
|
---|
| 327 | if (Settings.s_maxNumberThreads > 1 && outLen / 2 > Settings.s_minParallelElement1Count) {
|
---|
| 328 | if (outLen / workItemCount > Settings.s_minParallelElement1Count) {
|
---|
| 329 | workItemLength = outLen / workItemCount;
|
---|
| 330 | //workItemLength = (int)((double)outLen / workItemCount * 1.05);
|
---|
| 331 | } else {
|
---|
| 332 | workItemLength = outLen / 2;
|
---|
| 333 | workItemCount = 2;
|
---|
| 334 | }
|
---|
| 335 | } else {
|
---|
| 336 | workItemLength = outLen;
|
---|
| 337 | workItemCount = 1;
|
---|
| 338 | }
|
---|
| 339 | ILDenseStorage<float> retStorage = new ILDenseStorage<float>(retArr, inDim);
|
---|
| 340 |
|
---|
| 341 | Action<object> worker = data => {
|
---|
| 342 | Tuple<int, int, IntPtr, IntPtr, bool> range = (Tuple<int, int, IntPtr, IntPtr, bool>)data;
|
---|
| 343 |
|
---|
| 344 | float* cp = ((float*)range.Item4 + range.Item1);
|
---|
| 345 | int len = range.Item2;
|
---|
| 346 | if (range.Item5) {
|
---|
| 347 | // inplace
|
---|
| 348 | while (len > 20) {
|
---|
| 349 | cp[0] = (float)Math.Truncate(cp[0] ) /*dummy*/;
|
---|
| 350 | cp[1] = (float)Math.Truncate(cp[1] ) /*dummy*/;
|
---|
| 351 | cp[2] = (float)Math.Truncate(cp[2] ) /*dummy*/;
|
---|
| 352 | cp[3] = (float)Math.Truncate(cp[3] ) /*dummy*/;
|
---|
| 353 | cp[4] = (float)Math.Truncate(cp[4] ) /*dummy*/;
|
---|
| 354 | cp[5] = (float)Math.Truncate(cp[5] ) /*dummy*/;
|
---|
| 355 | cp[6] = (float)Math.Truncate(cp[6] ) /*dummy*/;
|
---|
| 356 | cp[7] = (float)Math.Truncate(cp[7] ) /*dummy*/;
|
---|
| 357 | cp[8] = (float)Math.Truncate(cp[8] ) /*dummy*/;
|
---|
| 358 | cp[9] = (float)Math.Truncate(cp[9] ) /*dummy*/;
|
---|
| 359 | cp[10] = (float)Math.Truncate(cp[10] ) /*dummy*/;
|
---|
| 360 | cp[11] = (float)Math.Truncate(cp[11] ) /*dummy*/;
|
---|
| 361 | cp[12] = (float)Math.Truncate(cp[12] ) /*dummy*/;
|
---|
| 362 | cp[13] = (float)Math.Truncate(cp[13] ) /*dummy*/;
|
---|
| 363 | cp[14] = (float)Math.Truncate(cp[14] ) /*dummy*/;
|
---|
| 364 | cp[15] = (float)Math.Truncate(cp[15] ) /*dummy*/;
|
---|
| 365 | cp[16] = (float)Math.Truncate(cp[16] ) /*dummy*/;
|
---|
| 366 | cp[17] = (float)Math.Truncate(cp[17] ) /*dummy*/;
|
---|
| 367 | cp[18] = (float)Math.Truncate(cp[18] ) /*dummy*/;
|
---|
| 368 | cp[19] = (float)Math.Truncate(cp[19] ) /*dummy*/;
|
---|
| 369 | cp[20] = (float)Math.Truncate(cp[20] ) /*dummy*/;
|
---|
| 370 | cp+=21; len -= 21;
|
---|
| 371 | }
|
---|
| 372 | while (len-- > 0) {
|
---|
| 373 | *cp = (float)Math.Truncate(*cp ) /*dummy*/;
|
---|
| 374 | cp++;
|
---|
| 375 | }
|
---|
| 376 | } else {
|
---|
| 377 | float* ap = ((float*)range.Item3 + range.Item1);
|
---|
| 378 | while (len > 20) {
|
---|
| 379 | cp[0] = (float)Math.Truncate(ap[0] ) /*dummy*/;
|
---|
| 380 | cp[1] = (float)Math.Truncate(ap[1] ) /*dummy*/;
|
---|
| 381 | cp[2] = (float)Math.Truncate(ap[2] ) /*dummy*/;
|
---|
| 382 | cp[3] = (float)Math.Truncate(ap[3] ) /*dummy*/;
|
---|
| 383 | cp[4] = (float)Math.Truncate(ap[4] ) /*dummy*/;
|
---|
| 384 | cp[5] = (float)Math.Truncate(ap[5] ) /*dummy*/;
|
---|
| 385 | cp[6] = (float)Math.Truncate(ap[6] ) /*dummy*/;
|
---|
| 386 | cp[7] = (float)Math.Truncate(ap[7] ) /*dummy*/;
|
---|
| 387 | cp[8] = (float)Math.Truncate(ap[8] ) /*dummy*/;
|
---|
| 388 | cp[9] = (float)Math.Truncate(ap[9] ) /*dummy*/;
|
---|
| 389 | cp[10] = (float)Math.Truncate(ap[10] ) /*dummy*/;
|
---|
| 390 | cp[11] = (float)Math.Truncate(ap[11] ) /*dummy*/;
|
---|
| 391 | cp[12] = (float)Math.Truncate(ap[12] ) /*dummy*/;
|
---|
| 392 | cp[13] = (float)Math.Truncate(ap[13] ) /*dummy*/;
|
---|
| 393 | cp[14] = (float)Math.Truncate(ap[14] ) /*dummy*/;
|
---|
| 394 | cp[15] = (float)Math.Truncate(ap[15] ) /*dummy*/;
|
---|
| 395 | cp[16] = (float)Math.Truncate(ap[16] ) /*dummy*/;
|
---|
| 396 | cp[17] = (float)Math.Truncate(ap[17] ) /*dummy*/;
|
---|
| 397 | cp[18] = (float)Math.Truncate(ap[18] ) /*dummy*/;
|
---|
| 398 | cp[19] = (float)Math.Truncate(ap[19] ) /*dummy*/;
|
---|
| 399 | cp[20] = (float)Math.Truncate(ap[20] ) /*dummy*/;
|
---|
| 400 | ap += 21;
|
---|
| 401 | cp += 21;
|
---|
| 402 | len -= 21;
|
---|
| 403 | }
|
---|
| 404 | while (len-- > 0) {
|
---|
| 405 | *cp = (float)Math.Truncate(*ap ) /*dummy*/;
|
---|
| 406 | ap++;
|
---|
| 407 | cp++;
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 | System.Threading.Interlocked.Decrement(ref workerCount);
|
---|
| 411 | };
|
---|
| 412 |
|
---|
| 413 | fixed ( float* arrAP = arrA)
|
---|
| 414 | fixed ( float* retArrP = retArr) {
|
---|
| 415 | for (; i < workItemCount - 1; i++) {
|
---|
| 416 | Tuple<int, int, IntPtr, IntPtr, bool> range
|
---|
| 417 | = new Tuple<int, int, IntPtr, IntPtr, bool>
|
---|
| 418 | (i * workItemLength, workItemLength, (IntPtr)arrAP, (IntPtr)retArrP, inplace);
|
---|
| 419 | System.Threading.Interlocked.Increment(ref workerCount);
|
---|
| 420 | ILThreadPool.QueueUserWorkItem(i,worker, range);
|
---|
| 421 | }
|
---|
| 422 | // the last (or may the only) chunk is done right here
|
---|
| 423 | worker(new Tuple<int, int, IntPtr, IntPtr, bool>
|
---|
| 424 | (i * workItemLength, outLen - i * workItemLength, (IntPtr)arrAP, (IntPtr)retArrP, inplace));
|
---|
| 425 |
|
---|
| 426 | ILThreadPool.Wait4Workers(ref workerCount);
|
---|
| 427 | }
|
---|
| 428 | return new ILRetArray<float>(retStorage);
|
---|
| 429 | }
|
---|
| 430 | }
|
---|
| 431 | /// <summary>Round towards zero</summary>
|
---|
| 432 | /// <param name="A">Input array</param>
|
---|
| 433 | /// <returns>Array of same size as A with elements rounded towards zero</returns>
|
---|
| 434 | /// <remarks><para>If the input array is empty, an empty array will be returned.</para>
|
---|
| 435 | /// <para>The array returned will be a dense array.</para></remarks>
|
---|
| 436 | public unsafe static ILRetArray<double> fix (ILInArray< double > A) {
|
---|
| 437 | using (ILScope.Enter(A)) {
|
---|
| 438 | if (A.IsEmpty)
|
---|
| 439 | return new ILRetArray<double>(A.Size);
|
---|
| 440 | ILSize inDim = A.Size;
|
---|
| 441 | double[] arrA = A.GetArrayForRead();
|
---|
| 442 | double [] retArr;
|
---|
| 443 | int outLen = inDim.NumberOfElements;
|
---|
| 444 | bool inplace = true;
|
---|
| 445 |
|
---|
| 446 | if (!A.TryGetStorage4InplaceOp(out retArr)) {
|
---|
| 447 | retArr = ILMemoryPool.Pool.New<double>(outLen);
|
---|
| 448 | inplace = false;
|
---|
| 449 | }
|
---|
| 450 | int i = 0, workItemCount = Settings.s_maxNumberThreads, workItemLength, workerCount = 1;
|
---|
| 451 | if (Settings.s_maxNumberThreads > 1 && outLen / 2 > Settings.s_minParallelElement1Count) {
|
---|
| 452 | if (outLen / workItemCount > Settings.s_minParallelElement1Count) {
|
---|
| 453 | workItemLength = outLen / workItemCount;
|
---|
| 454 | //workItemLength = (int)((double)outLen / workItemCount * 1.05);
|
---|
| 455 | } else {
|
---|
| 456 | workItemLength = outLen / 2;
|
---|
| 457 | workItemCount = 2;
|
---|
| 458 | }
|
---|
| 459 | } else {
|
---|
| 460 | workItemLength = outLen;
|
---|
| 461 | workItemCount = 1;
|
---|
| 462 | }
|
---|
| 463 | ILDenseStorage<double> retStorage = new ILDenseStorage<double>(retArr, inDim);
|
---|
| 464 |
|
---|
| 465 | Action<object> worker = data => {
|
---|
| 466 | Tuple<int, int, IntPtr, IntPtr, bool> range = (Tuple<int, int, IntPtr, IntPtr, bool>)data;
|
---|
| 467 |
|
---|
| 468 | double* cp = ((double*)range.Item4 + range.Item1);
|
---|
| 469 | int len = range.Item2;
|
---|
| 470 | if (range.Item5) {
|
---|
| 471 | // inplace
|
---|
| 472 | while (len > 20) {
|
---|
| 473 | cp[0] = Math.Truncate(cp[0] ) /*dummy*/;
|
---|
| 474 | cp[1] = Math.Truncate(cp[1] ) /*dummy*/;
|
---|
| 475 | cp[2] = Math.Truncate(cp[2] ) /*dummy*/;
|
---|
| 476 | cp[3] = Math.Truncate(cp[3] ) /*dummy*/;
|
---|
| 477 | cp[4] = Math.Truncate(cp[4] ) /*dummy*/;
|
---|
| 478 | cp[5] = Math.Truncate(cp[5] ) /*dummy*/;
|
---|
| 479 | cp[6] = Math.Truncate(cp[6] ) /*dummy*/;
|
---|
| 480 | cp[7] = Math.Truncate(cp[7] ) /*dummy*/;
|
---|
| 481 | cp[8] = Math.Truncate(cp[8] ) /*dummy*/;
|
---|
| 482 | cp[9] = Math.Truncate(cp[9] ) /*dummy*/;
|
---|
| 483 | cp[10] = Math.Truncate(cp[10] ) /*dummy*/;
|
---|
| 484 | cp[11] = Math.Truncate(cp[11] ) /*dummy*/;
|
---|
| 485 | cp[12] = Math.Truncate(cp[12] ) /*dummy*/;
|
---|
| 486 | cp[13] = Math.Truncate(cp[13] ) /*dummy*/;
|
---|
| 487 | cp[14] = Math.Truncate(cp[14] ) /*dummy*/;
|
---|
| 488 | cp[15] = Math.Truncate(cp[15] ) /*dummy*/;
|
---|
| 489 | cp[16] = Math.Truncate(cp[16] ) /*dummy*/;
|
---|
| 490 | cp[17] = Math.Truncate(cp[17] ) /*dummy*/;
|
---|
| 491 | cp[18] = Math.Truncate(cp[18] ) /*dummy*/;
|
---|
| 492 | cp[19] = Math.Truncate(cp[19] ) /*dummy*/;
|
---|
| 493 | cp[20] = Math.Truncate(cp[20] ) /*dummy*/;
|
---|
| 494 | cp+=21; len -= 21;
|
---|
| 495 | }
|
---|
| 496 | while (len-- > 0) {
|
---|
| 497 | *cp = Math.Truncate(*cp ) /*dummy*/;
|
---|
| 498 | cp++;
|
---|
| 499 | }
|
---|
| 500 | } else {
|
---|
| 501 | double* ap = ((double*)range.Item3 + range.Item1);
|
---|
| 502 | while (len > 20) {
|
---|
| 503 | cp[0] = Math.Truncate(ap[0] ) /*dummy*/;
|
---|
| 504 | cp[1] = Math.Truncate(ap[1] ) /*dummy*/;
|
---|
| 505 | cp[2] = Math.Truncate(ap[2] ) /*dummy*/;
|
---|
| 506 | cp[3] = Math.Truncate(ap[3] ) /*dummy*/;
|
---|
| 507 | cp[4] = Math.Truncate(ap[4] ) /*dummy*/;
|
---|
| 508 | cp[5] = Math.Truncate(ap[5] ) /*dummy*/;
|
---|
| 509 | cp[6] = Math.Truncate(ap[6] ) /*dummy*/;
|
---|
| 510 | cp[7] = Math.Truncate(ap[7] ) /*dummy*/;
|
---|
| 511 | cp[8] = Math.Truncate(ap[8] ) /*dummy*/;
|
---|
| 512 | cp[9] = Math.Truncate(ap[9] ) /*dummy*/;
|
---|
| 513 | cp[10] = Math.Truncate(ap[10] ) /*dummy*/;
|
---|
| 514 | cp[11] = Math.Truncate(ap[11] ) /*dummy*/;
|
---|
| 515 | cp[12] = Math.Truncate(ap[12] ) /*dummy*/;
|
---|
| 516 | cp[13] = Math.Truncate(ap[13] ) /*dummy*/;
|
---|
| 517 | cp[14] = Math.Truncate(ap[14] ) /*dummy*/;
|
---|
| 518 | cp[15] = Math.Truncate(ap[15] ) /*dummy*/;
|
---|
| 519 | cp[16] = Math.Truncate(ap[16] ) /*dummy*/;
|
---|
| 520 | cp[17] = Math.Truncate(ap[17] ) /*dummy*/;
|
---|
| 521 | cp[18] = Math.Truncate(ap[18] ) /*dummy*/;
|
---|
| 522 | cp[19] = Math.Truncate(ap[19] ) /*dummy*/;
|
---|
| 523 | cp[20] = Math.Truncate(ap[20] ) /*dummy*/;
|
---|
| 524 | ap += 21;
|
---|
| 525 | cp += 21;
|
---|
| 526 | len -= 21;
|
---|
| 527 | }
|
---|
| 528 | while (len-- > 0) {
|
---|
| 529 | *cp = Math.Truncate(*ap ) /*dummy*/;
|
---|
| 530 | ap++;
|
---|
| 531 | cp++;
|
---|
| 532 | }
|
---|
| 533 | }
|
---|
| 534 | System.Threading.Interlocked.Decrement(ref workerCount);
|
---|
| 535 | };
|
---|
| 536 |
|
---|
| 537 | fixed ( double* arrAP = arrA)
|
---|
| 538 | fixed ( double* retArrP = retArr) {
|
---|
| 539 | for (; i < workItemCount - 1; i++) {
|
---|
| 540 | Tuple<int, int, IntPtr, IntPtr, bool> range
|
---|
| 541 | = new Tuple<int, int, IntPtr, IntPtr, bool>
|
---|
| 542 | (i * workItemLength, workItemLength, (IntPtr)arrAP, (IntPtr)retArrP, inplace);
|
---|
| 543 | System.Threading.Interlocked.Increment(ref workerCount);
|
---|
| 544 | ILThreadPool.QueueUserWorkItem(i,worker, range);
|
---|
| 545 | }
|
---|
| 546 | // the last (or may the only) chunk is done right here
|
---|
| 547 | worker(new Tuple<int, int, IntPtr, IntPtr, bool>
|
---|
| 548 | (i * workItemLength, outLen - i * workItemLength, (IntPtr)arrAP, (IntPtr)retArrP, inplace));
|
---|
| 549 |
|
---|
| 550 | ILThreadPool.Wait4Workers(ref workerCount);
|
---|
| 551 | }
|
---|
| 552 | return new ILRetArray<double>(retStorage);
|
---|
| 553 | }
|
---|
| 554 | }
|
---|
| 555 |
|
---|
| 556 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 557 |
|
---|
| 558 | }
|
---|
| 559 | } |
---|