コード例 #1
0
ファイル: TwoColor.cs プロジェクト: tianjing/Packages
 public bool ValidNumber(string pNumber, NumericType pNumericType)
 {
     switch (pNumericType)
     {
         case NumericType.Dan:
         case NumericType.Red: return ValidHelper.NumberHelper.ValidNumber(pNumber, mRedMax, mRedMin);
         case NumericType.Blue: return ValidHelper.NumberHelper.ValidNumber(pNumber, mBlueMax, mBlueMin);
         default: return false;
     }
 }
コード例 #2
0
ファイル: convert.cs プロジェクト: wdxa/ILNumerics
 /// <summary>
 /// convert arbitrary numeric array to arbitrary numeric type
 /// </summary>
 /// <param name="X">input array</param>
 /// <param name="outputType">type description for return type</param>
 /// <returns>converted array</returns>
 /// <remarks> The newly created array will be converted to the type requested. 
 /// <para>Important note: if X matches the type requested, NO COPY will be made for it and the SAME array will be returned!</para></remarks>
 public static ILBaseArray convert(NumericType outputType,  ILArray</*!HC:inType1*/ double > X) {
     if (outputType  == /*!HC:inTypeName*/ NumericType.Double )
         return X; 
     ILBaseArray ret = null; 
     switch (outputType) {
         case NumericType.Double:
             unsafe {
                 double [] retA = ILMemoryPool.Pool.New<double>(X.Dimensions.NumberOfElements);
                 fixed (double * pretA = retA)
                 fixed (/*!HC:inType1*/ double * pX = X.m_data) {
                     double * pStartR = pretA; 
                     double * pEndR = pretA + X.m_data.Length;
                     /*!HC:inType1*/ double * pWalkX = pX; 
                     while (pStartR < pEndR) {
                         *(pStartR++) = (double) *(pWalkX++); 
                     }
                 }
                 ret = new ILArray<double> (retA,X.Dimensions); 
             }
             return ret; 
         case NumericType.Complex:
             unsafe {
                 complex [] retA = ILMemoryPool.Pool.New<complex>(X.Dimensions.NumberOfElements);
                 fixed (complex * pretA = retA)
                 fixed (/*!HC:inType1*/ double * pX = X.m_data) {
                     complex * pStartR = pretA; 
                     complex * pEndR = pretA + X.m_data.Length;
                     /*!HC:inType1*/ double * pWalkX = pX; 
                     while (pStartR < pEndR) {
                         *(pStartR++) = (complex) (*(pWalkX++)); 
                     }
                 }
                 ret = new ILArray<complex> (retA,X.Dimensions); 
             }
             return ret; 
         case NumericType.Byte:
             unsafe {
                 byte [] retA = ILMemoryPool.Pool.New<byte>(X.Dimensions.NumberOfElements);
                 fixed (byte * pretA = retA)
                 fixed (/*!HC:inType1*/ double * pX = X.m_data) {
                     byte * pStartR = pretA; 
                     byte * pEndR = pretA + X.m_data.Length;
                     /*!HC:inType1*/ double * pWalkX = pX; 
                     while (pStartR < pEndR) {
                         *(pStartR++) = (byte) *(pWalkX++); 
                     }
                 }
                 ret = new ILArray<byte> (retA,X.Dimensions); 
             }
             return ret; 
     }
     return ret; 
 }
コード例 #3
0
ファイル: TwoColor.cs プロジェクト: tianjing/Packages
 public void ValidNumbers(String pNumbers, NumericType pNumericType)
 {
     String[] res = pNumbers.Split(SplitStr);
     if (NumberHelper.IsRepeat(res))
     {
         throw new FormatException("error:number is repeat");
     }
     for (var i = 0; i < res.Length; i++)
     {
         if (!ValidHelper.NumberHelper.IsBitLength(res[i], mBit))
         {
             throw new FormatException("error:number bit is error");
         }
         if (!ValidNumber(res[i], pNumericType))
         {
             throw new FormatException("error:number is error");
         }
     }
 }
