Beispiel #1
0
 /// <summary>
 /// size of array A 
 /// </summary>
 /// <param name="A">input array</param>
 /// <returns>double ILArray with the length of each dimension of A.</returns>
 /// <remarks>If A is null, an empty array will be returned. Otherwise the array returned will always be a row vector of length s. s &gt;= 2</remarks>
 public static ILArray<double> size(ILBaseArray A) {
     if (object.Equals (A,null))
         return ILArray<double>.empty(0,0); 
     int numDim = A.Dimensions.NumberOfDimensions;
     double [] retArr = new double[numDim]; 
     for (int i = 0; i < numDim; i++) {
         retArr[i] = A.Dimensions[i];     
     }
     return new ILArray<double>(retArr,1,numDim); 
 }
Beispiel #2
0
 public static bool TestEqualSloppy (ILBaseArray A, ILBaseArray B) {
     if (A is ILArray<double>) {
         if (B is ILArray<double>) {
             return isequalwithequalnans(A as ILArray<double>,B as ILArray<double>); 
         } else if (B is ILArray<complex>) {
             ILArray<complex> Bc = B as ILArray<complex>; 
             if (Bc == null) return false;
             if (any(imag(Bc)).NumberTrues > 0) {
                 //if (any(isinf(imag(Bc)) != isinf(real(Bc))).NumberTrues > 0) return false;  
                 if (any(imag(Bc)[find(!isinf(Bc))]).NumberTrues > 0) return false; 
             }
             return isequalwithequalnans(A as ILArray<double>, real(Bc)); 
         } return false; 
     } else if (A is ILArray<float>) {
         if (B is ILArray<float>) {
             return isequalwithequalnans(A as ILArray<float>,B as ILArray<float>); 
         } else if (B is ILArray<fcomplex>) {
             ILArray<fcomplex> Bf = B as ILArray<fcomplex>; 
             if (Bf == null) return false; 
             if (any(imag(Bf)).NumberTrues > 0) {
                 //if (any(isinf(imag(Bf)) != isinf(real(Bf))).NumberTrues > 0) return false;  
                 if (any(imag(Bf)[find(!isinf(Bf))]).NumberTrues > 0) return false; 
             }
             return isequalwithequalnans(A as ILArray<fcomplex>, real(Bf)); 
         } return false; 
     } else if (A is ILArray<complex>) {
         if (B is ILArray<complex>) {
             return isequalwithequalnans(A as ILArray<complex>, B as ILArray<complex>); 
         } else if (B is ILArray<double>) {
             ILArray<complex> Ac = A as ILArray<complex>; 
             if (A == null) return false; 
             if (any(imag(Ac)).NumberTrues > 0) {
                 //if (any(isinf(imag(Ac)) != isinf(real(Ac))).NumberTrues > 0) return false;  
                 if (any(imag(Ac)[find(!isinf(Ac))]).NumberTrues > 0) return false; 
             }
             return isequalwithequalnans(real(Ac),B as ILArray<double>); 
         } else return false; 
     } else if (A is ILArray<fcomplex>) {
         if (B is ILArray<fcomplex>) {
             return isequalwithequalnans(A as ILArray<fcomplex>, B as ILArray<fcomplex>); 
         } else if (B is ILArray<float>) {
             ILArray<fcomplex> Af = A as ILArray<fcomplex>; 
             if (Af == null) return false; 
             if (any(imag(Af)).NumberTrues > 0) {
                 //if (any(isinf(imag(Af)) != isinf(real(Af))).NumberTrues > 0) return false;  
                 if (any(imag(Af)[find(!isinf(Af))]).NumberTrues > 0) return false; 
             }
             return isequalwithequalnans(real(Af),B as ILArray<float>); 
         } else return false; 
     } else {
         return A.Equals(B); 
     }
 }
