[9102] | 1 | ///
|
---|
| 2 | /// This file is part of ILNumerics Community Edition.
|
---|
| 3 | ///
|
---|
| 4 | /// ILNumerics Community Edition - high performance computing for applications.
|
---|
| 5 | /// Copyright (C) 2006 - 2012 Haymo Kutschbach, http://ilnumerics.net
|
---|
| 6 | ///
|
---|
| 7 | /// ILNumerics Community Edition is free software: you can redistribute it and/or modify
|
---|
| 8 | /// it under the terms of the GNU General Public License version 3 as published by
|
---|
| 9 | /// the Free Software Foundation.
|
---|
| 10 | ///
|
---|
| 11 | /// ILNumerics Community Edition is distributed in the hope that it will be useful,
|
---|
| 12 | /// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 13 | /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 14 | /// GNU General Public License for more details.
|
---|
| 15 | ///
|
---|
| 16 | /// You should have received a copy of the GNU General Public License
|
---|
| 17 | /// along with ILNumerics Community Edition. See the file License.txt in the root
|
---|
| 18 | /// of your distribution package. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | ///
|
---|
| 20 | /// In addition this software uses the following components and/or licenses:
|
---|
| 21 | ///
|
---|
| 22 | /// =================================================================================
|
---|
| 23 | /// The Open Toolkit Library License
|
---|
| 24 | ///
|
---|
| 25 | /// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
---|
| 26 | ///
|
---|
| 27 | /// Permission is hereby granted, free of charge, to any person obtaining a copy
|
---|
| 28 | /// of this software and associated documentation files (the "Software"), to deal
|
---|
| 29 | /// in the Software without restriction, including without limitation the rights to
|
---|
| 30 | /// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
---|
| 31 | /// the Software, and to permit persons to whom the Software is furnished to do
|
---|
| 32 | /// so, subject to the following conditions:
|
---|
| 33 | ///
|
---|
| 34 | /// The above copyright notice and this permission notice shall be included in all
|
---|
| 35 | /// copies or substantial portions of the Software.
|
---|
| 36 | ///
|
---|
| 37 | /// =================================================================================
|
---|
| 38 | ///
|
---|
| 39 |
|
---|
| 40 | using System;
|
---|
| 41 | using System.Collections.Generic;
|
---|
| 42 | using System.Text;
|
---|
| 43 | using ILNumerics;
|
---|
| 44 | using ILNumerics.Exceptions;
|
---|
| 45 | using ILNumerics.Storage;
|
---|
| 46 | using ILNumerics.Misc;
|
---|
| 47 |
|
---|
| 48 | namespace ILNumerics {
|
---|
| 49 | public partial class ILMath {
|
---|
| 50 |
|
---|
| 51 | |
---|
| 52 |
|
---|
| 53 | /// <summary>
|
---|
| 54 | /// Compares elements of two arrays, assume NaN and +/- infinity values are comparable and equal
|
---|
| 55 | /// </summary>
|
---|
| 56 | /// <param name="A">Input array</param>
|
---|
| 57 | /// <param name="B">Input array</param>
|
---|
| 58 | /// <returns>True, if all elements of both arrays are equal; false if any elements or the sizes are not equal</returns>
|
---|
| 59 | public static bool isequalwithequalnans(ILInArray</*HC:inArr1*/double> A, ILInArray</*HC:inArr1*/double> B) {
|
---|
| 60 | using (ILScope.Enter(A)) {
|
---|
| 61 | if (object.Equals(A, null) || object.Equals(B, null)) {
|
---|
| 62 | return !(object.Equals(A, null) ^ object.Equals(B, null));
|
---|
| 63 | }
|
---|
| 64 | if (A.IsEmpty && B.IsEmpty) return true;
|
---|
| 65 | if (!A.Size.IsSameSize(B.Size)) return false;
|
---|
| 66 | int pos = 0;
|
---|
| 67 | foreach ( double a in A) {
|
---|
| 68 |
|
---|
| 69 | double b = B.GetValue(pos++);
|
---|
| 70 | if ( double.IsNaN(a) && double.IsNaN(b)) continue;
|
---|
| 71 | if ( double.IsInfinity(a) && double.IsInfinity(b)) continue;
|
---|
| 72 | if (b != a) return false;
|
---|
| 73 | }
|
---|
| 74 | return true;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | |
---|
| 78 | #region HYCALPER AUTO GENERATED CODE
|
---|
| 79 | |
---|
| 80 |
|
---|
| 81 | /// <summary>
|
---|
| 82 | /// Compares elements of two arrays, assume NaN and +/- infinity values are comparable and equal
|
---|
| 83 | /// </summary>
|
---|
| 84 | /// <param name="A">Input array</param>
|
---|
| 85 | /// <param name="B">Input array</param>
|
---|
| 86 | /// <returns>True, if all elements of both arrays are equal; false if any elements or the sizes are not equal</returns>
|
---|
| 87 | public static bool isequalwithequalnans(ILInArray</*HC:*/fcomplex> A, ILInArray</*HC:*/fcomplex> B) {
|
---|
| 88 | using (ILScope.Enter(A)) {
|
---|
| 89 | if (object.Equals(A, null) || object.Equals(B, null)) {
|
---|
| 90 | return !(object.Equals(A, null) ^ object.Equals(B, null));
|
---|
| 91 | }
|
---|
| 92 | if (A.IsEmpty && B.IsEmpty) return true;
|
---|
| 93 | if (!A.Size.IsSameSize(B.Size)) return false;
|
---|
| 94 | int pos = 0;
|
---|
| 95 | foreach ( fcomplex a in A) {
|
---|
| 96 |
|
---|
| 97 | fcomplex b = B.GetValue(pos++);
|
---|
| 98 | if ( fcomplex.IsNaN(a) && fcomplex.IsNaN(b)) continue;
|
---|
| 99 | if ( fcomplex.IsInfinity(a) && fcomplex.IsInfinity(b)) continue;
|
---|
| 100 | if (b != a) return false;
|
---|
| 101 | }
|
---|
| 102 | return true;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | /// <summary>
|
---|
| 107 | /// Compares elements of two arrays, assume NaN and +/- infinity values are comparable and equal
|
---|
| 108 | /// </summary>
|
---|
| 109 | /// <param name="A">Input array</param>
|
---|
| 110 | /// <param name="B">Input array</param>
|
---|
| 111 | /// <returns>True, if all elements of both arrays are equal; false if any elements or the sizes are not equal</returns>
|
---|
| 112 | public static bool isequalwithequalnans(ILInArray</*HC:*/float> A, ILInArray</*HC:*/float> B) {
|
---|
| 113 | using (ILScope.Enter(A)) {
|
---|
| 114 | if (object.Equals(A, null) || object.Equals(B, null)) {
|
---|
| 115 | return !(object.Equals(A, null) ^ object.Equals(B, null));
|
---|
| 116 | }
|
---|
| 117 | if (A.IsEmpty && B.IsEmpty) return true;
|
---|
| 118 | if (!A.Size.IsSameSize(B.Size)) return false;
|
---|
| 119 | int pos = 0;
|
---|
| 120 | foreach ( float a in A) {
|
---|
| 121 |
|
---|
| 122 | float b = B.GetValue(pos++);
|
---|
| 123 | if ( float.IsNaN(a) && float.IsNaN(b)) continue;
|
---|
| 124 | if ( float.IsInfinity(a) && float.IsInfinity(b)) continue;
|
---|
| 125 | if (b != a) return false;
|
---|
| 126 | }
|
---|
| 127 | return true;
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | /// <summary>
|
---|
| 132 | /// Compares elements of two arrays, assume NaN and +/- infinity values are comparable and equal
|
---|
| 133 | /// </summary>
|
---|
| 134 | /// <param name="A">Input array</param>
|
---|
| 135 | /// <param name="B">Input array</param>
|
---|
| 136 | /// <returns>True, if all elements of both arrays are equal; false if any elements or the sizes are not equal</returns>
|
---|
| 137 | public static bool isequalwithequalnans(ILInArray</*HC:*/complex> A, ILInArray</*HC:*/complex> B) {
|
---|
| 138 | using (ILScope.Enter(A)) {
|
---|
| 139 | if (object.Equals(A, null) || object.Equals(B, null)) {
|
---|
| 140 | return !(object.Equals(A, null) ^ object.Equals(B, null));
|
---|
| 141 | }
|
---|
| 142 | if (A.IsEmpty && B.IsEmpty) return true;
|
---|
| 143 | if (!A.Size.IsSameSize(B.Size)) return false;
|
---|
| 144 | int pos = 0;
|
---|
| 145 | foreach ( complex a in A) {
|
---|
| 146 |
|
---|
| 147 | complex b = B.GetValue(pos++);
|
---|
| 148 | if ( complex.IsNaN(a) && complex.IsNaN(b)) continue;
|
---|
| 149 | if ( complex.IsInfinity(a) && complex.IsInfinity(b)) continue;
|
---|
| 150 | if (b != a) return false;
|
---|
| 151 | }
|
---|
| 152 | return true;
|
---|
| 153 | }
|
---|
| 154 | }
|
---|
| 155 |
|
---|
| 156 | #endregion HYCALPER AUTO GENERATED CODE
|
---|
| 157 |
|
---|
| 158 | /// <summary>
|
---|
| 159 | /// Compare two arrays, assume NaN and +/- infinity values are comparable and equal
|
---|
| 160 | /// </summary>
|
---|
| 161 | /// <param name="A">Input array A</param>
|
---|
| 162 | /// <param name="B">Input array B</param>
|
---|
| 163 | /// <returns>True if all non-NaN elements in A and B equal, false otherwise</returns>
|
---|
| 164 | public static bool isequalwithequalnans(ILBaseArray A, ILBaseArray B) {
|
---|
| 165 | using (ILScope.Enter(A, B)) {
|
---|
| 166 | if (A is ILDenseArray<double>) {
|
---|
| 167 | if (B is ILDenseArray<double>) {
|
---|
| 168 | return isequalwithequalnans((A as ILDenseArray<double>).C, (B as ILDenseArray<double>).C);
|
---|
| 169 | } else if (B is ILDenseArray<complex>) {
|
---|
| 170 | ILArray<complex> Bc = (B as ILDenseArray<complex>).C;
|
---|
| 171 | if (Bc == null) return false;
|
---|
| 172 | if (any(imag(Bc)).NumberNonZero > 0) return false;
|
---|
| 173 | return isequalwithequalnans((A as ILDenseArray<double>).C, real(Bc));
|
---|
| 174 | } return false;
|
---|
| 175 | } else if (A is ILDenseArray<float>) {
|
---|
| 176 | if (B is ILDenseArray<float>) {
|
---|
| 177 | return isequalwithequalnans((A as ILDenseArray<float>).C, (B as ILDenseArray<float>).C);
|
---|
| 178 | } else if (B is ILDenseArray<fcomplex>) {
|
---|
| 179 | ILArray<fcomplex> Bf = (B as ILDenseArray<fcomplex>).C;
|
---|
| 180 | if (Bf == null) return false;
|
---|
| 181 | if (any(imag(Bf)).NumberNonZero > 0) return false;
|
---|
| 182 | return isequalwithequalnans((A as ILDenseArray<fcomplex>).C, real(Bf));
|
---|
| 183 | } return false;
|
---|
| 184 | } else if (A is ILDenseArray<complex>) {
|
---|
| 185 | if (B is ILDenseArray<complex>) {
|
---|
| 186 | return isequalwithequalnans((A as ILDenseArray<complex>).C, (B as ILDenseArray<complex>).C);
|
---|
| 187 | } else if (B is ILDenseArray<double>) {
|
---|
| 188 | ILArray<complex> Ac = (A as ILDenseArray<complex>).C;
|
---|
| 189 | if (A == null) return false;
|
---|
| 190 | if (any(imag(Ac)).NumberNonZero > 0) return false;
|
---|
| 191 | return isequalwithequalnans(real(Ac), (B as ILDenseArray<double>).C);
|
---|
| 192 | } else return false;
|
---|
| 193 | } else if (A is ILDenseArray<fcomplex>) {
|
---|
| 194 | if (B is ILDenseArray<fcomplex>) {
|
---|
| 195 | return isequalwithequalnans((A as ILDenseArray<fcomplex>).C, (B as ILDenseArray<fcomplex>).C);
|
---|
| 196 | } else if (B is ILDenseArray<float>) {
|
---|
| 197 | ILArray<fcomplex> Af = (A as ILDenseArray<fcomplex>).C;
|
---|
| 198 | if (Af == null) return false;
|
---|
| 199 | if (any(imag(Af)).NumberNonZero > 0) return false;
|
---|
| 200 | return isequalwithequalnans(real(Af), (B as ILDenseArray<float>).C);
|
---|
| 201 | } else return false;
|
---|
| 202 | } else {
|
---|
| 203 | return A.Equals(B);
|
---|
| 204 | }
|
---|
| 205 | }
|
---|
| 206 | }
|
---|
| 207 | }
|
---|
| 208 | }
|
---|