Пример #1
0
 public TType GetField <TType>(int[] coords, int field_number)
 {
     using (MxArray array = GetField(coords, field_number))
     {
         return(MxConvert.FromMxArray <TType>(array));
     }
 }
Пример #2
0
 public TType GetField <TType>(int[] coords, string field_name)
 {
     using (MxArray array = GetField(coords, field_name))
     {
         return(MxConvert.FromMxArray <TType>(array));
     }
 }
Пример #3
0
        static MxArray _MxArrayFromInt16Array(
            Array value)
        {
            int count = value.Length;

            int[] arraydims = MxUtils.GetArrayDimensions(value);
            int[] dims;
            if (value.Rank == 1)
            {
                dims = new int[] { 1, count };
            }
            else
            {
                dims = (int[])arraydims.Clone();
            }
            MxArray result = MxArray.CreateArray(dims,
                                                 ClassID.Int16, Complexity.Real);

            unsafe
            {
                short *pr;
                pr = (short *)result.RealElements;

                for (int i = 0; i < count; i++)
                {
                    *pr++ = (short)
                            value.GetValue(MxUtils.CoordinatesFromIndex(i, arraydims));
                }
            }

            return(result);
        }
Пример #4
0
 public void SetField <TType>(int[] coords, int field_number, TType value)
 {
     using (MxArray array = MxConvert.ToMxArray(value))
     {
         SetField(coords, field_number, array);
     }
 }
Пример #5
0
 public void SetField <TType>(int[] coords, string field_name, TType value)
 {
     using (MxArray array = MxConvert.ToMxArray(value))
     {
         SetField(coords, field_name, array);
     }
 }
Пример #6
0
 public void SetVariable <TType>(string var_name, TType value)
 {
     using (MxArray array = MxConvert.ToMxArray <TType>(value))
     {
         SetVariable(var_name, array);
     }
 }
Пример #7
0
 public void SetField(string field_name, MxArray value)
 {
     if (NumberOfElements > 1)
     {
         throw new InvalidOperationException(DIRECT_SET_FIELD_EXCEPTION);
     }
     SetField(0, field_name, value);
 }
Пример #8
0
 public void SetField <TType>(int index, string field_name, TType value)
 {
     AssertClass(ClassID.Struct, "SetField");
     using (MxArray array = MxConvert.ToMxArray(value))
     {
         SetField(index, field_name, array);
     }
 }
Пример #9
0
 public void SetField <TType>(int index, int field_number, TType value)
 {
     AssertClass(ClassID.Struct, "SetField");
     using (MxArray array = MxConvert.ToMxArray(value))
     {
         SetField(index, field_number, value);
     }
 }
Пример #10
0
 public static MxArray ToMxArray <TType>(TType value)
 {
     if (typeof(TType) == typeof(string))
     {
         return(MxArray.CreateString((string)(Object)value));
     }
     return(_ToMxArray <TType>(value));
 }
Пример #11
0
        unsafe static MxArray _MxArrayFromBoolean(
            bool value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Logical, Complexity.Real);
            bool *pr;

            pr = (bool *)result.RealElements;
            *pr = value;

            return(result);
        }
Пример #12
0
        unsafe static MxArray _MxArrayFromInt16(
            short value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Int16, Complexity.Real);
            short *pr;

            pr = (short *)result.RealElements;
            *pr = value;

            return(result);
        }
Пример #13
0
        unsafe static MxArray _MxArrayFromByte(
            byte value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.UInt8, Complexity.Real);
            byte *pr;

            pr = (byte *)result.RealElements;
            *pr = value;

            return(result);
        }
Пример #14
0
        unsafe static MxArray _MxArrayFromChar(
            char value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Char, Complexity.Real);
            char *pr;

            pr = (char *)result.RealElements;
            *pr = value;

            return(result);
        }
Пример #15
0
        unsafe static MxArray _MxArrayFromDouble(
            double value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Double, Complexity.Real);
            double *pr;

            pr = (double *)result.RealElements;
            *pr = value;

            return(result);
        }
Пример #16
0
        unsafe static MxArray _MxArrayFromSingle(
            float value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Single, Complexity.Real);
            float *pr;

            pr = (float *)result.RealElements;
            *pr = value;

            return(result);
        }
Пример #17
0
        unsafe static MxArray _MxArrayFromInt64(
            long value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Int64, Complexity.Real);
            long *pr;

            pr = (long *)result.RealElements;
            *pr = value;

            return(result);
        }
Пример #18
0
        unsafe static MxArray _MxArrayFromUInt32(
            uint value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.UInt32, Complexity.Real);
            uint *pr;

            pr = (uint *)result.RealElements;
            *pr = value;

            return(result);
        }
Пример #19
0
        public void SetField(int index, string field_name, MxArray value)
        {
            AssertClass(ClassID.Struct, "SetField");
            int fieldIndex = _GetFieldNumber(field_name);

            if (fieldIndex < 0)
            {
                // If the field doesn't exists we automatically add it
                fieldIndex = AddField(field_name);
            }
            SetField(index, fieldIndex, value);
        }
Пример #20
0
 public void SetVariable(string var_name, MxArray array)
 {
     if (array == null)
     {
         throw new ArgumentNullException("array");
     }
     CheckPointer();
     if (LibEng.engPutVariable(m_engine, var_name, array.NativeObject) != 0)
     {
         throw new Exception(String.Format("Unable to put variable {0} in Matlab Engine", var_name));
     }
 }
