Ejemplo n.º 1
0
        public Matrix(MatrixTemplateSizeParameter parameter)
            : base(parameter.TemplateRows, parameter.TemplateColumns)
        {
            if (!TryParse(typeof(TElement), out var type))
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            if (parameter == null)
                throw new ArgumentNullException(nameof(parameter));
            if (parameter.TemplateRows < 0)
                throw new ArgumentOutOfRangeException($"{nameof(parameter.TemplateRows)}", $"{nameof(parameter.TemplateRows)} should be positive value.");
            if (parameter.TemplateColumns < 0)
                throw new ArgumentOutOfRangeException($"{nameof(parameter.TemplateColumns)}", $"{nameof(parameter.TemplateColumns)} should be positive value.");

            var templateRows = parameter.TemplateRows;
            var templateColumns = parameter.TemplateColumns;

            var error = NativeMethods.matrix_new4(type.ToNativeMatrixElementType(),
                                                  (uint)templateRows,
                                                  (uint)templateColumns,
                                                  out var ret);
            switch (error)
            {
                case NativeMethods.ErrorType.MatrixElementTypeNotSupport:
                    throw new ArgumentException($"Input {type} is not supported.");
                case NativeMethods.ErrorType.MatrixElementTemplateSizeNotSupport:
                    throw new ArgumentException($"{nameof(templateRows)} or {nameof(templateRows)} is not supported.");
            }

            this.NativePtr = ret;
            this._MatrixElementTypes = type;
            this._ElementType = type.ToNativeMatrixElementType();
            this._Indexer = this.CreateIndexer(type);
        }
Ejemplo n.º 2
0
        public Matrix(Array2D <TElement> array)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }

            array.ThrowIfDisposed();

            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();
            var ret = NativeMethods.mat_matrix(array.ImageType.ToNativeArray2DType(),
                                               array.NativePtr,
                                               0,
                                               0,
                                               this._ElementType,
                                               out var ptr);

            switch (ret)
            {
            case NativeMethods.ErrorType.MatrixElementTypeNotSupport:
                throw new ArgumentException($"{array.ImageType} can not convert to {type}.");
            }

            this.NativePtr = ptr;
            this._Indexer  = this.CreateIndexer(type);
        }
Ejemplo n.º 3
0
        public Matrix(byte[] array, int row, int column, int elementSize)
        {
            if (array == null)
                throw new ArgumentNullException(nameof(array));
            if (row < 0)
                throw new ArgumentOutOfRangeException($"{nameof(row)}", $"{nameof(row)} should be positive value.");
            if (column < 0)
                throw new ArgumentOutOfRangeException($"{nameof(column)}", $"{nameof(column)} should be positive value.");
            if (elementSize < 1)
                throw new ArgumentOutOfRangeException($"{nameof(elementSize)} should be greater than or equal to 1.");
            if (array.Length != row * column * elementSize)
                throw new ArgumentOutOfRangeException($"{nameof(array)}.Length should equal to {nameof(row)} x {nameof(column)} x {nameof(elementSize)}.");

            if (!TryParse(typeof(TElement), out var type))
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");

            this._MatrixElementTypes = type;
            this._ElementType = type.ToNativeMatrixElementType();

            var size = ElementSizeDictionary[this._ElementType];
            if (size != elementSize)
                throw new ArgumentOutOfRangeException($"The size of {typeof(TElement).Name} does not equalt to {nameof(elementSize)}.");

            unsafe
            {
                fixed (byte* src = &array[0])
                    this.NativePtr = NativeMethods.matrix_new3(this._ElementType, row, column, src);
            }

            this._Indexer = this.CreateIndexer(type);
        }
Ejemplo n.º 4
0
        public PolynomialKernel(int templateRow = 0, int templateColumn = 0) :
            base(SvmKernelType.Polynomial, templateRow, templateColumn)
        {
            if (!NumericKernelTypesRepository.SupportTypes.TryGetValue(typeof(TScalar), out _))
            {
                throw new NotSupportedException();
            }

            if (!Matrix <TScalar> .TryParse <TScalar>(out var type))
            {
                throw new NotSupportedException();
            }

            this.SampleType   = type;
            this._ElementType = type.ToNativeMatrixElementType();

            var error = NativeMethods.polynomial_kernel_new(this._ElementType, templateRow, templateColumn, out var ret);

            switch (error)
            {
            case NativeMethods.ErrorType.MatrixElementTypeNotSupport:
                throw new ArgumentException($"{type} is not supported.");

            case NativeMethods.ErrorType.MatrixElementTemplateSizeNotSupport:
                throw new ArgumentException($"{nameof(templateColumn)} or {nameof(templateRow)} is not supported.");

            case NativeMethods.ErrorType.SvmKernelNotSupport:
                throw new ArgumentException($"{this.KernelType} is not supported.");
            }

            this.NativePtr = ret;
        }