コード例 #4
0
ファイル: convert.cs プロジェクト: wdxa/ILNumerics
// DO NOT EDIT INSIDE THIS REGION !! CHANGES WILL BE LOST !! 
        /// <summary>
        /// convert arbitrary numeric array to arbitrary numeric type
        /// </summary>
        /// <param name="X">input array</param>
        /// <param name="outputType">type description for return type</param>
        /// <returns>converted array</returns>
        /// <remarks> The newly created array will be converted to the type requested. 
        /// <para>Important note: if X matches the type requested, NO COPY will be made for it and the SAME array will be returned!</para></remarks>
        public static ILBaseArray convert(NumericType outputType,  ILArray< UInt64 > X) {
            if (outputType  ==  NumericType.UInt64 )
                return X; 
            ILBaseArray ret = null; 
            switch (outputType) {
                case NumericType.Double:
                    unsafe {
                        double [] retA = ILMemoryPool.Pool.New<double>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            fixed (double * pretA = retA) {
                                int c = 0; 
                                double * pStart = pretA; 
                                double * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (double) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (double * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                double * pStartR = pretA; 
                                double * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (double) *(pWalkX++); 
                                }
                            }
                        }
                        ret = new ILArray<double> (retA,X.Dimensions); 
                    }
                    return ret; 
                case NumericType.Single:
                    unsafe {
                        float [] retA = ILMemoryPool.Pool.New<float>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (float * pretA = retA) {
                                float * pStart = pretA; 
                                float * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (float) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (float * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                float * pStartR = pretA; 
                                float * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (float) *(pWalkX++); 
                                }
                            }
                        }
                        ret = new ILArray<float> (retA,X.Dimensions); 
                    }
                    return ret; 
                case NumericType.Complex:
                    unsafe {
                        complex [] retA = ILMemoryPool.Pool.New<complex>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (complex * pretA = retA) {
                                complex * pStart = pretA; 
                                complex * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (complex * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                complex * pStartR = pretA; 
                                complex * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (complex) (*(pWalkX++)); 
                                }
                            }
                        }
                        ret = new ILArray<complex> (retA,X.Dimensions); 
                    }
                    return ret; 
                case NumericType.FComplex:
                    unsafe {
                        fcomplex [] retA = ILMemoryPool.Pool.New<fcomplex>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (fcomplex * pretA = retA) {
                                fcomplex * pStart = pretA; 
                                fcomplex * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (fcomplex) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (fcomplex * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                fcomplex * pStartR = pretA; 
                                fcomplex * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (fcomplex) (*(pWalkX++)); 
                                }
                            }
                        }
                        ret = new ILArray<fcomplex> (retA,X.Dimensions); 
                    }
                    return ret; 
                case NumericType.Byte:
                    unsafe {
                        byte [] retA = ILMemoryPool.Pool.New<byte>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (byte * pretA = retA) {
                                byte * pStart = pretA; 
                                byte * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (byte) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (byte * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                byte * pStartR = pretA; 
                                byte * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (byte) *(pWalkX++); 
                                }
                            }
                        }
                        ret = new ILArray<byte> (retA,X.Dimensions); 
                    }
                    return ret; 
                case NumericType.Char:
                    unsafe {
                        char [] retA = ILMemoryPool.Pool.New<char>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (char * pretA = retA) {
                                char * pStart = pretA; 
                                char * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (char) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (char * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                char * pStartR = pretA; 
                                char * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (char) *(pWalkX++); 
                                }
                            }
                        }
                        ret = new ILArray<char> (retA,X.Dimensions); 
                    }
                    return ret; 
                case NumericType.Int16:
                    unsafe {
                        Int16 [] retA = ILMemoryPool.Pool.New<Int16>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (Int16 * pretA = retA) {
                                Int16 * pStart = pretA; 
                                Int16 * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (Int16) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (Int16 * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                Int16 * pStartR = pretA; 
                                Int16 * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (short) *(pWalkX++); 
                                }
                            }
                        }
                        ret = new ILArray<Int16> (retA,X.Dimensions); 
                    }
                    return ret; 
                 case NumericType.Int32:
                    unsafe {
                        Int32 [] retA = ILMemoryPool.Pool.New<Int32>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (Int32 * pretA = retA) {
                                Int32 * pStart = pretA; 
                                Int32 * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (Int32) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (Int32 * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                Int32 * pStartR = pretA; 
                                Int32 * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (Int32) (*(pWalkX++)); 
                                }
                            }
                        }
                        ret = new ILArray<Int32> (retA,X.Dimensions); 
                    }
                    return ret; 
                 case NumericType.Int64:
                    unsafe {
                        Int64 [] retA = ILMemoryPool.Pool.New<Int64>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (Int64 * pretA = retA) {
                                Int64 * pStart = pretA; 
                                Int64 * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (Int64) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (Int64 * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                Int64 * pStartR = pretA; 
                                Int64 * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (Int64) (*(pWalkX++)); 
                                }
                            }
                        }
                        ret = new ILArray<Int64> (retA,X.Dimensions); 
                    }
                    return ret; 
                 case NumericType.UInt16:
                    unsafe {
                        UInt16 [] retA = ILMemoryPool.Pool.New<UInt16>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (UInt16 * pretA = retA) {
                                UInt16 * pStart = pretA; 
                                UInt16 * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (UInt16) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (UInt16 * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                UInt16 * pStartR = pretA; 
                                UInt16 * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (UInt16) (*(pWalkX++)); 
                                }
                            }
                        }
                        ret = new ILArray<UInt16> (retA,X.Dimensions); 
                    }
                    return ret; 
                 case NumericType.UInt32:
                    unsafe {
                        UInt32 [] retA = ILMemoryPool.Pool.New<UInt32>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (UInt32 * pretA = retA) {
                                UInt32 * pStart = pretA; 
                                UInt32 * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (UInt32) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (UInt32 * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                UInt32 * pStartR = pretA; 
                                UInt32 * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (UInt32) (*(pWalkX++)); 
                                }
                            }
                        }
                        ret = new ILArray<UInt32> (retA,X.Dimensions); 
                    }
                    return ret; 
                 case NumericType.UInt64:
                    unsafe {
                        UInt64 [] retA = ILMemoryPool.Pool.New<UInt64>(X.Dimensions.NumberOfElements);
                        if (X.IsReference) {
                            int c = 0; 
                            fixed (UInt64 * pretA = retA) {
                                UInt64 * pStart = pretA; 
                                UInt64 * pEnd = pretA + retA.Length; 
                                while (pStart < pEnd) {
                                    *(pStart++) = (UInt64) X.GetValue(c++);
                                }
                            }
                        } else {
                            fixed (UInt64 * pretA = retA)
                            fixed ( UInt64 * pX = X.m_data) {
                                UInt64 * pStartR = pretA; 
                                UInt64 * pEndR = pretA + X.m_data.Length;
                                UInt64 * pWalkX = pX; 
                                while (pStartR < pEndR) {
                                    *(pStartR++) = (UInt64) (*(pWalkX++)); 
                                }
                            }
                        }
                        ret = new ILArray<UInt64> (retA,X.Dimensions); 
                    }
                    return ret; 
            }
            return ret; 
        }
