public static void forwBackwCheck1DAlongD(ILArray <float> A, ILArray <fcomplex> Result, int p) { try { ILArray <fcomplex> B = fft(A, p); //double errMult = 1/(A.Dimensions.NumberOfElements * Math.Pow(10,A.Dimensions.NumberOfDimensions)); float errMult = (float)Math.Pow(0.1f, A.Dimensions.NumberOfDimensions) / A.Dimensions.NumberOfElements; if (!A.IsScalar) { errMult /= (float)A.Dimensions[A.Dimensions.FirstNonSingleton()]; } if (sumall(abs(subtract(Result, B))) * errMult > (double)MachineParameterFloat.eps) { throw new Exception("invalid value"); } ILArray <float> ResultR = ifftsym(B, p); if (ILMath.sumall(ILMath.abs(ResultR - A)) * errMult > (double)ILMath.MachineParameterFloat.eps) { throw new Exception("invalid value"); } B = ifft(B, p); if (ILMath.sumall(ILMath.abs(ILMath.tofcomplex(A) - B)) * errMult > (double)ILMath.MachineParameterFloat.eps) { throw new Exception("invalid value"); } } catch (ILNumerics.Exceptions.ILArgumentException) { throw new Exception("unexpected exception was thrown -> error!"); } }
public override ILCell GenerateTestArrays() { ILCell ret = new ILTestProviderComplex().GenerateTestArrays(); for (int i = 0; i < ret.Dimensions[0]; i++) { ret[i] = ILMath.tofcomplex(ret[i]); } return(ret); }
private void Test_conj() { // test for common matrix 4x3 ILArray <complex> A = new complex[, ] { { new complex(1, 2), new complex(3, 4), new complex(5, 6) }, { new complex(7, 8), new complex(9, 10), new complex(11, 12) }, { new complex(13, 14), new complex(15, 16), new complex(17, 18) }, { new complex(19, 20), new complex(21, 22), new complex(23, 24) } }; ILArray <fcomplex> Af = ILMath.tofcomplex(A); Test_isConj(A, ILMath.conj(A)); Test_isfConj(Af, ILMath.conj(Af)); // test on reference matrix Test_isConj(A, ILMath.conj(A.R)); Test_isfConj(Af, ILMath.conj(Af.R)); // test on 2x2x3 matrix (reference) A = A.Reshape(new ILDimension(2, 2, 3)).R; if (!A.IsReference) { throw new Exception("Unable to test conj() for reference 2x2x3!"); } Af = Af.Reshape(new ILDimension(2, 2, 3)).R; if (!Af.IsReference) { throw new Exception("Unable to test conj() for reference 2x2x3!"); } Test_isConj(A, ILMath.conj(A)); Test_isfConj(Af, ILMath.conj(Af)); // test those on dense array Test_isConj(A, ILMath.conj(A.C)); Test_isfConj(Af, ILMath.conj(Af.C)); // test for empty A = ILArray <complex> .empty(); Af = ILArray <fcomplex> .empty(); Test_isConj(A, ILMath.conj(A)); Test_isfConj(Af, ILMath.conj(Af)); // test on vector A = new complex[] { new complex(1, 2), new complex(3, 4), new complex(5, 6) }; Af = ILMath.tofcomplex(A); Test_isConj(A, ILMath.conj(A)); Test_isfConj(Af, ILMath.conj(Af)); // transpose Test_isConj(A.T, ILMath.conj(A.T)); Test_isfConj(Af.T, ILMath.conj(Af.T)); // test on scalar A = A[2]; Af = Af[2]; Test_isConj(A, ILMath.conj(A)); Test_isfConj(Af, ILMath.conj(Af)); }
public ILArray <fcomplex> FFTForward1D(ILArray <float> A, int dim) { if (A == null || dim < 0) { throw new ILArgumentException("invalid parameter!"); } if (A.IsEmpty) { return(ILArray <fcomplex> .empty(A.Dimensions)); } if (A.IsScalar || A.Dimensions[dim] == 1) { return(ILMath.tofcomplex(A)); } // prepare output array ILArray <fcomplex> ret = ILMath.tofcomplex(A); fft1dInplace(dim, ret, ACMLValues.Forward); return(ret); }
public ILArray <fcomplex> FFTForward(ILArray <float> A, int nDims) { if (A == null || nDims <= 0) { throw new ILArgumentException("invalid parameter!"); } if (A.IsEmpty) { return(ILArray <fcomplex> .empty(A.Dimensions)); } if (A.IsScalar || (A.Dimensions[0] == 1 && nDims == 1)) { return(ILMath.tofcomplex(A)); } if (nDims > A.Dimensions.NumberOfDimensions) { return(FFTForward(A, A.Dimensions.NumberOfDimensions)); } // prepare output array + transform each dimension inplace ILArray <fcomplex> ret = ILMath.tofcomplex(A); switch (nDims) { case 2: fft2dInplace(ret, ACMLValues.Forward); break; default: for (int i = 0; i < nDims; i++) { fft1dInplace(i, ret, ACMLValues.Forward); } break; } return(ret); }
/// <summary> /// run all tests for ILMatFile /// </summary> public override void Run() { // tests: creation // ================= Header(); Test_TestMatlab(); Test_StreamMatlab("testarray1.mat", ILMath.empty()); Test_StreamMatlab("testarray1.mat", ILMath.ones(1, 1)); Test_StreamMatlab("testarray1.mat", ILMath.rand(10, 1)); Test_StreamMatlab("testarray1.mat", ILMath.rand(1, 10)); Test_StreamMatlab("testarray1.mat", ILMath.rand(0, 1)); Test_StreamMatlab("testarray1.mat", ILMath.rand(10, 100, 4)); Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.ones(1, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.empty())); Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(10, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(1, 10))); Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(0, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tosingle(ILMath.rand(10, 100, 4))); Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.ones(1, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.empty())); Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(10, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(1, 10))); Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(0, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tological(ILMath.rand(10, 100, 4))); Test_StreamMatlab("testarray1.mat", new ILArray <complex>(new complex[] { new complex(1.0, 2.0) })); Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.empty())); Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(10, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(1, 10))); Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(0, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tocomplex(ILMath.rand(10, 100, 4))); Test_StreamMatlab("testarray1.mat", new ILArray <fcomplex>(new fcomplex[] { new fcomplex(1.0f, 2.0f) })); Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.empty())); Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(10, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(1, 10))); Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(0, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tofcomplex(ILMath.rand(10, 100, 4))); Test_StreamMatlab("testarray1.mat", new ILArray <char>(new char[] { 'A', 'B', 'F' })); Test_StreamMatlab("testarray1.mat", new ILArray <char>(new char[] { 'A', 'B', 'F' }).T); Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.empty())); Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(10, 1) * 250)); Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(1, 10) * 250)); Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(0, 1) * 250)); Test_StreamMatlab("testarray1.mat", ILMath.tochar(ILMath.rand(10, 100, 4) * 250)); Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.ones(1, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.empty())); Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(10, 1))); Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(1, 10) * 255)); Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(0, 1) * 255)); Test_StreamMatlab("testarray1.mat", ILMath.tobyte(ILMath.rand(10, 100, 4) * 255)); Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.ones(1, 1) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.empty()) * 16000); Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(10, 1) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(1, 10) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(0, 1) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint16(ILMath.rand(10, 100, 4) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.ones(1, 1) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.empty() * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(10, 1) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(1, 10) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(0, 1) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.toint32(ILMath.rand(10, 100, 4) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.ones(1, 1) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.empty() * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(10, 1) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(1, 10) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(0, 1) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.touint16(ILMath.rand(10, 100, 4) * 16000)); Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.ones(1, 1))); Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.empty())); Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(10, 1))); Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(1, 10))); Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(0, 1))); Test_StreamMatlab("testarray1.mat", ILMath.touint32(ILMath.rand(10, 100, 4))); Test_ImportMatlab2(); Test_ImportMatlab(); Test_NameRestrictions(); // summary Footer(); }