Beispiel #3
0
 /// <summary>
 /// get storage length of inner array elements 
 /// </summary>
 /// <param name="arr">base array in question</param>
 /// <returns>storage length in bytes</returns>
 private static int getElementLength(ILBaseArray arr) {
     Type arrType = arr.GetType();
     string innerType; 
     if (arr is ILLogicalArray) 
         return 1;
     if (!arrType.IsGenericType)
         throw new ILInvalidOperationException("The array type to be saved is not applicable!");
     innerType = arrType.GetGenericArguments()[0].Name;
     switch (innerType) {
         case "Double":
             return miSIZE_DOUBLE;  
         case "Single":
             return miSIZE_SINGLE;
         case "Int16":
             return miSIZE_INT16;
         case "Int32":
             return miSIZE_INT32;
         case "Int64":
             return 16;
         case "UInt16":
             return miSIZE_UINT16;
         case "UInt32":
             return miSIZE_UINT32;
         case "UInt64":
             return 16;
         case "complex":
             return miSIZE_DOUBLE;
         case "fcomplex":
             return miSIZE_SINGLE;
         case "Byte":
             return miSIZE_INT8;
         case "Char":
             return miSIZE_UINT16;
         default:
             throw new ILInvalidOperationException("Arrays of inner element type: '" + innerType + "' can not be written as Matfile!");
     }
 }
Beispiel #4
0
 /// <summary>
 /// get mat file array class type corresponding to this arra element type
 /// </summary>
 /// <param name="arr">arra with generic system type or complex/fcomplex</param>
 /// <returns>mat file array class type code (int value)</returns>
 private static int getElementClass(ILBaseArray arr) {
     Type arrType = arr.GetType();
     if (arr is ILLogicalArray) 
         return (int)MatFileArrayClass.mxINT8_CLASS; 
     if (!arrType.IsGenericType)
         throw new ILInvalidOperationException("The array type to be saved is not applicable!");
     string innerType = arrType.GetGenericArguments()[0].Name;
     switch (innerType) {
         case "Double":
             return (int)MatFileArrayClass.mxDOUBLE_CLASS;
         case "Single":
             return (int)MatFileArrayClass.mxSINGLE_CLASS;
         case "Int16":
             return (int)MatFileArrayClass.mxINT16_CLASS;
         case "Int32":
             return (int)MatFileArrayClass.mxINT32_CLASS;
         case "Int64":
             throw new ILInvalidOperationException("Int64 array class can not be written as Matfile!"); 
         case "UInt16":
             return (int)MatFileArrayClass.mxUINT16_CLASS;
         case "UInt32":
             return (int)MatFileArrayClass.mxUINT32_CLASS;
         case "UInt64":
             throw new ILInvalidOperationException("UInt64 array class can not be written as Matfile!"); 
         case "complex":
             return (int)MatFileArrayClass.mxDOUBLE_CLASS; 
         case "fcomplex":
             return (int)MatFileArrayClass.mxSINGLE_CLASS; 
         case "Byte":
             return (int)MatFileArrayClass.mxINT8_CLASS;
         case "Char":
             return (int)MatFileArrayClass.mxCHAR_CLASS;
         default:
             throw new ILInvalidOperationException("Arrays of inner element type: '" + innerType + "' can not be written as Matfile!");
     }
 }      
Beispiel #5
0
        private int[] createDimensionSubelement (ILBaseArray arr) {
            int[] ret; 
            int LengthInt; 
            // determine length of dimensions array byte (padding to full 8 byte border)
            if (arr.Dimensions.NumberOfDimensions % 2 == 0) {
                LengthInt = (arr.Dimensions.NumberOfDimensions + 2); 
             } else {
                // must pad to 8 byte border
                LengthInt = (arr.Dimensions.NumberOfDimensions + 3); 
            }
            ret = new int[LengthInt]; 
            ret[0] = (int)MatFileType.miINT32; 
            ret[1] = arr.Dimensions.NumberOfDimensions * 4; 
            for (int i = 0; i < arr.Dimensions.NumberOfDimensions; i++)
	        {
                ret[i+2] = arr.Dimensions[i]; 
	        }
            return ret; 
        }