コード例 #5
0
ファイル: convert.cs プロジェクト: wdxa/ILNumerics
 /// <summary>
 /// Convert arbitrary (numeric) array to other inner type
 /// </summary>
 /// <param name="typeName">Numeric type for output</param>
 /// <param name="X">input array, arbitrary inner type</param>
 /// <returns>Numeric array with specified inner element type</returns>
 public static ILBaseArray convert(NumericType typeName, ILBaseArray X) {
     if (X is ILArray<double>) {
         return convert(typeName,X as ILArray<double>);  
     } else if (X is ILArray<float>) {
         return convert(typeName,X as ILArray<float>); 
     } else if (X is ILArray<complex>) {
         return convert(typeName,X as ILArray<complex>);  
     } else if (X is ILArray<fcomplex>) {
         return convert(typeName,X as ILArray<fcomplex>);
     } else if (X is ILArray<byte>) {
         return convert(typeName,X as ILArray<byte>);  
     } else if (X is ILArray<char>) {
         return convert(typeName,X as ILArray<char>);
     } else if (X is ILArray<Int16>) {
         return convert(typeName,X as ILArray<Int16>);  
     } else if (X is ILArray<Int32>) {
         return convert(typeName,X as ILArray<Int32>);  
     } else if (X is ILArray<Int64>) {
         return convert(typeName,X as ILArray<Int64>);  
     } else if (X is ILArray<UInt16>) {
         return convert(typeName,X as ILArray<UInt16>); 
     } else if (X is ILArray<UInt32>) {
         return convert(typeName,X as ILArray<UInt32>);  
     } else if (X is ILArray<UInt64>) {
         return convert(typeName,X as ILArray<UInt64>);  
     } else 
         throw new ILArgumentException("convert: cannot convert invalid (non numeric) inner data type: '" + X.GetType().GetGenericArguments()[0].Name + "'");
 }
