Ejemplo n.º 1
0
 /// <summary>
 /// See <see cref="IEntrywiseOperableView2D{TMatrixIn, TMatrixOut}.DoEntrywise(TMatrixIn, Func{double, double, double})"/>.
 /// </summary>
 public IMatrix DoEntrywise(IMatrixView other, Func <double, double, double> binaryOperation)
 {
     if (other is SymmetricMatrix casted)
     {
         return(DoEntrywise(casted, binaryOperation));
     }
     else
     {
         return(DenseStrategies.DoEntrywise(this, other, binaryOperation)); //TODO: optimize this
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// See <see cref="IEntrywiseOperableView2D{TMatrixIn, TMatrixOut}.DoEntrywise(TMatrixIn, Func{double, double, double})"/>.
        /// </summary>
        public IMatrix DoEntrywise(IMatrixView other, Func <double, double, double> binaryOperation)
        {
            if (other is CscMatrix otherCSC) // In case both matrices have the exact same index arrays
            {
                if (HasSameIndexer(otherCSC))
                {
                    // Do not copy the index arrays, since they are already spread around. TODO: is this a good idea?
                    double[] resultValues = new double[values.Length];
                    for (int i = 0; i < values.Length; ++i)
                    {
                        resultValues[i] = binaryOperation(this.values[i], otherCSC.values[i]);
                    }
                    return(new CscMatrix(NumRows, NumColumns, resultValues, rowIndices, colOffsets));
                }
            }

            // All entries must be processed. TODO: optimizations may be possible (e.g. only access the nnz in this matrix)
            return(DenseStrategies.DoEntrywise(this, other, binaryOperation));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// See <see cref="IEntrywiseOperableView1D{TVectorIn, TVectorOut}.DoEntrywise(TVectorIn, Func{double, double, double})"/>.
        /// </summary>
        public IVector DoEntrywise(IVectorView otherVector, Func <double, double, double> binaryOperation)
        {
            Preconditions.CheckVectorDimensions(this, otherVector);
            if (otherVector is SparseVector otherSparse) // In case both matrices have the exact same index arrays
            {
                if (HasSameIndexer(otherSparse))
                {
                    // Do not copy the index arrays, since they are already spread around. TODO: is this a good idea?
                    double[] resultValues = new double[values.Length];
                    for (int i = 0; i < values.Length; ++i)
                    {
                        resultValues[i] = binaryOperation(this.values[i], otherSparse.values[i]);
                    }
                    return(new SparseVector(Length, resultValues, indices));
                }
            }

            // All entries must be processed. TODO: optimizations may be possible (e.g. only access the nnz in this vector)
            return(DenseStrategies.DoEntrywise(this, otherVector, binaryOperation));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// See <see cref="IEntrywiseOperableView2D{TMatrixIn, TMatrixOut}.DoEntrywise(TMatrixIn, Func{double, double, double})"/>.
 /// </summary>
 public IMatrix DoEntrywise(IMatrixView matrix, Func <double, double, double> binaryOperation)
 {
     return(DenseStrategies.DoEntrywise(this, matrix, binaryOperation)); //TODO: this can be optimized.
 }
Ejemplo n.º 5
0
 /// <summary>
 /// See <see cref="IEntrywiseOperableView2D{TMatrixIn, TMatrixOut}.DoEntrywise(TMatrixIn, Func{double, double, double})"/>.
 /// </summary>
 public IMatrix DoEntrywise(IMatrixView matrix, Func <double, double, double> binaryOperation)
 {
     return(DenseStrategies.DoEntrywise(this, matrix, binaryOperation));
 }