Ejemplo n.º 1
0
        ///<summary>Implicit cast conversion to <c>DoubleVector</c> from <c>FloatVector</c></summary>
        public static DoubleVector ToDoubleVector(FloatVector src)
        {
            if (src == null)
            {
                return(null);
            }
            var ret = new DoubleVector(src.Length);

            Array.Copy(src.GetInternalData(), ret._array, src.Length);
            return(ret);
        }
Ejemplo n.º 2
0
        private FloatVector Pivot(IReadOnlyList <float> B)
        {
            var ret      = new FloatVector(B.Count);
            var retArray = ret.GetInternalData();

            for (int i = 0; i < pivots.Length; i++)
            {
                retArray[i] = B[pivots[i]];
            }
            return(ret);
        }
Ejemplo n.º 3
0
        ///<summary>Solves a system on linear equations, AX=B, where A is the factored matrixed.</summary>
        ///<param name="B">RHS side of the system.</param>
        ///<returns>the solution vector, X.</returns>
        ///<exception cref="ArgumentNullException">B is null.</exception>
        ///<exception cref="NotPositiveDefiniteException">A is not positive definite.</exception>
        ///<exception cref="ArgumentException">The number of rows of A and the length of B must be the same.</exception>
        public FloatVector Solve(IReadOnlyList <float> B)
        {
            if (B == null)
            {
                throw new System.ArgumentNullException("B cannot be null.");
            }
            Compute();
            if (!ispd)
            {
                throw new NotPositiveDefiniteException();
            }
            else
            {
                if (B.Count != order)
                {
                    throw new System.ArgumentException("The length of B must be the same as the order of the matrix.");
                }
#if MANAGED
                // Copy right hand side.
                var X      = new FloatVector(B);
                var xarray = X.GetInternalData();
                // Solve L*Y = B;
                for (int i = 0; i < order; i++)
                {
                    float sum = B[i];
                    for (int k = i - 1; k >= 0; k--)
                    {
                        sum -= l.data[i][k] * xarray[k];
                    }
                    xarray[i] = sum / l.data[i][i];
                }
                // Solve L'*X = Y;
                for (int i = order - 1; i >= 0; i--)
                {
                    float sum = xarray[i];
                    for (int k = i + 1; k < order; k++)
                    {
                        sum -= l.data[k][i] * xarray[k];
                    }
                    xarray[i] = sum / l.data[i][i];
                }

                return(X);
#else
                float[] rhs = FloatMatrix.ToLinearArray(B);
                Lapack.Potrs.Compute(Lapack.UpLo.Lower, order, 1, l.data, order, rhs, B.Length);
                FloatVector ret = new FloatVector(order, B.Length);
                ret.data = rhs;
                return(ret);
#endif
            }
        }
Ejemplo n.º 4
0
 public void GetInternalData()
 {
   float[] testvector = new float[2]{0,1};
   FloatVector test = new FloatVector(testvector);
   float[] internaldata = test.GetInternalData();
   
   Assert.AreEqual(internaldata.Length,testvector.Length);
   Assert.AreEqual(internaldata[0],testvector[0]);
   Assert.AreEqual(internaldata[1],testvector[1]);
 }