コード例 #6
0
ファイル: ILMathCreation.cs プロジェクト: wdxa/ILNumerics
        /// <summary>
        /// Create array initialized with all elements set to one.
        /// </summary>
        /// <param name="type">Numeric type specification. One value out of the types listed in the <see cred="ILNumerics.NumericType"/>
        /// enum.</param>
        /// <param name="dimensions">Dimension specification. At least one dimension must be specified.</param>
        /// <returns>ILArray&lt;BaseT&gt; of inner type corresponding to <paramref name="type"/> argument.</returns>
        /// <remarks>The array returned may be cast to the appropriate actual type afterwards. 
        /// <para>
        /// <list type="number"> 
        /// <listheader>The following types are supported: </listheader>
        /// <item>Double</item>
        /// <item>Single</item>
        /// <item>Complex</item>
        /// <item>FComplex</item>
        /// <item>Byte</item>
        /// <item>Char</item>
        /// <item>Int16</item>
        /// <item>Int32</item>
        /// <item>Int64</item>
        /// <item>UInt16</item>
        /// <item>UInt32</item>
        /// <item>UInt64</item>
        /// </list>
        /// </para>
        /// </remarks>
        public static ILBaseArray ones(NumericType type, params int[] dimensions) {
            if (dimensions.Length < 1)
                throw new ILArgumentException("ones: invalid dimension specified!"); 
            switch (type) {
                case NumericType.Double: 
                    return ones(dimensions); 
                case NumericType.Single: 
	                ILDimension dim = new ILDimension(dimensions);
                    unsafe {
                        float[] data = null; 
                        data = new float[dim.NumberOfElements];
                        fixed(float* pD = data) {
                            float* pStart = pD; 
                            float* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = 1.0f; 
                            }
                        }
                        return new ILArray<float>(data, dimensions);
                    }
                case NumericType.Complex: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        complex[] data = null; 
                        data = new complex[dim.NumberOfElements];
                        fixed(complex* pD = data) {
                            complex* pStart = pD; 
                            complex* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = new complex(1.0,1.0); 
                            }
                        }
	                    return new ILArray<complex>(data, dimensions);
                    }
                case NumericType.FComplex: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        fcomplex[] data = null; 
                        data = new fcomplex[dim.NumberOfElements];
                        fixed(fcomplex* pD = data) {
                            fcomplex* pStart = pD; 
                            fcomplex* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = new fcomplex(1.0f,1.0f); 
                            }
                        }
	                    return new ILArray<fcomplex>(data, dimensions);
                    }
                case NumericType.Byte: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        byte[] data =  null; 
                        data = new byte[dim.NumberOfElements];
                        fixed(byte* pD = data) {
                            byte* pStart = pD; 
                            byte* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = 1; 
                            }
                        }
 	                    return new ILArray<byte>(data, dimensions);
                   }
                case NumericType.Char: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        char[] data =  null; 
                        data = new char[dim.NumberOfElements];
                        fixed(char* pD = data) {
                            char* pStart = pD; 
                            char* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = Char.MinValue; 
                            }
                        }
	                    return new ILArray<char>(data, dimensions);
                    }
                case NumericType.Int16: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        Int16[] data =  null; 
                        data = new Int16[dim.NumberOfElements];
                        fixed(Int16* pD = data) {
                            Int16* pStart = pD; 
                            Int16* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = 1; 
                            }
                        }
	                    return new ILArray<Int16>(data, dimensions);
                    }
                case NumericType.Int32: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        Int32[] data =  null; 
                        data = new Int32[dim.NumberOfElements];
                        fixed(Int32* pD = data) {
                            Int32* pStart = pD; 
                            Int32* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = 1; 
                            }
                        }
	                    return new ILArray<Int32>(data, dimensions);
                    }
                case NumericType.Int64: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        Int64[] data =  null; 
                        data = new Int64[dim.NumberOfElements];
                        fixed(Int64* pD = data) {
                            Int64* pStart = pD; 
                            Int64* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = 1; 
                            }
                        }
 	                    return new ILArray<Int64>(data, dimensions);
                   }
                case NumericType.UInt16: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        UInt16[] data =  null; 
                        data = new UInt16[dim.NumberOfElements];
                        fixed(UInt16* pD = data) {
                            UInt16* pStart = pD; 
                            UInt16* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = 1; 
                            }
                        }
	                    return new ILArray<UInt16>(data, dimensions);
                    }
                case NumericType.UInt32: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        UInt32[] data =  null; 
                        data = new UInt32[dim.NumberOfElements];
                        fixed(UInt32* pD = data) {
                            UInt32* pStart = pD; 
                            UInt32* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = 1; 
                            }
                        }
 	                    return new ILArray<UInt32>(data, dimensions);
                   }
                case NumericType.UInt64: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        UInt64[] data =  null; 
                        data = new UInt64[dim.NumberOfElements];
                        fixed(UInt64* pD = data) {
                            UInt64* pStart = pD; 
                            UInt64* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = 1; 
                            }
                        }
	                    return new ILArray<UInt64>(data, dimensions);
                    }
            }
            return null; 
        }
