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