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