Ejemplo n.º 5
0
 internal FloatImp(DlibObject parent,
                   KernelBaseParameter kernelParameter,
                   NativeMethods.MatrixElementType elementType,
                   NativeMethods.SvmFunctionType functionType) :
     base(parent, kernelParameter, elementType, functionType)
 {
 }
Ejemplo n.º 6
0
        public RadialBasisKernel(TScalar gamma, int templateRow, int templateColumn) :
            base(SvmKernelType.RadialBasis, templateRow, templateColumn)
        {
            if (!NumericKernelTypesRepository.SupportTypes.TryGetValue(typeof(TScalar), out _))
            {
                throw new NotSupportedException();
            }

            if (!Matrix <TScalar> .TryParse <TScalar>(out var type))
            {
                throw new NotSupportedException();
            }

            this.SampleType   = type;
            this._ElementType = type.ToNativeMatrixElementType();

            this._Bridge = CreateBridge(type, templateRow, templateColumn);

            var error = this._Bridge.Create(gamma, templateRow, templateColumn, out var ret);

            switch (error)
            {
            case NativeMethods.ErrorType.MatrixElementTypeNotSupport:
                throw new ArgumentException($"{type} is not supported.");

            case NativeMethods.ErrorType.MatrixElementTemplateSizeNotSupport:
                throw new ArgumentException($"{nameof(templateColumn)} or {nameof(templateRow)} is not supported.");
            }

            this.NativePtr = ret;
        }
Ejemplo n.º 7
0
 internal SigmoidKernel(IntPtr ptr, int templateRow, int templateColumn, bool isEnabledDispose = true) :
     base(SvmKernelType.Sigmoid, templateRow, templateColumn, isEnabledDispose)
 {
     Matrix<TScalar>.TryParse<TScalar>(out var type);
     this.SampleType = type;
     this._ElementType = type.ToNativeMatrixElementType();
     this.NativePtr = ptr;
 }
Ejemplo n.º 8
0
        internal MatrixRangeExp(IntPtr ptr)
        {
            Matrix <T> .TryParse <T>(out var type);

            this._NativeMatrixElementType = type.ToNativeMatrixElementType();
            this._MatrixElementType       = type;

            this.NativePtr = ptr;
        }
Ejemplo n.º 9
0
        internal MatrixOp(NativeMethods.ElementType elementType, MatrixElementTypes type, IntPtr ptr, int templateRows = 0, int templateColumns = 0)
        {
            this._ElementType       = elementType;
            this._MatrixElementType = type.ToNativeMatrixElementType();
            this.NativePtr          = ptr;

            this.TemplateRows    = templateRows;
            this.TemplateColumns = templateColumns;
        }
Ejemplo n.º 10
0
 internal Imp(DlibObject parent,
              KernelBaseParameter kernelParameter,
              NativeMethods.MatrixElementType elementType,
              NativeMethods.SvmFunctionType functionType)
 {
     this.Parent          = parent ?? throw new ArgumentNullException(nameof(parent));
     this.KernelParameter = kernelParameter;
     this.ElementType     = elementType;
     this.FunctionType    = functionType;
 }
Ejemplo n.º 11
0
        public MatrixRangeExp(T start, T end, int num)
        {
            Matrix <T> .TryParse <T>(out var type);

            this._Bridge = CreateBridge(type);

            this._NativeMatrixElementType = type.ToNativeMatrixElementType();
            this._MatrixElementType       = type;

            this.NativePtr = this._Bridge.Create3(start, end, num);
        }
Ejemplo n.º 12
0
        public Matrix()
        {
            if (!TryParse(typeof(TElement), out var type))
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");

            this._MatrixElementTypes = type;
            this._ElementType = type.ToNativeMatrixElementType();
            this.NativePtr = NativeMethods.matrix_new(this._ElementType);

            this._Indexer = this.CreateIndexer(type);
        }
Ejemplo n.º 13
0
        internal MatrixRangeExp(IntPtr ptr)
        {
            if (!SupportTypes.TryGetValue(typeof(T), out var type))
            {
                throw new NotSupportedException($"{typeof(T).Name} does not support");
            }

            this._NativeMatrixElementType = type.ToNativeMatrixElementType();
            this._MatrixElementType       = type;
            this.NativePtr = ptr;
        }