Beispiel #6
0
 protected ErrorHandlerProcessMethod ProcessParameterErrorInfo(int id, ILBaseArray parameter0, 
                         int nrInputParams, int nrOutputParams, int failedResultNo, 
                         ILMatFile inputMatfile, ILMatFile outputMatfile, 
                         string functionDefinition) {
     // determine how to proceed with the error
     if (m_ignoreAllErrors || m_manualIgnoreIds.Contains(id)) {
         if (!m_manualIgnoreIds.Contains(id))
             m_manualIgnoreIds.Add(id); 
         return ErrorHandlerProcessMethod.IgnoreAll; 
     }
     Console.ResetColor();
     Console.WriteLine("Press 'i' for extended error information! (will continue in " + m_errorWaitForUserInputSec.ToString() + " sec otherwise)");
     DateTime end = DateTime.Now + TimeSpan.FromSeconds(m_errorWaitForUserInputSec);
     while (!Console.KeyAvailable && DateTime.Now < end) {
         System.Threading.Thread.Sleep(100);
     }
     if (Console.KeyAvailable && Console.ReadKey().Key == ConsoleKey.I) {
         // function definition
         Console.WriteLine("Function: {0}",functionDefinition); 
         // write error infos: input parameters
         for (int i = 0; i < nrInputParams; i++) {
             Console.WriteLine("Input parameter #{0}:\r\n#############################\r\n{1}", i, inputMatfile["input_" + id.ToString() + "_" + i.ToString()].ToString());
         }
         // write error infos: output parameters
         for (int i = 0; i < nrOutputParams; i++) {
             Console.WriteLine("Expected output parameter #{0}:\r\n#############################\r\n{1}", i, outputMatfile["output_" + id.ToString() + "_" + i.ToString()].ToString());
         }
         Console.WriteLine("Result #{0} returned unexpected value: \r\n ############################\r\n{1}", failedResultNo, parameter0.ToString());
         // ask how to proceed
         ConsoleKey pressedKey = ConsoleKey.NoName;
         while (pressedKey != ConsoleKey.A && 
                 pressedKey != ConsoleKey.I && 
                 pressedKey != ConsoleKey.P && 
                 pressedKey != ConsoleKey.L) {
             Console.WriteLine("_A_bort / _I_gnore/ _P_ermanently ignore / Ignore al_L_ ");
             while (!Console.KeyAvailable) {
                 System.Threading.Thread.Sleep(100);
             }
             pressedKey = Console.ReadKey(false).Key; 
         }
         if (pressedKey == ConsoleKey.A) {
             Console.WriteLine("Aborting...");
             return ErrorHandlerProcessMethod.Abort; 
         } else if (pressedKey == ConsoleKey.L) {
             Console.WriteLine("All errors will be ignored in future runs of this test ...");
             m_manualIgnoreIds.Add(id); 
             m_ignoreAllErrors = true; 
             return ErrorHandlerProcessMethod.IgnoreAll; 
         } else if (pressedKey == ConsoleKey.I) {
             Console.WriteLine("The error will be ignored in this test ...");
             return ErrorHandlerProcessMethod.IgnoreAll; 
         } else if (pressedKey == ConsoleKey.P) {
             Console.WriteLine("The error will be permanently ignored in this test ...");
             m_manualIgnoreIds.Add(id); 
             return ErrorHandlerProcessMethod.IgnoreAll; 
         } 
     }
     return ErrorHandlerProcessMethod.Ignore; 
 }
Beispiel #7
0
 protected void CheckManualOverwrite(int waitAutoContinueMs, 
                                     ILMatFile inputs, ILMatFile outputsExt, 
                                     int id, int nrInputParams, int nrOutputParams,
                                     int idFailedOutput, ILBaseArray failedOutputILN) {
     // give extensive error info
     Console.Out.WriteLine("Failure! ####################################"); 
     Console.Out.WriteLine("Should extensive error information be displayed? (y/n)"); 
     if (Console.In.Read() == 1) return; 
     // waits for n msec for user input
     // skip
     // overwrite 
     
 
 }
