void TestComplexMemories()
        {
            var c_m1_1 = new double[] { 8.952764e-05, 4.348213e-04, -1.051215e+08, 1.458626e-09, -2.575954e+10, 2.118740e+03, -2.555026e-02, 2.192576e-18, -2.035082e+18, 2.951834e-09, -1.760731e+15, 4.620903e-11, -3.098798e+05, -8.883556e-07, 2.472289e+17, 7.059075e-12 };

            r.c_m1.Write(10, ComplexFromScalars(c_m1_1), 0, 8);

            var c_m1_3 = new CDouble[8];

            r.c_m1.Read(10, c_m1_3, 0, 8);

            ca(ComplexFromScalars(c_m1_1), c_m1_3, 8);

            var z = new ulong[] { 0, 0 };
            var c = new ulong[] { 3, 3 };

            var c_m2_1 = new uint[] { 3, 3 };
            var c_m2_2 = new double[] { -4.850043e-03, 3.545429e-07, 2.169430e+12, 1.175943e-09, 2.622300e+08, -4.439823e-11, -1.520489e+17, 8.250078e-14, 3.835439e-07, -1.424709e-02, 3.703099e+08, -1.971111e-08, -2.805354e+01, -2.093850e-17, -4.476148e+19, 9.914350e+11, 2.753067e+08, -1.745041e+14 };
            var c_m2_3 = new MultiDimArray(c_m2_1, ComplexFromScalars(c_m2_2));

            r.c_m2.Write(z, c_m2_3, z, c);

            var c_m2_4 = new MultiDimArray(c_m2_1, new CDouble[9]);

            r.c_m2.Read(z, c_m2_4, z, c);

            ca(c_m2_3.Dims, c_m2_4.Dims);
            ca((CDouble[])c_m2_3.Array_, (CDouble[])c_m2_4.Array_);
        }
        void TestBoolMemories()
        {
            var c_m5 = r.c_m5;

            bool[] v1_1 = { true, false, false, true, true, false, false, false, true, true };
            c_m5.Write(100, v1_1, 1, 8);
            var v2 = new bool[10];

            c_m5.Read(99, v2, 0, 10);
            for (int i = 1; i < 9; i++)
            {
                if (v2[i] != v1_1[i])
                {
                    throw new Exception();
                }
            }

            var c_m6 = r.c_m6;
            var v3   = new MultiDimArray(new uint[] { 2, 5 }, v1_1);

            c_m6.Write(new ulong[] { 0, 0 }, v3, new ulong[] { 0, 0 }, new ulong[] { 2, 5 });

            var v4 = new MultiDimArray(new uint[] { 2, 5 }, new bool[10]);

            c_m6.Read(new ulong[] { 0, 0 }, v4, new ulong[] { 0, 0 }, new ulong[] { 2, 5 });
            ca(v3.Dims, v4.Dims);
            ca((bool[])v3.Array_, (bool[])v4.Array_);
        }
        public static void TestByte()
        {
            MultiDimArray m1 = LoadByteArrayFromFile(Path.Combine("testdata", "testmdarray_b1.bin"));
            MultiDimArray m2 = LoadByteArrayFromFile(Path.Combine("testdata", "testmdarray_b2.bin"));
            MultiDimArray m3 = LoadByteArrayFromFile(Path.Combine("testdata", "testmdarray_b3.bin"));
            MultiDimArray m4 = LoadByteArrayFromFile(Path.Combine("testdata", "testmdarray_b4.bin"));
            MultiDimArray m5 = LoadByteArrayFromFile(Path.Combine("testdata", "testmdarray_b5.bin"));

            m1.AssignSubArray(new uint[] { 50, 100 }, m2, new uint[] { 20, 25 }, new uint[] { 200, 200 });



            ca <byte>((byte[])m1.Array_, (byte[])m3.Array_);


            MultiDimArray m6 = new MultiDimArray(new uint[] { 200, 200 }, new byte[40000]);

            m1.RetrieveSubArray(new uint[] { 65, 800 }, m6, new uint[] { 0, 0 }, new uint[] { 200, 200 });
            ca <byte>((byte[])m4.Array_, (byte[])m6.Array_);


            MultiDimArray m7 = new MultiDimArray(new uint[] { 512, 512 }, new byte[512 * 512]);

            m1.RetrieveSubArray(new uint[] { 65, 800 }, m7, new uint[] { 100, 230 }, new uint[] { 200, 200 });
            ca <byte>((byte[])m5.Array_, (byte[])m7.Array_);
        }
        public static MultiDimArray LoadDoubleArrayFromFile(string fname)
        {
            FileStream    f = new FileStream(fname, FileMode.Open, FileAccess.Read);
            MultiDimArray a = LoadDoubleArray(f);

            f.Close();
            return(a);
        }
