Example #1
0
 /// <summary>
 /// Performs the following operation for 0 &lt;= i &lt; this.<see cref="Length"/>:
 /// result[i] = <paramref name="scalar"/> * this[i].
 /// The resulting vector is written to a new <see cref="Vector"/> and then returned.
 /// </summary>
 /// <param name="scalar">The scalar value that multiplies all entries of the vector.</param>
 public Vector Scale(double scalar)
 {
     //TODO: Perhaps this should be done using mkl_malloc and BLAS copy.
     double[] result = new double[data.Length];
     Array.Copy(data, result, data.Length);
     Blas.Dscal(Length, scalar, result, 0, 1);
     return(new Vector(result));
 }
Example #2
0
        /// <summary>
        /// Performs the following operation for the non-zero entries (i, j), such that 0 &lt;= i &lt; <see cref="NumRows"/>,
        /// 0 &lt;= j &lt; <see cref="NumColumns"/>: result[i, j] = <paramref name="scalar"/> * this[i, j].
        /// The resulting matrix is written to a new <see cref="CscMatrix"/> and then returned.
        /// </summary>
        /// <param name="scalar">A scalar that multiplies each entry of this matrix.</param>
        public CscMatrix Scale(double scalar)
        {
            int nnz = this.values.Length;

            double[] resultValues = new double[nnz];
            Array.Copy(this.values, resultValues, nnz); //TODO: perhaps I should also copy the indexers
            Blas.Dscal(nnz, scalar, resultValues, 0, 1);
            return(new CscMatrix(this.NumRows, this.NumColumns, resultValues, this.rowIndices, this.colOffsets));
        }
Example #3
0
        /// <summary>
        /// Performs the following operation for 0 &lt;= i &lt; this.<see cref="Length"/>:
        /// result[i] = <paramref name="scalar"/> * this[i].
        /// The resulting vector is written to a new <see cref="SparseVector"/> and then returned.
        /// </summary>
        /// <param name="scalar">The scalar value that multiplies all entries of the vector.</param>
        public SparseVector Scale(double scalar)
        {
            int nnz = this.values.Length;

            double[] resultValues = new double[nnz];
            Array.Copy(this.values, resultValues, nnz);
            Blas.Dscal(nnz, scalar, resultValues, 0, 1);
            return(new SparseVector(Length, resultValues, this.indices)); //TODO: perhaps I should also copy the indices
        }
Example #4
0
        // markov operation
        public void DoBackward(double t, double[] x, int right, double[] prob)
        {
            //int right;
            //if (t > maxt)
            //{
            //	right = setMaxT(t);
            //}
            //else
            //{
            //	right = PoiDist.getRightBound(lambda * t, epsi);
            //}
            double weight = PoiDist.CompProb(Lambda * t, 0, right, prob);

            Blas.Dcopy(ndim, x, xi);
            Blas.Fill(ndim, x, 0.0);
            Blas.Daxpy(ndim, prob[0], xi, x);
            for (int l = 1; l <= right; l++)
            {
                Blas.Dcopy(ndim, xi, tmp);
                DgemvNoTrans(1.0, tmp, 0.0, xi);
                Blas.Daxpy(ndim, prob[l], xi, x);
            }
            Blas.Dscal(ndim, 1.0 / weight, x);
        }
Example #5
0
        public void DoSojournForward(double t, double[] f, double[] b, double[] h, int right, double[] prob, double[][] vc)
        {
            //int right;
            //if (t > maxt)
            //{
            //	right = setMaxT(t);
            //}
            //else
            //{
            //	right = PoiDist.getRightBound(lambda * t, epsi);
            //}
            double weight = PoiDist.CompProb(Lambda * t, 0, right + 1, prob);

            // forward and backward
            Blas.Fill(ndim, vc[right + 1], 0.0);
            Blas.Daxpy(ndim, prob[right + 1], b, vc[right + 1]);
            for (int l = right; l >= 1; l--)
            {
                DgemvNoTrans(1.0, vc[l + 1], 0.0, vc[l]);
                Blas.Daxpy(ndim, prob[l], b, vc[l]);
            }
            Blas.Dcopy(ndim, f, xi);
            Blas.Fill(ndim, f, 0.0);
            Blas.Daxpy(ndim, prob[0], xi, f);
            Blas.Fill(ndim * 2, h, 0.0);
            Dger(1.0, xi, vc[1], h);
            for (int l = 1; l <= right; l++)
            {
                Blas.Dcopy(ndim, xi, tmp);
                DgemvTrans(1.0, tmp, 0.0, xi);
                Blas.Daxpy(ndim, prob[l], xi, f);
                Dger(1.0, xi, vc[l + 1], h);
            }
            Blas.Dscal(ndim, 1.0 / weight, f);
            Blas.Dscal(ndim * 2, 1.0 / Lambda / weight, h);
        }
Example #6
0
 /// <summary>
 /// See <see cref="IVector.ScaleIntoThis(double)"/>.
 /// </summary>
 public void ScaleIntoThis(double scalar) => Blas.Dscal(Length, scalar, data, 0, 1);
Example #7
0
 /// <summary>
 /// See <see cref="IMatrix.ScaleIntoThis(double)"/>.
 /// </summary>
 public void ScaleIntoThis(double scalar) => Blas.Dscal(values.Length, scalar, values, 0, 1);
 /// <summary>
 /// See https://software.intel.com/en-us/mkl-developer-reference-fortran-scal#7269DCFE-7235-4690-A69E-D08712D8FC44
 /// </summary>
 public void Dscal(int n, double alpha, double[] x, int offsetX, int incX)
 => Blas.Dscal(ref n, ref alpha, ref x[offsetX], ref incX);
Example #9
0
 private void SetScaledRate()
 {
     lambda = Blas.Amax(ndim, rate) * factor;
     Blas.Dcopy(ndim, rate, scaledRate);
     Blas.Dscal(ndim, 1.0 / lambda, scaledRate);
 }