Пример #1
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);
        }
Пример #2
0
        public override string ToString()
        {
            if (m_array == IntPtr.Zero)
            {
                return("Deleted mxArray");
            }

            StringBuilder result = new StringBuilder();

            result.Append(MxUtils.DimensionsToString(Dimensions));
            result.Append(" ");
            result.Append(Class.ToString());
            if (IsComplex)
            {
                result.Append(" (complex)");
            }
            result.Append(" mxArray");

            string simpleString = ToSimpleString();

            if (simpleString != null)
            {
                result.Append(" (");
                result.Append(simpleString);
                result.Append(")");
            }

            return(result.ToString());
        }
Пример #3
0
        static MxArray _MxArrayFromInt16Array_Cplx(
            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.Complex);

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

                Complex <short> currentValue;
                for (int i = 0; i < count; i++)
                {
                    currentValue = (Complex <short>)
                                   value.GetValue(MxUtils.CoordinatesFromIndex(i, arraydims));
                    *pr++ = currentValue.RealPart;
                    *pi++ = currentValue.ImaginaryPart;
                }
            }

            return(result);
        }
Пример #4
0
 public int IndexFromCoordinates(int[] coordinates)
 {
     CheckPointer();
     return(MxUtils.IndexFromCoordinates(coordinates, Dimensions));
 }
Пример #5
0
 public int[] CoordinatesFromIndex(int index)
 {
     CheckPointer();
     return(MxUtils.CoordinatesFromIndex(index, Dimensions));
 }