Ejemplo n.º 14
0
            internal Row(IntPtr ptr, NativeMethods.MatrixElementType type, Array2DMatrixBase parent)
            {
                if (ptr == IntPtr.Zero)
                {
                    throw new ArgumentException("Can not pass IntPtr.Zero", nameof(ptr));
                }

                this._Parent   = parent ?? throw new ArgumentNullException(nameof(parent));
                this.NativePtr = ptr;
                this._Type     = type;
            }
Ejemplo n.º 15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RunningStats{TTKernel}"/> class.
        /// </summary>
        public VectorNormalizer()
            : base(NormalizerType.Vector)
        {
            if (!VectorNormalizerElementTypesRepository.Types.TryGetValue(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._ElementType = type.ToNativeMatrixElementType();
            this._Imp         = this.CreateImp(type);
            this.NativePtr    = NativeMethods.vector_normalizer_new(this._ElementType);
        }
Ejemplo n.º 16
0
        internal RadialBasisKernel(IntPtr ptr, int templateRow, int templateColumn, bool isEnabledDispose = true) :
            base(SvmKernelType.RadialBasis, templateRow, templateColumn, isEnabledDispose)
        {
            Matrix <TScalar> .TryParse <TScalar>(out var type);

            this.SampleType   = type;
            this._ElementType = type.ToNativeMatrixElementType();

            this._Bridge = CreateBridge(type, templateRow, templateColumn);

            this.NativePtr = ptr;
        }
Ejemplo n.º 17
0
        public LinearKernel(int templateRow = 0, int templateColumn = 0)
        {
            using (var tmp = new T())
            {
                this._MatrixElementTypes = tmp.MatrixElementType;
                this._ElementType        = this._MatrixElementTypes.ToNativeMatrixElementType();

                this.TemplateRows    = templateRow;
                this.TemplateColumns = templateColumn;

                this.NativePtr = NativeMethods.linear_kernel_new(this._ElementType, templateRow, templateColumn);
            }
        }
Ejemplo n.º 18
0
            internal SurfPointMatrix(IntPtr ptr, bool isEnableDispose)
                : base(ptr, 0, 0, isEnableDispose)
            {
                if (!SupportMatrixTypes.TryGetValue(typeof(T), out var matrixType))
                {
                    throw new NotSupportedException($"{typeof(T).Name} does not support");
                }

                this._MatrixElementType = matrixType.ToNativeMatrixElementType();

                this.NativePtr         = ptr;
                this.MatrixElementType = matrixType;
            }
Ejemplo n.º 19
0
        public Matrix(IntPtr array, int row, int column, int stride)
        {
            if (array == IntPtr.Zero)
            {
                throw new ArgumentException($"{nameof(array)} must not be {nameof(IntPtr)}.{nameof(IntPtr.Zero)}", nameof(array));
            }
            if (row < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(row)}", $"{nameof(row)} should be positive value.");
            }
            if (column < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(column)}", $"{nameof(column)} should be positive value.");
            }
            if (column < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(stride)} should be positive value.");
            }

            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();

            unsafe
            {
                switch (this._ElementType)
                {
                case NativeMethods.MatrixElementType.UInt8:
                case NativeMethods.MatrixElementType.UInt16:
                case NativeMethods.MatrixElementType.UInt32:
                case NativeMethods.MatrixElementType.Int8:
                case NativeMethods.MatrixElementType.Int16:
                case NativeMethods.MatrixElementType.Int32:
                case NativeMethods.MatrixElementType.Float:
                case NativeMethods.MatrixElementType.Double:
                case NativeMethods.MatrixElementType.RgbPixel:
                case NativeMethods.MatrixElementType.BgrPixel:
                case NativeMethods.MatrixElementType.RgbAlphaPixel:
                case NativeMethods.MatrixElementType.HsiPixel:
                case NativeMethods.MatrixElementType.LabPixel:
                    this.NativePtr = NativeMethods.matrix_new6(this._ElementType, row, column, stride, array);
                    break;
                }
            }

            this._Indexer = this.CreateIndexer(type);
        }