コード例 #7
0
ファイル: ILMathCreation.cs プロジェクト: wdxa/ILNumerics
        /// <summary>
        /// Create array innitialized with ones
        /// </summary>
        /// <param name="type">Numeric type specification. One value out of the types listed in the <see cred="ILNumerics.NumericType"/>
        /// enum.</param>
        /// <param name="dimensions">Dimension specification. At least one dimension must be specified.</param>
        /// <returns>ILArray&lt;BaseT&gt; of inner type corresponding to <paramref name="type"/> argument.</returns>
        /// <remarks>The array returned may be casted to the actual type accordingly afterwards. 
        /// <para>
        /// <list type="number"> 
        /// <listheader>The following types are supported: </listheader>
        /// <item>Double</item>
        /// <item>Single</item>
        /// <item>Complex</item>
        /// <item>FComplex</item>
        /// <item>Byte</item>
        /// <item>Char</item>
        /// <item>Int16</item>
        /// <item>Int32</item>
        /// <item>Int64</item>
        /// <item>UInt16</item>
        /// <item>UInt32</item>
        /// <item>UInt64</item>
        /// </list>
        /// </para>
        /// </remarks>
        public static ILBaseArray ones(NumericType type, params int[] dimensions) {
            if (dimensions.Length < 1)
                throw new ILArgumentException("ones: invalid dimension specified!"); 
            switch (type) {
                case NumericType.Double: 
                    return ones(dimensions); 
                case NumericType.Complex: 
	                ILDimension dim = new ILDimension(dimensions);
                    unsafe {
                        complex[] data = null; 
                        data = new complex[dim.NumberOfElements];
                        fixed(complex* pD = data) {
                            complex* pStart = pD; 
                            complex* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = new complex(1.0,1.0); 
                            }
                        }
	                    return new ILArray<complex>(data, dimensions);
                    }
                case NumericType.Byte: 
	                dim = new ILDimension(dimensions);
                    unsafe {
                        byte[] data =  null; 
                        data = new byte[dim.NumberOfElements];
                        fixed(byte* pD = data) {
                            byte* pStart = pD; 
                            byte* pEnd = pD + data.Length; 
                            while (pEnd > pStart) {
                                *(--pEnd) = 1; 
                            }
                        }
 	                    return new ILArray<byte>(data, dimensions);
                   }
            }
            return null; 
        }