Ejemplo n.º 1
0
        /// <summary>
        /// Initializes this R matrix, using the values in a rectangular array.
        /// </summary>
        /// <param name="matrix"></param>
        protected override void InitMatrixFastDirect(Complex[,] matrix)
        {
            var vectorCplx = ArrayConverter.ArrayConvertOneDim(matrix);
            var data       = RTypesUtil.SerializeComplexToDouble(vectorCplx);

            Marshal.Copy(data, 0, DataPointer, data.Length);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Efficient initialisation of R vector values from an array representation in the CLR
        /// </summary>
        protected override void SetVectorDirect(Complex[] values)
        {
            double[] data    = RTypesUtil.SerializeComplexToDouble(values);
            IntPtr   pointer = IntPtr.Add(DataPointer, 0);

            Marshal.Copy(data, 0, pointer, data.Length);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets an array representation in the CLR of a vector in R.
        /// </summary>
        /// <returns></returns>
        protected override Complex[] GetArrayFast()
        {
            int n    = this.Length;
            var data = new double[2 * n];

            Marshal.Copy(DataPointer, data, 0, 2 * n);
            return(RTypesUtil.DeserializeComplexFromDouble(data));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets a rectangular array representation in the CLR, equivalent of a matrix in R.
        /// </summary>
        /// <returns>Rectangular array with values representing the content of the R matrix. Beware NA codes</returns>
        protected override Complex[,] GetArrayFast()
        {
            int n    = this.ItemCount;
            var data = new double[2 * n];

            Marshal.Copy(DataPointer, data, 0, 2 * n);
            var oneDim = RTypesUtil.DeserializeComplexFromDouble(data);

            return(ArrayConverter.ArrayConvertAllTwoDim(oneDim, this.RowCount, this.ColumnCount));
        }
Ejemplo n.º 5
0
        public void CanSerializeComplexValues()
        {
            var result = RTypesUtil.SerializeComplexToDouble(new[] { new Complex(1, 0), new Complex(0, 1), new Complex(1, 1) });

            Assert.That(result, Is.EqualTo(new[] { 1d, 0, 0, 1, 1, 1 }));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Sets the element at the specified index.
 /// </summary>
 /// <remarks>Used for R 3.5 and higher, to account for ALTREP objects</remarks>
 /// <param name="index">The zero-based index of the element to set.</param>
 /// <param name="value">The value to set</param>
 protected override void SetValueAltRep(int index, Complex value)
 {
     GetFunction <SET_COMPLEX_ELT>()(this.DangerousGetHandle(), (IntPtr)index,
                                     RTypesUtil.SerializeComplexToRComplex(value));
 }