Beispiel #8
0
 /// <summary>
 /// length of one specific dimension of A
 /// </summary>
 /// <param name="A">input array</param>
 /// <param name="dim">number of dimension to query the length for</param>
 /// <returns>length of dimension 'dim'</returns>
 public static int size(ILBaseArray A, int dim) {
     if (object.Equals(A,null) || dim < 0)
         throw new ILArgumentException("size: A must not be null");
     return A.Dimensions[dim];
 }
 /// <summary>
 /// Deserialize an ILLogicalArray from stream
 /// </summary>
 /// <param name="inStream">strem to read from</param>
 /// <returns>ILLogicalArray deserialized from stream</returns>
 public new static ILLogicalArray Deserialize(System.IO.Stream inStream)
 {
     return((ILLogicalArray)ILBaseArray <Byte> .Deserialize(inStream));
 }
Beispiel #10
0
 /// <summary>
 /// create new lit surface, provide heights (Z values)
 /// </summary>
 /// <param name="panel">the panel hosting the scene</param>
 /// <param name="Z">data matrix, at least 2 rows, 2 columns</param>
 public ILLitSurface(ILPanel panel, ILBaseArray Z)
     : this(panel, Z, new ILColormap(Colormaps.ILNumerics)) { }
Beispiel #11
0
        /// <summary>
        /// create new lit surface, provide data for X,Y and Z coordinates
        /// </summary>
        /// <param name="panel">the panel hosting the scene</param>
        /// <param name="X">X coordinates matrix, same size as Z or null</param>
        /// <param name="Y">Y coordinates matrix, same size as Z or null</param>
        /// <param name="Z">Z data matrix, at least 2 rows, 2 columns</param>
        /// <param name="colormap">colormap used for auto coloring the surface</param>
        public ILLitSurface(ILPanel panel, ILBaseArray X, ILBaseArray Y, ILBaseArray Z, ILColormap colormap)
            : base(panel) {
            if (Z == null || Z.Dimensions[0] < 2 || Z.Dimensions[1] < 2)
                throw new ArgumentException("invalid parameter size: Z");
            if (X == null || !X.Dimensions.IsSameSize(Z.Dimensions))
                throw new ArgumentException("invalid parameter size: X");
            if (Y == null || !Y.Dimensions.IsSameSize(Z.Dimensions))
                throw new ArgumentException("invalid parameter size: Y");
            m_quads = new ILLitQuads(panel, Z.Dimensions.NumberOfElements);
            m_quads.Label.Text = ""; 
            m_quads.Shading = ShadingStyles.Interpolate;
            Add(m_quads);
            m_colorMap = colormap;
            ZValues = Z; 
            XValues = X;
            YValues = Y;

            Invalidate();
        }
