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