Exemplo n.º 5
0
        public TArray ReadValue(IValueReader valueReader)
        {
            if (valueReader is IValueReader <TArray> reader)
            {
                return(reader.ReadValue());
            }

            var rw = new MultiDimArray <TArray, TElement> .FirstRW();

            valueReader.ReadArray(rw);

            return(rw.GetContent());
        }
Exemplo n.º 6
0
        public void VerifyIssue54_WriteTomlWithMultiArrays_ProducesCorrectTomlOutput()
        {
            // Arrange
            var obj = new MultiDimArray();

            // Act
            string output = Toml.WriteString(obj);
            var    x      = new int[, ] {
                { 1 }, { 2 }
            };

            // Assert
            output.Trim().ShouldBeSemanticallyEquivalentTo(MultiDimArray.TomlRep);
        }
Exemplo n.º 7
0
        public void WriteValue(IValueWriter valueWriter, TArray value)
        {
            if (value is null)
            {
                valueWriter.DirectWrite(null);
            }
            else if (valueWriter is IValueWriter <TArray> writer)
            {
                writer.WriteValue(value);
            }
            else
            {
                var rw = new MultiDimArray <TArray, TElement> .FirstRW();

                rw.Initialize(value);

                valueWriter.WriteArray(rw);
            }
        }
Exemplo n.º 8
0
            internal static void TestCorrectness()
            {
                MultiDimArray <int> a = new MultiDimArray <int>(2, 3, 4, 3, 2);

                for (int i = 0; i < a.Length; i++)
                {
                    a[i] = i;
                    Console.Write(a[i] + " ");
                }
                Console.WriteLine();
                Console.WriteLine();
                for (int i = 0; i < a.Lengths[0] * a.Lengths[1]; i++)
                {
                    for (int j = 0; j < a.Lengths[2]; j++)
                    {
                        for (int k = 0; k < a.Lengths[3] * a.Lengths[4]; k++)
                        {
                            a[i, j, k] = k;
                            Console.Write(a[i, j, k] + " ");
                        }
                    }
                }
                Console.WriteLine();
                Console.WriteLine();
                for (int i = 0; i < a.Lengths[0]; i++)
                {
                    for (int j = 0; j < a.Lengths[1]; j++)
                    {
                        for (int k = 0; k < a.Lengths[2]; k++)
                        {
                            for (int l = 0; l < a.Lengths[3]; l++)
                            {
                                for (int m = 0; m < a.Lengths[4]; m++)
                                {
                                    a[i, j, k, l, m] = m + l;
                                    Console.Write(a[i, j, k, l, m] + " ");
                                }
                            }
                        }
                    }
                }
            }
        public static void TestDouble()
        {
            MultiDimArray m1 = LoadDoubleArrayFromFile(Path.Combine("testdata", "testmdarray1.bin"));
            MultiDimArray m2 = LoadDoubleArrayFromFile(Path.Combine("testdata", "testmdarray2.bin"));
            MultiDimArray m3 = LoadDoubleArrayFromFile(Path.Combine("testdata", "testmdarray3.bin"));
            MultiDimArray m4 = LoadDoubleArrayFromFile(Path.Combine("testdata", "testmdarray4.bin"));
            MultiDimArray m5 = LoadDoubleArrayFromFile(Path.Combine("testdata", "testmdarray5.bin"));

            m1.AssignSubArray(new uint[] { 2, 2, 3, 3, 4 }, m2, new uint[] { 0, 2, 0, 0, 0 }, new uint[] { 1, 5, 5, 2, 1 });



            ca <double>((double[])m1.Array_, (double[])m3.Array_);

            MultiDimArray m6 = new MultiDimArray(new uint[] { 2, 2, 1, 1, 10 }, new double[40]);

            m1.RetrieveSubArray(new uint[] { 4, 2, 2, 8, 0 }, m6, new uint[] { 0, 0, 0, 0, 0 }, new uint[] { 2, 2, 1, 1, 10 });
            ca <double>((double[])m4.Array_, (double[])m6.Array_);

            MultiDimArray m7 = new MultiDimArray(new uint[] { 4, 4, 4, 4, 10 }, new double[2560]);

            m1.RetrieveSubArray(new uint[] { 4, 2, 2, 8, 0 }, m7, new uint[] { 2, 1, 2, 1, 0 }, new uint[] { 2, 2, 1, 1, 10 });
            ca <double>((double[])m5.Array_, (double[])m7.Array_);
        }