Beispiel #12
0
        /// <summary>
        /// helper function to prepare parameters for partial removal
        /// </summary>
        /// <param name="range">object with index specification.May be of
        /// type ILBaseArray[] with numeric arrays or a string array according
        /// to the format of <see cref="ILNumerics.Storage.ILRange"/>.
        /// </param>
        /// <param name="dimensionIdx">out parameter: number of dimension the indices to be removed lay in</param>
        /// <param name="indices">indices to be removed</param>
        /// <param name="dimensions">dimension structure, may be used if the array must be
        /// reshaped <b>before</b> the removal.</param>
        /// <remarks>if range consists out of a range specification wich is smaller than
        /// the actual dimension length of this array, the array must also be reshaped in order to remove
        /// the data accordingly. This reshape proccess will <b>not</b> be done inside of this function! However
        /// ther <c>dimension</c> value returned reflect the size of the array before removing and therefore
        /// may comfortable be used for reshaping the array.</remarks>
        /// <exception cref="ILNumerics.Exceptions.ILArgumentException">if <list type="bullet">
        /// <item>the length of range exceeds the dimensions of this array</item>
        /// <item>more or less than exactly one dimension of <c>range</c> was not null</item>
        /// <item>the type of range was invalid, or</item>
        /// <item>range is of type array of <see cref="ILNumerics.ILBaseArray"/>, but the elements are non numeric ILArray's</item>
        /// </list></exception>
        private void ExtractRemovalParameter(object[] range, out int dimensionIdx, out int[] indices, out ILDimension dimensions)
        {
            dimensionIdx = 0;
            indices      = null;
            dimensions   = null;
            int inDimCount = 0;

            //
            if (range.Length > m_dimensions.NumberOfDimensions)
            {
                throw new ILArgumentException("Error removing: dimension specification exceeds matrix dimensions.");
            }
            int specCount = 0;
            int tmp       = 0;

            inDimCount = range.Length;
            //
            for (int i = 0; i < range.Length; i++)
            {
                if (range[i] is ILBaseArray)
                {
                    #region ILBaseArray input
                    ILBaseArray rng = (ILBaseArray)range[i];
                    if (rng != null && !rng.IsEmpty)
                    {
                        dimensionIdx = i;
                        if (specCount++ > 0)
                        {
                            throw new ILArgumentException("Error removing: only one dimension must be non-empty!");
                        }
                        if (false)
                        {
                        }
                        else if (rng is ILLogicalArray)
                        {
                            ILArray <double> ind = ILNumerics.BuiltInFunctions.ILMath.find((ILLogicalArray)rng);
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }
                            #region HYCALPER LOOPSTART

                            /* !HC:TYPELIST:
                             * <hycalper>
                             * <type>
                             * <source locate="after">
                             * inCls1
                             * </source>
                             * <destination><![CDATA[ILArray<float>]]></destination>
                             * <destination><![CDATA[ILArray<Int16>]]></destination>
                             * <destination><![CDATA[ILArray<Int32>]]></destination>
                             * <destination><![CDATA[ILArray<Int64>]]></destination>
                             * <destination><![CDATA[ILArray<UInt16>]]></destination>
                             * <destination><![CDATA[ILArray<UInt32>]]></destination>
                             * <destination><![CDATA[ILArray<UInt64>]]></destination>
                             * <destination><![CDATA[ILArray<char>]]></destination>
                             * <destination><![CDATA[ILArray<byte>]]></destination>
                             * <destination><![CDATA[ILArray<complex>]]></destination>
                             * <destination><![CDATA[ILArray<fcomplex>]]></destination>
                             * </type>
                             * </hycalper>
                             */
                        }
                        else if (rng is /*!HC:inCls1*/ ILArray <double> )
                        {
                            /*!HC:inCls1*/
                            ILArray <double> ind = (/*!HC:inCls1*/ ILArray <double>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }
                            #endregion HYCALPER LOOPEND
                            #region HYCALPER AUTO GENERATED CODE
                            // DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !!

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <fcomplex> )
                        {
                            ILArray <fcomplex> ind = (ILArray <fcomplex>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <complex> )
                        {
                            ILArray <complex> ind = (ILArray <complex>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <byte> )
                        {
                            ILArray <byte> ind = (ILArray <byte>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <char> )
                        {
                            ILArray <char> ind = (ILArray <char>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <UInt64> )
                        {
                            ILArray <UInt64> ind = (ILArray <UInt64>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <UInt32> )
                        {
                            ILArray <UInt32> ind = (ILArray <UInt32>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <UInt16> )
                        {
                            ILArray <UInt16> ind = (ILArray <UInt16>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <Int64> )
                        {
                            ILArray <Int64> ind = (ILArray <Int64>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <Int32> )
                        {
                            ILArray <Int32> ind = (ILArray <Int32>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <Int16> )
                        {
                            ILArray <Int16> ind = (ILArray <Int16>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            /* !HC:TYPELIST:
                             *
                             */
                        }
                        else if (rng is ILArray <float> )
                        {
                            ILArray <float> ind = (ILArray <float>)rng;
                            tmp     = ind.Dimensions.NumberOfElements;
                            indices = new int[tmp];
                            for (int p = 0; p < tmp; p++)
                            {
                                indices[p] = (int)ind.GetValue(p);
                            }

                            #endregion HYCALPER AUTO GENERATED CODE
                        }
                        else
                        {
                            throw new ILArgumentTypeException("error removing: dimensions specifier must be numeric type!");
                        }
                    }
                    if (indices == null)
                    {
                        dimensionIdx = 0;
                        dimensions   = m_dimensions;
                        indices      = new int[0] {
                        };
                        return;
                    }
                    #endregion
                }
                else if (range[i] is Slice)
                {
                    #region Python slice input
                    Slice rng = (Slice)range[i];
                    if ((rng != null) && !(rng.start == null && rng.stop == null && rng.step == null))
                    {
                        dimensionIdx = i;
                        if (specCount++ > 0)
                        {
                            throw new ILArgumentException("Error removing: only one dimension must be non-empty!");
                        }
                        List <int> ids = new List <int>();
                        int        start, ende, step;
                        if (rng.start == null)
                        {
                            start = 0;
                        }
                        else
                        {
                            start = (int)(rng.start);
                        }
                        if (rng.stop == null)
                        {
                            ende = m_dimensions[i];
                        }
                        else
                        {
                            ende = (int)(rng.stop) + 1;
                        }
                        if (rng.step == null)
                        {
                            step = 1;
                        }
                        else
                        {
                            step = (int)(rng.step);
                        }
                        try
                        {
                            for (int r = start; r < ende; r += step)
                            {
                                ids.Add(r);
                            }
                            indices = ids.ToArray();
                        }
                        catch (FormatException e)
                        {
                            throw new ILArgumentException("remove: invalid index in " + i.ToString() + "th dimension! (" + e.Message + ")");
                        }
                        if (indices == null)
                        {
                            dimensionIdx = 0;
                            dimensions   = m_dimensions;
                            indices      = new int[0] {
                            };
                            return;
                        }
                    }
                    #endregion
                }
                else if (range is string[])
                {
                    #region string input
                    string rng = (string)range[i];
                    if (rng.Contains(";"))
                    {
                        throw new ILArgumentException("Error removing: ';' not valid");
                    }
                    if (rng != null && rng.Trim() != ":")
                    {
                        dimensionIdx = i;
                        if (specCount++ > 0)
                        {
                            throw new ILArgumentException("Error removing: only one dimension must be non-empty!");
                        }
                        rng = rng.Replace("end", (m_dimensions[i] - 1).ToString());
                        string[]   tmpIdx = rng.Split(',');
                        List <int> ids    = new List <int>();
                        try
                        {
                            for (int c = 0; c < tmpIdx.Length; c++)
                            {
                                string[] tmprng = tmpIdx[c].Split(':');
                                switch (tmprng.Length)
                                {
                                case 1:
                                    // no range spec.
                                    ids.Add(int.Parse(tmprng[0].Trim()));
                                    break;

                                case 2:
                                    // single range: spacing 1
                                    int start = int.Parse(tmprng[0].Trim());
                                    int ende  = int.Parse(tmprng[1].Trim()) + 1;
                                    for (int r = start; r < ende; r++)
                                    {
                                        ids.Add(r);
                                    }
                                    break;

                                case 3:
                                    // single range: spacing 1
                                    start = int.Parse(tmprng[0].Trim());
                                    ende  = int.Parse(tmprng[2].Trim()) + 1;
                                    int step = int.Parse(tmprng[1].Trim());
                                    for (int r = start; r < ende; r += step)
                                    {
                                        ids.Add(r);
                                    }
                                    break;
                                }
                            }
                            indices = ids.ToArray();
                        }
                        catch (FormatException e)
                        {
                            throw new ILArgumentException("remove: invalid index in " + i.ToString() + "th dimension! Did you seperate dimensions by ';'? (" + e.Message + ")");
                        }
                    }
                    if (indices == null)
                    {
                        dimensionIdx = 0;
                        dimensions   = m_dimensions;
                        indices      = new int[0] {
                        };
                        return;
                    }
                    #endregion
                }
                else
                {
                    throw new ILArgumentException("Invalid range specification. The type of indices specified is invalid. Remove failed.");
                }
            }
            // check if array must be reshaped
            int[] tmpDim = new int[(inDimCount > 1) ? inDimCount : 2];
            int   pos    = 0;
            while (pos < m_dimensions.NumberOfDimensions)
            {
                if (pos < inDimCount)
                {
                    tmpDim[pos] = m_dimensions[pos];
                }
                else
                {
                    int mult = 1;
                    int i    = pos;
                    while (i < m_dimensions.NumberOfDimensions)
                    {
                        mult *= m_dimensions[i++];
                    }
                    tmpDim[pos - 1] *= mult;
                    break;
                }
                pos++;
            }
            // if only one dimension specified -> make row vector
            if (pos == 1)
            {
                tmpDim[1]    = tmpDim[0];
                tmpDim[0]    = 1;
                dimensionIdx = 1;
            }
            dimensions = new ILDimension(tmpDim);
        }
Beispiel #13
0
 /// <summary>
 /// Number of elements of A
 /// </summary>
 /// <param name="A">input array</param>
 /// <returns>number of elements of A</returns>
 /// <remarks>this is an alias/abreviation for A.Dimensions.NumberOfElements</remarks>
 public static int numel(ILBaseArray A) {
     if (object.Equals(A,null)) return 0;
     return A.Dimensions.NumberOfElements;   
 }
Beispiel #14
0
 /// <summary>
 /// Number of dimensions of A
 /// </summary>
 /// <param name="A">input array</param>
 /// <returns>if A is null: 0 - else number of dimensions of A</returns>
 /// <remarks>this is an alias/abreviation for A.Dimensions.NumberOfDimensions</remarks>
 /// 
 public static int ndims(ILBaseArray A) {
     if (object.Equals(A,null)) return 0;
     return A.Dimensions.NumberOfDimensions;  
 }
Beispiel #15
0
 /// <summary>
 /// longest dimension of A
 /// </summary>
 /// <param name="A">input array</param>
 /// <returns>if A is null:0 - length of longest dimension of A</returns>
 /// <remarks>this is an alias/abreviation for A.Dimensions.Longest</remarks>
 public static int length(ILBaseArray A) {
     if (object.Equals(A,null)) return 0;
     return A.Dimensions.Longest; 
 }
Beispiel #16
0
 /// <summary>
 /// add array to collection of arrays in this ILMatFile container
 /// </summary>
 /// <param name="A">array to be added to ILMatFile</param>
 /// <returns>string used to identify the array in the collection of arrays</returns>
 /// <remarks><para>The internal <code>Name</code> property of array given will be used as identification key.</para>
 /// <para>Note, the test if elements of A are supported by MatFile specification is done if the MatFile is to be written to stream ('write').</para></remarks>
 /// <exception cref="ILNumerics.Exceptions.ILInvalidOperationException"> if the internal name of A does not fullfill the restrictions given by Matlab.</exception>
 public string Add(ILBaseArray A) {
     this[A.Name] = A; 
     return A.Name; 
 }
Beispiel #17
0
 /// <summary>
 /// Create MatFile object from ILBaseArray
 /// </summary>
 /// <param name="input">ILBaseArray of arbitrary size/type</param>
 /// <exception cref="ArgumentNullException"> if input array was null or one of the names in the input arrays does not fullfill the restrictions made from Matlab</exception>
 public ILMatFile(ILBaseArray[] input) {
     if (object.Equals(input,null))
         throw new ArgumentNullException ("input array may not be null!"); 
     m_data = new Dictionary<string,ILBaseArray> (input.Length);
     for (int i=0; i < input.Length; i++) {
         this[input[i].Name] = input[i]; 
     }
 }
Beispiel #18
0
 public static bool isequal(ILBaseArray A, ILBaseArray B) {
     return A.Equals(B); 
 }