[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.Storage;
|
---|
| 44 | using ILNumerics.Misc;
|
---|
| 45 | using ILNumerics.Exceptions;
|
---|
| 46 |
|
---|
| 47 | namespace ILNumerics {
|
---|
| 48 | public partial class ILMath {
|
---|
| 49 | |
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | |
---|
| 54 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 55 | |
---|
| 56 | /// <summary>Determine, if any elements are nonzero</summary>
|
---|
| 57 | /// <param name="A">Input array</param>
|
---|
| 58 | /// <param name="dim">[Optional] Index of the dimension to operate along. If omitted operates along the first non singleton dimension (i.e. != 1).</param>
|
---|
| 59 | /// <returns><para>Array of same size as A, having the specified or first non-singleton dimension reduced to 1, if any elements along that dimension are non-zero, '0' else. </para></returns>
|
---|
| 60 | public static ILRetLogical any (ILInArray<double> A, int dim = -1) {
|
---|
| 61 | using (ILScope.Enter(A)) {
|
---|
| 62 | if (dim < 0)
|
---|
| 63 | dim = A.Size.WorkingDimension();
|
---|
| 64 | if (dim >= A.Size.NumberOfDimensions)
|
---|
| 65 | throw new ILArgumentException("dimension parameter out of range!");
|
---|
| 66 | if (A.IsEmpty)
|
---|
| 67 | return new ILRetLogical(A.Size);
|
---|
| 68 | if (A.IsScalar) {
|
---|
| 69 | return new ILRetLogical (new byte [1]{(A.GetValue(0) == 0.0 || double.IsNaN(A.GetValue(0)))?(byte)0:(byte)1},1,1);
|
---|
| 70 | }
|
---|
| 71 | ILSize inDim = A.Size;
|
---|
| 72 | int[] newDims = inDim.ToIntArray();
|
---|
| 73 | int tmpCount = 0;
|
---|
| 74 |
|
---|
| 75 | int newLength;
|
---|
| 76 |
|
---|
| 77 | byte[] retArr;
|
---|
| 78 | // build ILSize
|
---|
| 79 | newLength = inDim.NumberOfElements / newDims[dim];
|
---|
| 80 | newDims[dim] = 1;
|
---|
| 81 | retArr = ILMemoryPool.Pool.New< byte>(newLength);
|
---|
| 82 | ILSize newDimension = new ILSize(newDims);
|
---|
| 83 | int incOut = newDimension.SequentialIndexDistance(dim);
|
---|
| 84 | int dimLen = inDim[dim];
|
---|
| 85 | int nrHigherDims = inDim.NumberOfElements / dimLen;
|
---|
| 86 | if (dim == 0) {
|
---|
| 87 | #region physical along 1st leading dimension
|
---|
| 88 | unsafe {
|
---|
| 89 | fixed ( byte* pOutArr = retArr)
|
---|
| 90 | fixed ( double* pInArr = A.GetArrayForRead()) {
|
---|
| 91 |
|
---|
| 92 | double* lastElement;
|
---|
| 93 |
|
---|
| 94 | byte* tmpOut = pOutArr;
|
---|
| 95 |
|
---|
| 96 | double* tmpIn = pInArr;
|
---|
| 97 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 98 | lastElement = tmpIn + dimLen;
|
---|
| 99 |
|
---|
| 100 | while (tmpIn < lastElement) {
|
---|
| 101 |
|
---|
| 102 | double inVal = *(tmpIn++);
|
---|
| 103 | if (double.IsNaN(inVal)) continue;
|
---|
| 104 |
|
---|
| 105 | tmpCount += ( /*dummy*/ (inVal) == 0.0)?0:1;
|
---|
| 106 | }
|
---|
| 107 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 108 | tmpOut++;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | #endregion
|
---|
| 113 | } else {
|
---|
| 114 | #region physical along abitrary dimension
|
---|
| 115 | // sum along abitrary dimension
|
---|
| 116 | unsafe {
|
---|
| 117 | fixed ( byte* pOutArr = retArr)
|
---|
| 118 | fixed ( double* pInArr = A.GetArrayForRead()) {
|
---|
| 119 |
|
---|
| 120 | byte* lastElementOut = newLength + pOutArr - 1;
|
---|
| 121 | int inLength = inDim.NumberOfElements - 1;
|
---|
| 122 |
|
---|
| 123 | double* lastElementIn = pInArr + inLength;
|
---|
| 124 | int inc = inDim.SequentialIndexDistance(dim);
|
---|
| 125 |
|
---|
| 126 | byte* tmpOut = pOutArr;
|
---|
| 127 | int outLength = newLength - 1;
|
---|
| 128 |
|
---|
| 129 | double* leadEnd;
|
---|
| 130 |
|
---|
| 131 | double* tmpIn = pInArr;
|
---|
| 132 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 133 | leadEnd = tmpIn + dimLen * inc;
|
---|
| 134 |
|
---|
| 135 | while (tmpIn < leadEnd) {
|
---|
| 136 |
|
---|
| 137 | double inVal = *(tmpIn);
|
---|
| 138 | tmpIn += inc;
|
---|
| 139 | if (double.IsNaN(inVal)) continue;
|
---|
| 140 |
|
---|
| 141 | tmpCount += ( /*dummy*/ (inVal) == 0.0)?0:1; //
|
---|
| 142 | }
|
---|
| 143 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 144 | tmpOut += inc;
|
---|
| 145 | if (tmpOut > lastElementOut)
|
---|
| 146 | tmpOut = pOutArr + ((tmpOut - pOutArr) - outLength);
|
---|
| 147 | if (tmpIn > lastElementIn)
|
---|
| 148 | tmpIn = pInArr + ((tmpIn - pInArr) - inLength);
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 | }
|
---|
| 152 | #endregion
|
---|
| 153 | }
|
---|
| 154 | return new ILRetLogical(retArr, newDims);
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 | /// <summary>Determine, if any elements are nonzero</summary>
|
---|
| 158 | /// <param name="A">Input array</param>
|
---|
| 159 | /// <param name="dim">[Optional] Index of the dimension to operate along. If omitted operates along the first non singleton dimension (i.e. != 1).</param>
|
---|
| 160 | /// <returns><para>Array of same size as A, having the specified or first non-singleton dimension reduced to 1, if any elements along that dimension are non-zero, '0' else. </para></returns>
|
---|
| 161 | public static ILRetLogical any (ILInArray<Int64> A, int dim = -1) {
|
---|
| 162 | using (ILScope.Enter(A)) {
|
---|
| 163 | if (dim < 0)
|
---|
| 164 | dim = A.Size.WorkingDimension();
|
---|
| 165 | if (dim >= A.Size.NumberOfDimensions)
|
---|
| 166 | throw new ILArgumentException("dimension parameter out of range!");
|
---|
| 167 | if (A.IsEmpty)
|
---|
| 168 | return new ILRetLogical(A.Size);
|
---|
| 169 | if (A.IsScalar) {
|
---|
| 170 | return new ILRetLogical (new byte [1]{(A.GetValue(0) == 0)?(byte)0:(byte)1},1,1);
|
---|
| 171 | }
|
---|
| 172 | ILSize inDim = A.Size;
|
---|
| 173 | int[] newDims = inDim.ToIntArray();
|
---|
| 174 | int tmpCount = 0;
|
---|
| 175 |
|
---|
| 176 | int newLength;
|
---|
| 177 |
|
---|
| 178 | byte[] retArr;
|
---|
| 179 | // build ILSize
|
---|
| 180 | newLength = inDim.NumberOfElements / newDims[dim];
|
---|
| 181 | newDims[dim] = 1;
|
---|
| 182 | retArr = ILMemoryPool.Pool.New< byte>(newLength);
|
---|
| 183 | ILSize newDimension = new ILSize(newDims);
|
---|
| 184 | int incOut = newDimension.SequentialIndexDistance(dim);
|
---|
| 185 | int dimLen = inDim[dim];
|
---|
| 186 | int nrHigherDims = inDim.NumberOfElements / dimLen;
|
---|
| 187 | if (dim == 0) {
|
---|
| 188 | #region physical along 1st leading dimension
|
---|
| 189 | unsafe {
|
---|
| 190 | fixed ( byte* pOutArr = retArr)
|
---|
| 191 | fixed ( Int64* pInArr = A.GetArrayForRead()) {
|
---|
| 192 |
|
---|
| 193 | Int64* lastElement;
|
---|
| 194 |
|
---|
| 195 | byte* tmpOut = pOutArr;
|
---|
| 196 |
|
---|
| 197 | Int64* tmpIn = pInArr;
|
---|
| 198 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 199 | lastElement = tmpIn + dimLen;
|
---|
| 200 |
|
---|
| 201 | while (tmpIn < lastElement) {
|
---|
| 202 |
|
---|
| 203 | Int64 inVal = *(tmpIn++);
|
---|
| 204 |
|
---|
| 205 |
|
---|
| 206 | tmpCount += ( /*dummy*/ (inVal) == 0)?0:1;
|
---|
| 207 | }
|
---|
| 208 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 209 | tmpOut++;
|
---|
| 210 | }
|
---|
| 211 | }
|
---|
| 212 | }
|
---|
| 213 | #endregion
|
---|
| 214 | } else {
|
---|
| 215 | #region physical along abitrary dimension
|
---|
| 216 | // sum along abitrary dimension
|
---|
| 217 | unsafe {
|
---|
| 218 | fixed ( byte* pOutArr = retArr)
|
---|
| 219 | fixed ( Int64* pInArr = A.GetArrayForRead()) {
|
---|
| 220 |
|
---|
| 221 | byte* lastElementOut = newLength + pOutArr - 1;
|
---|
| 222 | int inLength = inDim.NumberOfElements - 1;
|
---|
| 223 |
|
---|
| 224 | Int64* lastElementIn = pInArr + inLength;
|
---|
| 225 | int inc = inDim.SequentialIndexDistance(dim);
|
---|
| 226 |
|
---|
| 227 | byte* tmpOut = pOutArr;
|
---|
| 228 | int outLength = newLength - 1;
|
---|
| 229 |
|
---|
| 230 | Int64* leadEnd;
|
---|
| 231 |
|
---|
| 232 | Int64* tmpIn = pInArr;
|
---|
| 233 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 234 | leadEnd = tmpIn + dimLen * inc;
|
---|
| 235 |
|
---|
| 236 | while (tmpIn < leadEnd) {
|
---|
| 237 |
|
---|
| 238 | Int64 inVal = *(tmpIn);
|
---|
| 239 | tmpIn += inc;
|
---|
| 240 |
|
---|
| 241 |
|
---|
| 242 | tmpCount += ( /*dummy*/ (inVal) == 0)?0:1; //
|
---|
| 243 | }
|
---|
| 244 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 245 | tmpOut += inc;
|
---|
| 246 | if (tmpOut > lastElementOut)
|
---|
| 247 | tmpOut = pOutArr + ((tmpOut - pOutArr) - outLength);
|
---|
| 248 | if (tmpIn > lastElementIn)
|
---|
| 249 | tmpIn = pInArr + ((tmpIn - pInArr) - inLength);
|
---|
| 250 | }
|
---|
| 251 | }
|
---|
| 252 | }
|
---|
| 253 | #endregion
|
---|
| 254 | }
|
---|
| 255 | return new ILRetLogical(retArr, newDims);
|
---|
| 256 | }
|
---|
| 257 | }
|
---|
| 258 | /// <summary>Determine, if any elements are nonzero</summary>
|
---|
| 259 | /// <param name="A">Input array</param>
|
---|
| 260 | /// <param name="dim">[Optional] Index of the dimension to operate along. If omitted operates along the first non singleton dimension (i.e. != 1).</param>
|
---|
| 261 | /// <returns><para>Array of same size as A, having the specified or first non-singleton dimension reduced to 1, if any elements along that dimension are non-zero, '0' else. </para></returns>
|
---|
| 262 | public static ILRetLogical any (ILInArray<Int32> A, int dim = -1) {
|
---|
| 263 | using (ILScope.Enter(A)) {
|
---|
| 264 | if (dim < 0)
|
---|
| 265 | dim = A.Size.WorkingDimension();
|
---|
| 266 | if (dim >= A.Size.NumberOfDimensions)
|
---|
| 267 | throw new ILArgumentException("dimension parameter out of range!");
|
---|
| 268 | if (A.IsEmpty)
|
---|
| 269 | return new ILRetLogical(A.Size);
|
---|
| 270 | if (A.IsScalar) {
|
---|
| 271 | return new ILRetLogical (new byte [1]{(A.GetValue(0) == 0)?(byte)0:(byte)1},1,1);
|
---|
| 272 | }
|
---|
| 273 | ILSize inDim = A.Size;
|
---|
| 274 | int[] newDims = inDim.ToIntArray();
|
---|
| 275 | int tmpCount = 0;
|
---|
| 276 |
|
---|
| 277 | int newLength;
|
---|
| 278 |
|
---|
| 279 | byte[] retArr;
|
---|
| 280 | // build ILSize
|
---|
| 281 | newLength = inDim.NumberOfElements / newDims[dim];
|
---|
| 282 | newDims[dim] = 1;
|
---|
| 283 | retArr = ILMemoryPool.Pool.New< byte>(newLength);
|
---|
| 284 | ILSize newDimension = new ILSize(newDims);
|
---|
| 285 | int incOut = newDimension.SequentialIndexDistance(dim);
|
---|
| 286 | int dimLen = inDim[dim];
|
---|
| 287 | int nrHigherDims = inDim.NumberOfElements / dimLen;
|
---|
| 288 | if (dim == 0) {
|
---|
| 289 | #region physical along 1st leading dimension
|
---|
| 290 | unsafe {
|
---|
| 291 | fixed ( byte* pOutArr = retArr)
|
---|
| 292 | fixed ( Int32* pInArr = A.GetArrayForRead()) {
|
---|
| 293 |
|
---|
| 294 | Int32* lastElement;
|
---|
| 295 |
|
---|
| 296 | byte* tmpOut = pOutArr;
|
---|
| 297 |
|
---|
| 298 | Int32* tmpIn = pInArr;
|
---|
| 299 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 300 | lastElement = tmpIn + dimLen;
|
---|
| 301 |
|
---|
| 302 | while (tmpIn < lastElement) {
|
---|
| 303 |
|
---|
| 304 | Int32 inVal = *(tmpIn++);
|
---|
| 305 |
|
---|
| 306 |
|
---|
| 307 | tmpCount += ( /*dummy*/ (inVal) == 0)?0:1;
|
---|
| 308 | }
|
---|
| 309 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 310 | tmpOut++;
|
---|
| 311 | }
|
---|
| 312 | }
|
---|
| 313 | }
|
---|
| 314 | #endregion
|
---|
| 315 | } else {
|
---|
| 316 | #region physical along abitrary dimension
|
---|
| 317 | // sum along abitrary dimension
|
---|
| 318 | unsafe {
|
---|
| 319 | fixed ( byte* pOutArr = retArr)
|
---|
| 320 | fixed ( Int32* pInArr = A.GetArrayForRead()) {
|
---|
| 321 |
|
---|
| 322 | byte* lastElementOut = newLength + pOutArr - 1;
|
---|
| 323 | int inLength = inDim.NumberOfElements - 1;
|
---|
| 324 |
|
---|
| 325 | Int32* lastElementIn = pInArr + inLength;
|
---|
| 326 | int inc = inDim.SequentialIndexDistance(dim);
|
---|
| 327 |
|
---|
| 328 | byte* tmpOut = pOutArr;
|
---|
| 329 | int outLength = newLength - 1;
|
---|
| 330 |
|
---|
| 331 | Int32* leadEnd;
|
---|
| 332 |
|
---|
| 333 | Int32* tmpIn = pInArr;
|
---|
| 334 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 335 | leadEnd = tmpIn + dimLen * inc;
|
---|
| 336 |
|
---|
| 337 | while (tmpIn < leadEnd) {
|
---|
| 338 |
|
---|
| 339 | Int32 inVal = *(tmpIn);
|
---|
| 340 | tmpIn += inc;
|
---|
| 341 |
|
---|
| 342 |
|
---|
| 343 | tmpCount += ( /*dummy*/ (inVal) == 0)?0:1; //
|
---|
| 344 | }
|
---|
| 345 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 346 | tmpOut += inc;
|
---|
| 347 | if (tmpOut > lastElementOut)
|
---|
| 348 | tmpOut = pOutArr + ((tmpOut - pOutArr) - outLength);
|
---|
| 349 | if (tmpIn > lastElementIn)
|
---|
| 350 | tmpIn = pInArr + ((tmpIn - pInArr) - inLength);
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
| 353 | }
|
---|
| 354 | #endregion
|
---|
| 355 | }
|
---|
| 356 | return new ILRetLogical(retArr, newDims);
|
---|
| 357 | }
|
---|
| 358 | }
|
---|
| 359 | /// <summary>Determine, if any elements are nonzero</summary>
|
---|
| 360 | /// <param name="A">Input array</param>
|
---|
| 361 | /// <param name="dim">[Optional] Index of the dimension to operate along. If omitted operates along the first non singleton dimension (i.e. != 1).</param>
|
---|
| 362 | /// <returns><para>Array of same size as A, having the specified or first non-singleton dimension reduced to 1, if any elements along that dimension are non-zero, '0' else. </para></returns>
|
---|
| 363 | public static ILRetLogical any (ILInArray<byte> A, int dim = -1) {
|
---|
| 364 | using (ILScope.Enter(A)) {
|
---|
| 365 | if (dim < 0)
|
---|
| 366 | dim = A.Size.WorkingDimension();
|
---|
| 367 | if (dim >= A.Size.NumberOfDimensions)
|
---|
| 368 | throw new ILArgumentException("dimension parameter out of range!");
|
---|
| 369 | if (A.IsEmpty)
|
---|
| 370 | return new ILRetLogical(A.Size);
|
---|
| 371 | if (A.IsScalar) {
|
---|
| 372 | return new ILRetLogical (new byte [1]{(A.GetValue(0) == 0)?(byte)0:(byte)1},1,1);
|
---|
| 373 | }
|
---|
| 374 | ILSize inDim = A.Size;
|
---|
| 375 | int[] newDims = inDim.ToIntArray();
|
---|
| 376 | int tmpCount = 0;
|
---|
| 377 |
|
---|
| 378 | int newLength;
|
---|
| 379 |
|
---|
| 380 | byte[] retArr;
|
---|
| 381 | // build ILSize
|
---|
| 382 | newLength = inDim.NumberOfElements / newDims[dim];
|
---|
| 383 | newDims[dim] = 1;
|
---|
| 384 | retArr = ILMemoryPool.Pool.New< byte>(newLength);
|
---|
| 385 | ILSize newDimension = new ILSize(newDims);
|
---|
| 386 | int incOut = newDimension.SequentialIndexDistance(dim);
|
---|
| 387 | int dimLen = inDim[dim];
|
---|
| 388 | int nrHigherDims = inDim.NumberOfElements / dimLen;
|
---|
| 389 | if (dim == 0) {
|
---|
| 390 | #region physical along 1st leading dimension
|
---|
| 391 | unsafe {
|
---|
| 392 | fixed ( byte* pOutArr = retArr)
|
---|
| 393 | fixed ( byte* pInArr = A.GetArrayForRead()) {
|
---|
| 394 |
|
---|
| 395 | byte* lastElement;
|
---|
| 396 |
|
---|
| 397 | byte* tmpOut = pOutArr;
|
---|
| 398 |
|
---|
| 399 | byte* tmpIn = pInArr;
|
---|
| 400 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 401 | lastElement = tmpIn + dimLen;
|
---|
| 402 |
|
---|
| 403 | while (tmpIn < lastElement) {
|
---|
| 404 |
|
---|
| 405 | byte inVal = *(tmpIn++);
|
---|
| 406 |
|
---|
| 407 |
|
---|
| 408 | tmpCount += ( /*dummy*/ (inVal) == 0)?0:1;
|
---|
| 409 | }
|
---|
| 410 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 411 | tmpOut++;
|
---|
| 412 | }
|
---|
| 413 | }
|
---|
| 414 | }
|
---|
| 415 | #endregion
|
---|
| 416 | } else {
|
---|
| 417 | #region physical along abitrary dimension
|
---|
| 418 | // sum along abitrary dimension
|
---|
| 419 | unsafe {
|
---|
| 420 | fixed ( byte* pOutArr = retArr)
|
---|
| 421 | fixed ( byte* pInArr = A.GetArrayForRead()) {
|
---|
| 422 |
|
---|
| 423 | byte* lastElementOut = newLength + pOutArr - 1;
|
---|
| 424 | int inLength = inDim.NumberOfElements - 1;
|
---|
| 425 |
|
---|
| 426 | byte* lastElementIn = pInArr + inLength;
|
---|
| 427 | int inc = inDim.SequentialIndexDistance(dim);
|
---|
| 428 |
|
---|
| 429 | byte* tmpOut = pOutArr;
|
---|
| 430 | int outLength = newLength - 1;
|
---|
| 431 |
|
---|
| 432 | byte* leadEnd;
|
---|
| 433 |
|
---|
| 434 | byte* tmpIn = pInArr;
|
---|
| 435 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 436 | leadEnd = tmpIn + dimLen * inc;
|
---|
| 437 |
|
---|
| 438 | while (tmpIn < leadEnd) {
|
---|
| 439 |
|
---|
| 440 | byte inVal = *(tmpIn);
|
---|
| 441 | tmpIn += inc;
|
---|
| 442 |
|
---|
| 443 |
|
---|
| 444 | tmpCount += ( /*dummy*/ (inVal) == 0)?0:1; //
|
---|
| 445 | }
|
---|
| 446 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 447 | tmpOut += inc;
|
---|
| 448 | if (tmpOut > lastElementOut)
|
---|
| 449 | tmpOut = pOutArr + ((tmpOut - pOutArr) - outLength);
|
---|
| 450 | if (tmpIn > lastElementIn)
|
---|
| 451 | tmpIn = pInArr + ((tmpIn - pInArr) - inLength);
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
| 455 | #endregion
|
---|
| 456 | }
|
---|
| 457 | return new ILRetLogical(retArr, newDims);
|
---|
| 458 | }
|
---|
| 459 | }
|
---|
| 460 | /// <summary>Determine, if any elements are nonzero</summary>
|
---|
| 461 | /// <param name="A">Input array</param>
|
---|
| 462 | /// <param name="dim">[Optional] Index of the dimension to operate along. If omitted operates along the first non singleton dimension (i.e. != 1).</param>
|
---|
| 463 | /// <returns><para>Array of same size as A, having the specified or first non-singleton dimension reduced to 1, if any elements along that dimension are non-zero, '0' else. </para></returns>
|
---|
| 464 | public static ILRetLogical any (ILInArray<fcomplex> A, int dim = -1) {
|
---|
| 465 | using (ILScope.Enter(A)) {
|
---|
| 466 | if (dim < 0)
|
---|
| 467 | dim = A.Size.WorkingDimension();
|
---|
| 468 | if (dim >= A.Size.NumberOfDimensions)
|
---|
| 469 | throw new ILArgumentException("dimension parameter out of range!");
|
---|
| 470 | if (A.IsEmpty)
|
---|
| 471 | return new ILRetLogical(A.Size);
|
---|
| 472 | if (A.IsScalar) {
|
---|
| 473 | return new ILRetLogical (new byte [1]{(A.GetValue(0).iszero() || fcomplex.IsNaN(A.GetValue(0)))?(byte)1:(byte)0},1,1);
|
---|
| 474 | }
|
---|
| 475 | ILSize inDim = A.Size;
|
---|
| 476 | int[] newDims = inDim.ToIntArray();
|
---|
| 477 | int tmpCount = 0;
|
---|
| 478 |
|
---|
| 479 | int newLength;
|
---|
| 480 |
|
---|
| 481 | byte[] retArr;
|
---|
| 482 | // build ILSize
|
---|
| 483 | newLength = inDim.NumberOfElements / newDims[dim];
|
---|
| 484 | newDims[dim] = 1;
|
---|
| 485 | retArr = ILMemoryPool.Pool.New< byte>(newLength);
|
---|
| 486 | ILSize newDimension = new ILSize(newDims);
|
---|
| 487 | int incOut = newDimension.SequentialIndexDistance(dim);
|
---|
| 488 | int dimLen = inDim[dim];
|
---|
| 489 | int nrHigherDims = inDim.NumberOfElements / dimLen;
|
---|
| 490 | if (dim == 0) {
|
---|
| 491 | #region physical along 1st leading dimension
|
---|
| 492 | unsafe {
|
---|
| 493 | fixed ( byte* pOutArr = retArr)
|
---|
| 494 | fixed ( fcomplex* pInArr = A.GetArrayForRead()) {
|
---|
| 495 |
|
---|
| 496 | fcomplex* lastElement;
|
---|
| 497 |
|
---|
| 498 | byte* tmpOut = pOutArr;
|
---|
| 499 |
|
---|
| 500 | fcomplex* tmpIn = pInArr;
|
---|
| 501 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 502 | lastElement = tmpIn + dimLen;
|
---|
| 503 |
|
---|
| 504 | while (tmpIn < lastElement) {
|
---|
| 505 |
|
---|
| 506 | fcomplex inVal = *(tmpIn++);
|
---|
| 507 | if (fcomplex.IsNaN(inVal)) continue;
|
---|
| 508 |
|
---|
| 509 | tmpCount += ( /*dummy*/ (inVal) .iszero())?0:1;
|
---|
| 510 | }
|
---|
| 511 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 512 | tmpOut++;
|
---|
| 513 | }
|
---|
| 514 | }
|
---|
| 515 | }
|
---|
| 516 | #endregion
|
---|
| 517 | } else {
|
---|
| 518 | #region physical along abitrary dimension
|
---|
| 519 | // sum along abitrary dimension
|
---|
| 520 | unsafe {
|
---|
| 521 | fixed ( byte* pOutArr = retArr)
|
---|
| 522 | fixed ( fcomplex* pInArr = A.GetArrayForRead()) {
|
---|
| 523 |
|
---|
| 524 | byte* lastElementOut = newLength + pOutArr - 1;
|
---|
| 525 | int inLength = inDim.NumberOfElements - 1;
|
---|
| 526 |
|
---|
| 527 | fcomplex* lastElementIn = pInArr + inLength;
|
---|
| 528 | int inc = inDim.SequentialIndexDistance(dim);
|
---|
| 529 |
|
---|
| 530 | byte* tmpOut = pOutArr;
|
---|
| 531 | int outLength = newLength - 1;
|
---|
| 532 |
|
---|
| 533 | fcomplex* leadEnd;
|
---|
| 534 |
|
---|
| 535 | fcomplex* tmpIn = pInArr;
|
---|
| 536 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 537 | leadEnd = tmpIn + dimLen * inc;
|
---|
| 538 |
|
---|
| 539 | while (tmpIn < leadEnd) {
|
---|
| 540 |
|
---|
| 541 | fcomplex inVal = *(tmpIn);
|
---|
| 542 | tmpIn += inc;
|
---|
| 543 | if (fcomplex.IsNaN(inVal)) continue;
|
---|
| 544 |
|
---|
| 545 | tmpCount += ( /*dummy*/ (inVal) .iszero())?0:1; //
|
---|
| 546 | }
|
---|
| 547 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 548 | tmpOut += inc;
|
---|
| 549 | if (tmpOut > lastElementOut)
|
---|
| 550 | tmpOut = pOutArr + ((tmpOut - pOutArr) - outLength);
|
---|
| 551 | if (tmpIn > lastElementIn)
|
---|
| 552 | tmpIn = pInArr + ((tmpIn - pInArr) - inLength);
|
---|
| 553 | }
|
---|
| 554 | }
|
---|
| 555 | }
|
---|
| 556 | #endregion
|
---|
| 557 | }
|
---|
| 558 | return new ILRetLogical(retArr, newDims);
|
---|
| 559 | }
|
---|
| 560 | }
|
---|
| 561 | /// <summary>Determine, if any elements are nonzero</summary>
|
---|
| 562 | /// <param name="A">Input array</param>
|
---|
| 563 | /// <param name="dim">[Optional] Index of the dimension to operate along. If omitted operates along the first non singleton dimension (i.e. != 1).</param>
|
---|
| 564 | /// <returns><para>Array of same size as A, having the specified or first non-singleton dimension reduced to 1, if any elements along that dimension are non-zero, '0' else. </para></returns>
|
---|
| 565 | public static ILRetLogical any (ILInArray<float> A, int dim = -1) {
|
---|
| 566 | using (ILScope.Enter(A)) {
|
---|
| 567 | if (dim < 0)
|
---|
| 568 | dim = A.Size.WorkingDimension();
|
---|
| 569 | if (dim >= A.Size.NumberOfDimensions)
|
---|
| 570 | throw new ILArgumentException("dimension parameter out of range!");
|
---|
| 571 | if (A.IsEmpty)
|
---|
| 572 | return new ILRetLogical(A.Size);
|
---|
| 573 | if (A.IsScalar) {
|
---|
| 574 | return new ILRetLogical (new byte [1]{(A.GetValue(0) == 0.0f || float.IsNaN(A.GetValue(0)))?(byte)0:(byte)1},1,1);
|
---|
| 575 | }
|
---|
| 576 | ILSize inDim = A.Size;
|
---|
| 577 | int[] newDims = inDim.ToIntArray();
|
---|
| 578 | int tmpCount = 0;
|
---|
| 579 |
|
---|
| 580 | int newLength;
|
---|
| 581 |
|
---|
| 582 | byte[] retArr;
|
---|
| 583 | // build ILSize
|
---|
| 584 | newLength = inDim.NumberOfElements / newDims[dim];
|
---|
| 585 | newDims[dim] = 1;
|
---|
| 586 | retArr = ILMemoryPool.Pool.New< byte>(newLength);
|
---|
| 587 | ILSize newDimension = new ILSize(newDims);
|
---|
| 588 | int incOut = newDimension.SequentialIndexDistance(dim);
|
---|
| 589 | int dimLen = inDim[dim];
|
---|
| 590 | int nrHigherDims = inDim.NumberOfElements / dimLen;
|
---|
| 591 | if (dim == 0) {
|
---|
| 592 | #region physical along 1st leading dimension
|
---|
| 593 | unsafe {
|
---|
| 594 | fixed ( byte* pOutArr = retArr)
|
---|
| 595 | fixed ( float* pInArr = A.GetArrayForRead()) {
|
---|
| 596 |
|
---|
| 597 | float* lastElement;
|
---|
| 598 |
|
---|
| 599 | byte* tmpOut = pOutArr;
|
---|
| 600 |
|
---|
| 601 | float* tmpIn = pInArr;
|
---|
| 602 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 603 | lastElement = tmpIn + dimLen;
|
---|
| 604 |
|
---|
| 605 | while (tmpIn < lastElement) {
|
---|
| 606 |
|
---|
| 607 | float inVal = *(tmpIn++);
|
---|
| 608 | if (float.IsNaN(inVal)) continue;
|
---|
| 609 |
|
---|
| 610 | tmpCount += ( /*dummy*/ (inVal) == 0.0f)?0:1;
|
---|
| 611 | }
|
---|
| 612 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 613 | tmpOut++;
|
---|
| 614 | }
|
---|
| 615 | }
|
---|
| 616 | }
|
---|
| 617 | #endregion
|
---|
| 618 | } else {
|
---|
| 619 | #region physical along abitrary dimension
|
---|
| 620 | // sum along abitrary dimension
|
---|
| 621 | unsafe {
|
---|
| 622 | fixed ( byte* pOutArr = retArr)
|
---|
| 623 | fixed ( float* pInArr = A.GetArrayForRead()) {
|
---|
| 624 |
|
---|
| 625 | byte* lastElementOut = newLength + pOutArr - 1;
|
---|
| 626 | int inLength = inDim.NumberOfElements - 1;
|
---|
| 627 |
|
---|
| 628 | float* lastElementIn = pInArr + inLength;
|
---|
| 629 | int inc = inDim.SequentialIndexDistance(dim);
|
---|
| 630 |
|
---|
| 631 | byte* tmpOut = pOutArr;
|
---|
| 632 | int outLength = newLength - 1;
|
---|
| 633 |
|
---|
| 634 | float* leadEnd;
|
---|
| 635 |
|
---|
| 636 | float* tmpIn = pInArr;
|
---|
| 637 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 638 | leadEnd = tmpIn + dimLen * inc;
|
---|
| 639 |
|
---|
| 640 | while (tmpIn < leadEnd) {
|
---|
| 641 |
|
---|
| 642 | float inVal = *(tmpIn);
|
---|
| 643 | tmpIn += inc;
|
---|
| 644 | if (float.IsNaN(inVal)) continue;
|
---|
| 645 |
|
---|
| 646 | tmpCount += ( /*dummy*/ (inVal) == 0.0f)?0:1; //
|
---|
| 647 | }
|
---|
| 648 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 649 | tmpOut += inc;
|
---|
| 650 | if (tmpOut > lastElementOut)
|
---|
| 651 | tmpOut = pOutArr + ((tmpOut - pOutArr) - outLength);
|
---|
| 652 | if (tmpIn > lastElementIn)
|
---|
| 653 | tmpIn = pInArr + ((tmpIn - pInArr) - inLength);
|
---|
| 654 | }
|
---|
| 655 | }
|
---|
| 656 | }
|
---|
| 657 | #endregion
|
---|
| 658 | }
|
---|
| 659 | return new ILRetLogical(retArr, newDims);
|
---|
| 660 | }
|
---|
| 661 | }
|
---|
| 662 | /// <summary>Determine, if any elements are nonzero</summary>
|
---|
| 663 | /// <param name="A">Input array</param>
|
---|
| 664 | /// <param name="dim">[Optional] Index of the dimension to operate along. If omitted operates along the first non singleton dimension (i.e. != 1).</param>
|
---|
| 665 | /// <returns><para>Array of same size as A, having the specified or first non-singleton dimension reduced to 1, if any elements along that dimension are non-zero, '0' else. </para></returns>
|
---|
| 666 | public static ILRetLogical any (ILInArray<complex> A, int dim = -1) {
|
---|
| 667 | using (ILScope.Enter(A)) {
|
---|
| 668 | if (dim < 0)
|
---|
| 669 | dim = A.Size.WorkingDimension();
|
---|
| 670 | if (dim >= A.Size.NumberOfDimensions)
|
---|
| 671 | throw new ILArgumentException("dimension parameter out of range!");
|
---|
| 672 | if (A.IsEmpty)
|
---|
| 673 | return new ILRetLogical(A.Size);
|
---|
| 674 | if (A.IsScalar) {
|
---|
| 675 | return new ILRetLogical (new byte [1]{(A.GetValue(0).iszero() || complex.IsNaN(A.GetValue(0)))?(byte)0:(byte)1},1,1);
|
---|
| 676 | }
|
---|
| 677 | ILSize inDim = A.Size;
|
---|
| 678 | int[] newDims = inDim.ToIntArray();
|
---|
| 679 | int tmpCount = 0;
|
---|
| 680 |
|
---|
| 681 | int newLength;
|
---|
| 682 |
|
---|
| 683 | byte[] retArr;
|
---|
| 684 | // build ILSize
|
---|
| 685 | newLength = inDim.NumberOfElements / newDims[dim];
|
---|
| 686 | newDims[dim] = 1;
|
---|
| 687 | retArr = ILMemoryPool.Pool.New< byte>(newLength);
|
---|
| 688 | ILSize newDimension = new ILSize(newDims);
|
---|
| 689 | int incOut = newDimension.SequentialIndexDistance(dim);
|
---|
| 690 | int dimLen = inDim[dim];
|
---|
| 691 | int nrHigherDims = inDim.NumberOfElements / dimLen;
|
---|
| 692 | if (dim == 0) {
|
---|
| 693 | #region physical along 1st leading dimension
|
---|
| 694 | unsafe {
|
---|
| 695 | fixed ( byte* pOutArr = retArr)
|
---|
| 696 | fixed ( complex* pInArr = A.GetArrayForRead()) {
|
---|
| 697 |
|
---|
| 698 | complex* lastElement;
|
---|
| 699 |
|
---|
| 700 | byte* tmpOut = pOutArr;
|
---|
| 701 |
|
---|
| 702 | complex* tmpIn = pInArr;
|
---|
| 703 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 704 | lastElement = tmpIn + dimLen;
|
---|
| 705 |
|
---|
| 706 | while (tmpIn < lastElement) {
|
---|
| 707 |
|
---|
| 708 | complex inVal = *(tmpIn++);
|
---|
| 709 | if (complex.IsNaN(inVal)) continue;
|
---|
| 710 |
|
---|
| 711 | tmpCount += ( /*dummy*/ (inVal) .iszero())?0:1;
|
---|
| 712 | }
|
---|
| 713 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 714 | tmpOut++;
|
---|
| 715 | }
|
---|
| 716 | }
|
---|
| 717 | }
|
---|
| 718 | #endregion
|
---|
| 719 | } else {
|
---|
| 720 | #region physical along abitrary dimension
|
---|
| 721 | // sum along abitrary dimension
|
---|
| 722 | unsafe {
|
---|
| 723 | fixed ( byte* pOutArr = retArr)
|
---|
| 724 | fixed ( complex* pInArr = A.GetArrayForRead()) {
|
---|
| 725 |
|
---|
| 726 | byte* lastElementOut = newLength + pOutArr - 1;
|
---|
| 727 | int inLength = inDim.NumberOfElements - 1;
|
---|
| 728 |
|
---|
| 729 | complex* lastElementIn = pInArr + inLength;
|
---|
| 730 | int inc = inDim.SequentialIndexDistance(dim);
|
---|
| 731 |
|
---|
| 732 | byte* tmpOut = pOutArr;
|
---|
| 733 | int outLength = newLength - 1;
|
---|
| 734 |
|
---|
| 735 | complex* leadEnd;
|
---|
| 736 |
|
---|
| 737 | complex* tmpIn = pInArr;
|
---|
| 738 | for (int h = nrHigherDims; h-- > 0; ) {
|
---|
| 739 | leadEnd = tmpIn + dimLen * inc;
|
---|
| 740 |
|
---|
| 741 | while (tmpIn < leadEnd) {
|
---|
| 742 |
|
---|
| 743 | complex inVal = *(tmpIn);
|
---|
| 744 | tmpIn += inc;
|
---|
| 745 | if (complex.IsNaN(inVal)) continue;
|
---|
| 746 |
|
---|
| 747 | tmpCount += ( /*dummy*/ (inVal) .iszero())?0:1; //
|
---|
| 748 | }
|
---|
| 749 | *tmpOut = (tmpCount == 0)? (byte)0:(byte)1; tmpCount = 0;
|
---|
| 750 | tmpOut += inc;
|
---|
| 751 | if (tmpOut > lastElementOut)
|
---|
| 752 | tmpOut = pOutArr + ((tmpOut - pOutArr) - outLength);
|
---|
| 753 | if (tmpIn > lastElementIn)
|
---|
| 754 | tmpIn = pInArr + ((tmpIn - pInArr) - inLength);
|
---|
| 755 | }
|
---|
| 756 | }
|
---|
| 757 | }
|
---|
| 758 | #endregion
|
---|
| 759 | }
|
---|
| 760 | return new ILRetLogical(retArr, newDims);
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
| 763 |
|
---|
| 764 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 765 | }
|
---|
| 766 | }
|
---|