Пример #21
0
        /// <summary>
        /// Cas spécial pour les strings, utile car si non les strings ne sont que
        /// des char[].
        ///
        /// </summary>
        /// <remarks>
        /// <code></code>
        /// <list type=""
        /// </remarks>
        /// <param name="array">Un mxArray de type Char</param>
        /// <returns>Les caractères du tableau de charactère contenu dans
        /// <paramref name="array"/> sous forme de string.</returns>
        static string ToString(MxArray array)
        {
            if (array == null)
            {
                throw new ArgumentNullException("array");
            }
            if (array.Class != ClassID.Char)
            {
                throw new InvalidCastException("Char mxArray required");
            }

            return(array.StringValue);
        }
Пример #22
0
        unsafe static MxArray _MxArrayFromSingle_Cplx(
            Complex <float> value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Single, Complexity.Complex);
            float *pr, pi;

            pr = (float *)result.RealElements;
            pi = (float *)result.ImaginaryElements;

            *pr = value.RealPart;
            *pi = value.ImaginaryPart;

            return(result);
        }
Пример #23
0
        unsafe static MxArray _MxArrayFromChar_Cplx(
            Complex <char> value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Char, Complexity.Complex);
            char *pr, pi;

            pr = (char *)result.RealElements;
            pi = (char *)result.ImaginaryElements;

            *pr = value.RealPart;
            *pi = value.ImaginaryPart;

            return(result);
        }
Пример #24
0
        unsafe static MxArray _MxArrayFromBoolean_Cplx(
            Complex <bool> value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Logical, Complexity.Complex);
            bool *pr, pi;

            pr = (bool *)result.RealElements;
            pi = (bool *)result.ImaginaryElements;

            *pr = value.RealPart;
            *pi = value.ImaginaryPart;

            return(result);
        }
Пример #25
0
        unsafe static MxArray _MxArrayFromByte_Cplx(
            Complex <byte> value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.UInt8, Complexity.Complex);
            byte *pr, pi;

            pr = (byte *)result.RealElements;
            pi = (byte *)result.ImaginaryElements;

            *pr = value.RealPart;
            *pi = value.ImaginaryPart;

            return(result);
        }
Пример #26
0
        unsafe static MxArray _MxArrayFromInt16_Cplx(
            Complex <short> value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.Int16, Complexity.Complex);
            short *pr, pi;

            pr = (short *)result.RealElements;
            pi = (short *)result.ImaginaryElements;

            *pr = value.RealPart;
            *pi = value.ImaginaryPart;

            return(result);
        }
Пример #27
0
        unsafe static MxArray _MxArrayFromUInt64_Cplx(
            Complex <ulong> value)
        {
            MxArray result = MxArray.CreateArray(new int[] { 1 },
                                                 ClassID.UInt64, Complexity.Complex);
            ulong *pr, pi;

            pr = (ulong *)result.RealElements;
            pi = (ulong *)result.ImaginaryElements;

            *pr = value.RealPart;
            *pi = value.ImaginaryPart;

            return(result);
        }
Пример #28
0
        public static TType FromMxArray <TType>(MxArray array, bool noVectorization)
        {
            ClassID classId = array.Class;
            int     ndims   = array.NumberOfDimensions;

            Type genericType = typeof(TType);
            // There is two sorts of Array types : the ones that answer true to IsArray, where we could
            // get dimensions, element type and other details; and the Array class that could contain
            // any array.
            //bool isArray = genericType.IsArray;
            bool isArrayClass  = genericType == typeof(Array);
            bool isObjectClass = genericType == typeof(Object);
            bool isStringClass = genericType == typeof(String);

            if (isStringClass)
            {
                return((TType)(Object)ToString(array));
            }
            else if (isArrayClass)
            {
                return((TType)(Object)_ConvertToArray(array, classId, ndims));
            }
            else if (isObjectClass)
            {
                // Try to find the C# type that match the mxArray
                if (classId == ClassID.Char)
                {
                    return((TType)(Object)ToString(array));
                }
                else if (array.NumberOfElements == 1)
                {
                    return((TType)_ConvertToBasicType(array, classId));
                }
                else
                {
                    return((TType)(Object)_ConvertToArray(array, classId, ndims));
                }
            }
            else
            {
                // Try to convert the mxArray to the specified C# type
                return(_ConvertToSomeType <TType>(array, classId, ndims, noVectorization));
            }
        }
Пример #29
0
 public TType GetVariable <TType>(string var_name, bool noVectorization)
 {
     using (MxArray array = GetVariable(var_name))
     {
         if (array == null)
         {
             throw new VariableNotFoundException(var_name);
         }
         try
         {
             return(MxConvert.FromMxArray <TType>(array, noVectorization));
         }
         catch (InvalidCastException e)
         {
             throw new InvalidCastException(string.Format(
                                                "Unable to get the variable \"{0}\" as {1}.",
                                                var_name, typeof(TType).Name), e);
         }
     }
 }
Пример #30
0
        public void SetField(int index, int field_number, MxArray value)
        {
            AssertClass(ClassID.Struct, "SetField");
            AssertFieldExists(field_number);

            if (value.Parent != null)
            {
                // We make a copy so we are sure that we could use this array as we wish.
                // We don't do this otherwise for performance reasons.
                value = value.Clone();
            }

            IntPtr oldFieldValue = LibMx.mxGetFieldByNumber(m_array, index, field_number);

            RemoveChilds(oldFieldValue);
            LibMx.mxDestroyArray(oldFieldValue);

            LibMx.mxSetFieldByNumber(m_array, index, field_number, value.m_array);
            value.Parent = this;
        }