Rcpp_matrix_vect_substract

C++ Function Reference

1 Signature

Rcpp::RObject BigDataStatMeth::Rcpp_matrix_vect_substract(T A, U B)

2 Description

Matrix-vector subtraction.

3 Parameters

  • A (T): Input matrix
  • B (U): Input vector (subtracted from A)

4 Returns

Result of matrix-vector subtraction

5 Details

Subtracts a vector from each row or column of a matrix.

6 Source Code

File: inst/include/memAlgebra/memSubstract.hppLines 181-210

inline Rcpp::RObject Rcpp_matrix_vect_substract ( T  A, U  B)
    {
        
        Rcpp::NumericMatrix m = Rcpp::as<Rcpp::NumericMatrix>(A);
        Rcpp::NumericVector v = Rcpp::as<Rcpp::NumericVector>(B);
        
        if( v.length() == m.rows()) {
            
            Rcpp::NumericMatrix C = Rcpp::no_init( m.rows(), m.cols());
            
            for( int i=0; i<m.cols(); i++) {
                C( Rcpp::_, i) = m( Rcpp::_, i) - v;  
            }    
            return(C);
            
        } else if( v.length() == m.cols()) {
            
            Rcpp::NumericMatrix C = Rcpp::no_init( m.rows(), m.cols());
            
            for( int i=0; i<m.rows(); i++) {
                C( i, Rcpp::_) = m( i, Rcpp::_) - v;  
            }    
            return(C);
            
        } else {
            Rcpp::Rcout<<"Error: non-conformable arguments";
        }
        
        return(R_NilValue);
    }

7 Usage Example

#include "BigDataStatMeth.hpp"

// Example usage
auto result = Rcpp_matrix_vect_substract(...);