Ejemplo n.º 20
0
        public MatrixRangeExp(T start, T end, uint num)
        {
            if (!SupportTypes.TryGetValue(typeof(T), out var type))
            {
                throw new NotSupportedException($"{typeof(T).Name} does not support");
            }

            this._NativeMatrixElementType = type.ToNativeMatrixElementType();
            this._MatrixElementType       = type;

            var param = this.CreataParam(start, end, false, default(T), true, num);

            this.NativePtr = NativeMethods.matrix_range_exp_create(this._NativeMatrixElementType, ref param);
        }
Ejemplo n.º 21
0
        internal Matrix(IntPtr ptr, int templateRows = 0, int templateColumns = 0, bool isEnabledDispose = true)
            : base(templateRows, templateColumns, isEnabledDispose)
        {
            if (ptr == IntPtr.Zero)
                throw new ArgumentException("Can not pass IntPtr.Zero", nameof(ptr));

            if (!TryParse(typeof(TElement), out var type))
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");

            this.NativePtr = ptr;
            this._MatrixElementTypes = type;
            this._ElementType = type.ToNativeMatrixElementType();

            this._Indexer = this.CreateIndexer(type);
        }
Ejemplo n.º 22
0
        public Matrix(int row, int column)
        {
            if (!TryParse(typeof(TElement), out var type))
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            if (row < 0)
                throw new ArgumentOutOfRangeException($"{nameof(row)}", $"{nameof(row)} should be positive value.");
            if (column < 0)
                throw new ArgumentOutOfRangeException($"{nameof(column)}", $"{nameof(column)} should be positive value.");

            this._MatrixElementTypes = type;
            this._ElementType = type.ToNativeMatrixElementType();
            this.NativePtr = NativeMethods.matrix_new1(this._ElementType, row, column);

            this._Indexer = this.CreateIndexer(type);
        }
Ejemplo n.º 23
0
        public Array2DMatrix()
        {
            if (!SupportMatrixTypes.TryGetValue(typeof(TElement), out var matrixType))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._MatrixElementType = matrixType.ToNativeMatrixElementType();

            this.NativePtr = NativeMethods.array2d_matrix_new(this._MatrixElementType, 0, 0);
            if (this.NativePtr == IntPtr.Zero)
            {
                throw new ArgumentException($"{matrixType} is not supported.");
            }

            this.MatrixElementType = matrixType;
        }
Ejemplo n.º 24
0
        public Array2DMatrix(int rows, int columns, int templateRows = 0, int templateColumns = 0) :
            base(templateRows, templateColumns)
        {
            if (!SupportMatrixTypes.TryGetValue(typeof(TElement), out var matrixType))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._MatrixElementType = matrixType.ToNativeMatrixElementType();

            this.NativePtr = NativeMethods.array2d_matrix_new1(this._MatrixElementType, rows, columns, templateRows, templateColumns);
            if (this.NativePtr == IntPtr.Zero)
            {
                throw new ArgumentException($"{matrixType} is not supported.");
            }

            this.MatrixElementType = matrixType;
        }