Exemplo n.º 10
0
        void TestComplex()
        {
            var c1_1 = new CDouble(5.708705e+01, -2.328294e-03);

            if (r.c1 != c1_1)
            {
                throw new Exception();
            }

            var c1_2 = new CDouble(5.708705e+01, -2.328294e-03);

            r.c1 = c1_2;

            CDouble[] c2_1   = r.c2;
            double[]  c2_1_1 = new double[] { 1.968551e+07, 2.380643e+18, 3.107374e-16, 7.249542e-16, -4.701135e-19, -6.092764e-17, 2.285854e+14, 2.776180e+05, -1.436152e-12, 3.626609e+11, 3.600952e-02, -3.118123e-16, -1.312210e-10, -1.738940e-07, -1.476586e-12, -2.899781e-20, 4.806642e+03, 4.476869e-05, -2.935084e-16, 3.114019e-20, -3.675955e+01, 3.779796e-21, 2.190594e-11, 4.251420e-06, -9.715221e+11, -3.483924e-01, 7.606428e+05, 5.418088e+15, 4.786378e+16, -1.202581e+08, -1.662061e+02, -2.392954e+03 };
            ca(c2_1, ComplexFromScalars(c2_1_1));

            double[] c2_2_1 = new double[] { 4.925965e-03, 5.695254e+13, -4.576890e-14, -6.056342e-07, -4.918571e-08, -1.940684e-10, 1.549104e-02, -1.954145e+04, -2.499019e-16, 4.010614e+09, -1.906811e-08, 3.297924e-10, 2.742399e-02, -4.372839e-01, -3.093171e-10, 4.311755e-01, -2.218220e-14, 5.399758e+10, 3.360304e+17, 1.340681e-18, -4.441140e+11, -1.845055e-09, -3.074586e-10, -1.754926e+01, -2.766799e+04, -2.307577e+10, 2.754875e+14, 1.179639e+15, 6.976204e-10, 1.901856e+08, -3.824351e-02, -1.414167e+08 };

            r.c2 = ComplexFromScalars(c2_2_1);

            MultiDimArray c3_1 = r.c3;

            uint[]   c3_1_1 = new uint[] { 2, 5 };
            double[] c3_1_2 = new double[] { 5.524802e+18, -2.443857e-05, 3.737932e-02, -4.883553e-03, -1.184347e+12, 4.537366e-08, -4.567913e-01, -1.683542e+15, -1.676517e+00, -8.911085e+12, -2.537376e-17, 1.835687e-10, -9.366069e-22, -5.426323e-12, -7.820969e-10, -1.061541e+12, -3.660854e-12, -4.969930e-03, 1.988428e+07, 1.860782e-16 };
            ca(c3_1.Dims, c3_1_1);
            ca((CDouble[])c3_1.Array_, ComplexFromScalars(c3_1_2));

            uint[]   c3_2_1 = new uint[] { 3, 4 };
            double[] c3_2_2 = new double[] { 4.435180e+04, 5.198060e-18, -1.316737e-13, -4.821771e-03, -4.077550e-19, -1.659105e-09, -6.332363e-11, -1.128999e+16, 4.869912e+16, 2.680490e-04, -8.880119e-04, 3.960452e+11, 4.427784e-09, -2.813742e-18, 7.397516e+18, 1.196394e+13, 3.236906e-14, -4.219297e-17, 1.316282e-06, -2.771084e-18, -1.239118e-09, 2.887453e-08, -1.746515e+08, -2.312264e-11 };
            r.c3 = new MultiDimArray(c3_2_1, ComplexFromScalars(c3_2_2));

            List <CDouble[]> c5_1 = r.c5;

            double[] c5_1_1 = new double[] { 1.104801e+00, 4.871266e-10, -2.392938e-03, 4.210339e-07, 1.474114e-19, -1.147137e-01, -2.026434e+06, 4.450447e-19, 3.702953e-21, 9.722025e+12, 3.464073e-14, 4.628110e+15, 2.345453e-19, 3.730012e-04, 4.116650e+16, 4.380220e+08 };
            ca(c5_1[0], ComplexFromScalars(c5_1_1));

            var c5_2 = new List <CDouble[]>();

            double[] c5_2_1 = { 2.720831e-20, 2.853037e-16, -7.982497e+16, -2.684318e-09, -2.505796e+17, -4.743970e-12, -3.657056e+11, 2.718388e+15, 1.597672e+03, 2.611859e+14, 2.224926e+06, -1.431096e-09, 3.699894e+19, -5.936706e-01, -1.385395e-09, -4.248415e-13 };
            c5_2.Add(ComplexFromScalars(c5_2_1));
            r.c5 = (c5_2);

            var c7_1 = new CSingle(-5.527021e-18f, -9.848457e+03f);

            if (r.c7 != c7_1)
            {
                throw new Exception();
            }

            var c7_2 = new CSingle(9.303345e-12f, -3.865684e-05f);

            r.c7 = (c7_2);

            var c8_1 = r.c8;

            float[] c8_1_1 = new float[] { -3.153395e-09f, 3.829492e-02f, -2.665239e+12f, 1.592927e-03f, 3.188444e+06f, -3.595015e-11f, 2.973887e-18f, -2.189921e+17f, 1.651567e+10f, 1.095838e+05f, 3.865249e-02f, 4.725510e+10f, -2.334376e+03f, 3.744977e-05f, -1.050821e+02f, 1.122660e-22f, 3.501520e-18f, -2.991601e-17f, 6.039622e-17f, 4.778095e-07f, -4.793136e-05f, 3.096513e+19f, 2.476004e+18f, 1.296297e-03f, 2.165336e-13f, 4.834427e+06f, 4.675370e-01f, -2.942290e-12f, -2.090883e-19f, 6.674942e+07f, -4.809047e-10f, -4.911772e-13f };
            ca(c8_1, ComplexFromScalars(c8_1_1));

            float[] c8_2_1 = new float[] { 1.324498e+06f, 1.341746e-04f, 4.292993e-04f, -3.844509e+15f, -3.804802e+10f, 3.785305e-12f, 2.628285e-19f, -1.664089e+15f, -4.246472e-10f, -3.334943e+03f, -3.305796e-01f, 1.878648e-03f, 1.420880e-05f, -3.024657e+14f, 2.227031e-21f, 2.044653e+17f, 9.753609e-20f, -6.581817e-03f, 3.271063e-03f, -1.726081e+06f, -1.614502e-06f, -2.641638e-19f, -2.977317e+07f, -1.278224e+03f, -1.760207e-05f, -4.877944e-07f, -2.171524e+02f, 1.620645e+01f, -4.334168e-02f, 1.871011e-09f, -3.066163e+06f, -3.533662e+07f };
            r.c8 = ComplexFromScalars(c8_2_1);

            var c9_1 = r.c9;

            uint[]  c9_1_1 = new uint[] { 2, 4 };
            float[] c9_1_2 = new float[] { 1.397743e+15f, 3.933042e+10f, -3.812329e+07f, 1.508109e+16f, -2.091397e-20f, 3.207851e+12f, -3.640702e+02f, 3.903769e+02f, -2.879727e+17f, -4.589604e-06f, 2.202769e-06f, 2.892523e+04f, -3.306489e-14f, 4.522308e-06f, 1.665807e+15f, 2.340476e+10f };
            ca(c9_1.Dims, c9_1_1);
            ca((CSingle[])c9_1.Array_, ComplexFromScalars(c9_1_2));

            uint[]  c9_2_1 = new uint[] { 2, 2, 2 };
            float[] c9_2_2 = new float[] { 2.138322e-03f, 4.036979e-21f, 1.345236e+10f, -1.348460e-12f, -3.615340e+12f, -2.911340e-21f, 3.220362e+09f, 3.459909e-04f, 4.276259e-08f, -3.199451e+18f, 3.468308e+07f, -2.928506e-09f, -3.154288e+17f, -2.352920e-02f, 6.976385e-21f, 2.435472e+12f };
            r.c9 = new MultiDimArray(c9_2_1, ComplexFromScalars(c9_2_2));
        }
Exemplo n.º 11
0
 internal static void TestCorrectness() {
     MultiDimArray<int> a = new MultiDimArray<int>(2, 3, 4, 3, 2);
     for (int i = 0; i < a.Length; i++) {
         a[i] = i;
         Console.Write(a[i] + " ");
     }
     Console.WriteLine();
     Console.WriteLine();
     for (int i = 0; i < a.Lengths[0] * a.Lengths[1]; i++) {
         for (int j = 0; j < a.Lengths[2]; j++) {
             for (int k = 0; k < a.Lengths[3] * a.Lengths[4]; k++) {
                 a[i, j, k] = k;
                 Console.Write(a[i, j, k] + " ");
             }
         }
     }
     Console.WriteLine();
     Console.WriteLine();
     for (int i = 0; i < a.Lengths[0]; i++) {
         for (int j = 0; j < a.Lengths[1]; j++) {
             for (int k = 0; k < a.Lengths[2]; k++) {
                 for (int l = 0; l < a.Lengths[3]; l++) {
                     for (int m = 0; m < a.Lengths[4]; m++) {
                         a[i, j, k, l, m] = m + l;
                         Console.Write(a[i, j, k, l, m] + " ");
                     }
                 }
             }
         }
     }
 }