Ejemplo n.º 25
0
        private Imp <TScalar> CreateImp(NativeMethods.MatrixElementType type)
        {
            switch (type)
            {
            case NativeMethods.MatrixElementType.UInt8:
                return(new UInt8Imp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            case NativeMethods.MatrixElementType.Int8:
                return(new Int8Imp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            case NativeMethods.MatrixElementType.UInt16:
                return(new UInt16Imp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            case NativeMethods.MatrixElementType.Int16:
                return(new Int16Imp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            case NativeMethods.MatrixElementType.UInt32:
                return(new UInt32Imp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            case NativeMethods.MatrixElementType.Int32:
                return(new Int32Imp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            case NativeMethods.MatrixElementType.UInt64:
                return(new UInt64Imp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            case NativeMethods.MatrixElementType.Int64:
                return(new Int64Imp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            case NativeMethods.MatrixElementType.Double:
                return(new DoubleImp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            case NativeMethods.MatrixElementType.Float:
                return(new FloatImp(this, this._Parameter, type, this._SvmFunctionType) as Imp <TScalar>);

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Ejemplo n.º 26
0
        public Matrix(TElement[] array, int row, int column)
        {
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }
            if (row < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(row)}", $"{nameof(row)} should be positive value.");
            }
            if (column < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(column)}", $"{nameof(column)} should be positive value.");
            }
            if (array.Length != row * column)
            {
                throw new ArgumentOutOfRangeException($"{nameof(array)}.Length should equal to {nameof(row)} x {nameof(column)}.");
            }

            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._MatrixElementTypes = type;
            this._ElementType        = type.ToNativeMatrixElementType();

            unsafe
            {
                switch (this._ElementType)
                {
                case NativeMethods.MatrixElementType.UInt8:
                {
                    var tmp = array as byte[];

                    fixed(byte *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.UInt16:
                {
                    var tmp = array as ushort[];

                    fixed(ushort *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.UInt32:
                {
                    var tmp = array as uint[];

                    fixed(uint *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Int8:
                {
                    var tmp = array as sbyte[];

                    fixed(sbyte *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Int16:
                {
                    var tmp = array as short[];

                    fixed(short *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Int32:
                {
                    var tmp = array as int[];

                    fixed(int *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Float:
                {
                    var tmp = array as float[];

                    fixed(float *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.Double:
                {
                    var tmp = array as double[];

                    fixed(double *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.RgbPixel:
                {
                    var tmp = array as RgbPixel[];

                    fixed(RgbPixel *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.BgrPixel:
                {
                    var tmp = array as BgrPixel[];

                    fixed(BgrPixel *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.RgbAlphaPixel:
                {
                    var tmp = array as RgbAlphaPixel[];

                    fixed(RgbAlphaPixel *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.HsiPixel:
                {
                    var tmp = array as HsiPixel[];

                    fixed(HsiPixel *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;

                case NativeMethods.MatrixElementType.LabPixel:
                {
                    var tmp = array as LabPixel[];

                    fixed(LabPixel *src = &tmp[0])
                    this.NativePtr = NativeMethods.matrix_new2(this._ElementType, row, column, (IntPtr)src);
                }
                break;
                }
            }

            this._Indexer = this.CreateIndexer(type);
        }
Ejemplo n.º 27
0
        public Matrix(MatrixTemplateSizeParameter parameter, TElement[] array)
            : base(parameter.TemplateRows, parameter.TemplateColumns)
        {
            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }
            if (parameter == null)
            {
                throw new ArgumentNullException(nameof(parameter));
            }
            if (array == null)
            {
                throw new ArgumentNullException(nameof(array));
            }
            if (parameter.TemplateRows < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(parameter.TemplateRows)}", $"{nameof(parameter.TemplateRows)} should be positive value.");
            }
            if (parameter.TemplateColumns < 0)
            {
                throw new ArgumentOutOfRangeException($"{nameof(parameter.TemplateColumns)}", $"{nameof(parameter.TemplateColumns)} should be positive value.");
            }

            var templateRows    = parameter.TemplateRows;
            var templateColumns = parameter.TemplateColumns;

            if (templateRows * templateColumns != 0)
            {
                if (templateRows * templateColumns != array.Length)
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
            else if (templateRows != 0)
            {
                if (array.Length % templateRows != 0)
                {
                    throw new ArgumentOutOfRangeException();
                }
            }
            else if (templateColumns != 0)
            {
                if (array.Length % templateColumns != 0)
                {
                    throw new ArgumentOutOfRangeException();
                }
            }

            using (var vector = new StdVector <TElement>(array))
            {
                var error = NativeMethods.matrix_new5(type.ToNativeMatrixElementType(),
                                                      (uint)templateRows,
                                                      (uint)templateColumns,
                                                      vector.NativePtr,
                                                      out var ret);
                switch (error)
                {
                case NativeMethods.ErrorType.MatrixElementTypeNotSupport:
                    throw new ArgumentException($"Input {type} is not supported.");

                case NativeMethods.ErrorType.MatrixElementTemplateSizeNotSupport:
                    throw new ArgumentException($"{nameof(templateRows)} or {nameof(templateRows)} is not supported.");
                }

                this.NativePtr           = ret;
                this._MatrixElementTypes = type;
                this._ElementType        = type.ToNativeMatrixElementType();
                this._Indexer            = this.CreateIndexer(type);
            }
        }
Ejemplo n.º 28
0
 public static extern NativeMethods.ErrorType matrix_op_op_std_vect_to_mat_operator_left_shift(NativeMethods.MatrixElementType type, IntPtr obj, int templateRows, int templateColumns, IntPtr stream);
Ejemplo n.º 29
0
 public static extern NativeMethods.ErrorType matrix_op_op_join_rows_nr(NativeMethods.MatrixElementType type, IntPtr obj, int templateRows, int templateColumns, out int ret);
Ejemplo n.º 30
0
 public static extern NativeMethods.ErrorType matrix_op_op_jet_nr_matrix(NativeMethods.MatrixElementType type, IntPtr img, int templateRows, int templateColumns, out int ret);