Skip to content

Commit

Permalink
Schur
Browse files Browse the repository at this point in the history
  • Loading branch information
stla committed Mar 7, 2024
1 parent e3d329f commit c449952
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 50 deletions.
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
Package: EigenR
Type: Package
Title: Complex Matrix Algebra with 'Eigen'
Version: 1.2.3
Version: 1.2.3.9000
Author: Stéphane Laurent
Maintainer: Stéphane Laurent <laurent_step@outlook.fr>
Description: Matrix algebra using the 'Eigen' C++ library: determinant, rank, inverse, pseudo-inverse, kernel and image, QR decomposition, Cholesky decomposition, linear least-squares problems. Also provides matrix functions such as exponential, logarithm, power, sine and cosine. Complex matrices are supported.
License: GPL-3
Imports: Rcpp (>= 1.0.5)
LinkingTo: Rcpp, RcppEigen
RoxygenNote: 7.1.2
LinkingTo: Rcpp, RcppEigen (>= 0.3.4.0.0)
RoxygenNote: 7.3.1
Encoding: UTF-8
URL: https://github.com/stla/EigenR
BugReports: https://github.com/stla/EigenR/issues
SystemRequirements: C++ 17
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export(Eigen_QR)
export(Eigen_UtDU)
export(Eigen_absdet)
export(Eigen_chol)
export(Eigen_complexSchur)
export(Eigen_cos)
export(Eigen_cosh)
export(Eigen_det)
Expand All @@ -22,6 +23,8 @@ export(Eigen_pinverse)
export(Eigen_pow)
export(Eigen_range)
export(Eigen_rank)
export(Eigen_realQZ)
export(Eigen_realSchur)
export(Eigen_sin)
export(Eigen_sinh)
export(Eigen_sqrt)
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# EigenR 1.3.0

New features: Schur decomposition, QZ decomposition (only for real matrices).


# EigenR 1.2.3

Fixed a mistake in `Eigen_UtDU`.


# EigenR 1.2.2

No change for the user.
Expand Down
9 changes: 9 additions & 0 deletions R/EigenR.R
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ Eigen_sqrt <- function(M){
#'
#' @return A list with the \code{Q}, \code{Z}, \code{S} and \code{T} matrices.
#' @export
#' @details See \href{https://eigen.tuxfamily.org/dox/classEigen_1_1RealQZ.html}{Eigen::RealQZ}.
#'
#' @examples
#' library(EigenR)
Expand Down Expand Up @@ -713,11 +714,15 @@ Eigen_realQZ <- function(A, B) {
#'
#' @return A list with the \code{T} and \code{U} matrices.
#' @export
#' @details See \href{https://eigen.tuxfamily.org/dox/classEigen_1_1RealSchur.html}{Eigen::RealSchur}.
#'
#' @examples
#' library(EigenR)
#' M <- cbind(c(3, 2, 3), c(1, 1, 1), c(5, 0, -2))
#' schur <- Eigen_realSchur(M)
#' T <- schur$T
#' U <- schur$U
#' M - U %*% T %*% t(U)
Eigen_realSchur <- function(M) {
stopifnot(isSquareMatrix(M), isReal(M))
EigenR_realSchur(M)
Expand All @@ -731,11 +736,15 @@ Eigen_realSchur <- function(M) {
#'
#' @return A list with the \code{T} and \code{U} matrices.
#' @export
#' @details See \href{https://eigen.tuxfamily.org/dox/classEigen_1_1ComplexSchur.html}{Eigen::ComplexSchur}.
#'
#' @examples
#' library(EigenR)
#' M <- cbind(c(3, 2i, 1+3i), c(1, 1i, 1), c(5, 0, -2i))
#' schur <- Eigen_complexSchur(M)
#' T <- schur$T
#' U <- schur$U
#' M - U %*% T %*% t(Conj(U))
Eigen_complexSchur <- function(M) {
stopifnot(isSquareMatrix(M), isRealOrComplex(M))
schur <- EigenR_complexSchur(Re(M), Im(M))
Expand Down
12 changes: 12 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,18 @@ EigenR_rank_cplx <- function(Re, Im) {
.Call('_EigenR_EigenR_rank_cplx', PACKAGE = 'EigenR', Re, Im)
}

EigenR_realQZ <- function(A, B) {
.Call('_EigenR_EigenR_realQZ', PACKAGE = 'EigenR', A, B)
}

EigenR_realSchur <- function(M) {
.Call('_EigenR_EigenR_realSchur', PACKAGE = 'EigenR', M)
}

EigenR_complexSchur <- function(Re, Im) {
.Call('_EigenR_EigenR_complexSchur', PACKAGE = 'EigenR', Re, Im)
}

EigenR_isInjective_real <- function(M) {
.Call('_EigenR_EigenR_isInjective_real', PACKAGE = 'EigenR', M)
}
Expand Down
41 changes: 0 additions & 41 deletions inst/RealSchur.cpp

This file was deleted.

28 changes: 28 additions & 0 deletions man/Eigen_complexSchur.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions man/Eigen_realQZ.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions man/Eigen_realSchur.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

## With R 3.1.0 or later, you can uncomment the following line to tell R to
## enable compilation with C++11 (or even C++14) where available
CXX_STD = CXX11
CXX_STD = CXX17
2 changes: 1 addition & 1 deletion src/Makevars.win
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

## With R 3.1.0 or later, you can uncomment the following line to tell R to
## enable compilation with C++11 (or even C++14) where available
CXX_STD = CXX11
CXX_STD = CXX17
38 changes: 38 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,41 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// EigenR_realQZ
Rcpp::List EigenR_realQZ(const Eigen::MatrixXd& A, const Eigen::MatrixXd& B);
RcppExport SEXP _EigenR_EigenR_realQZ(SEXP ASEXP, SEXP BSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type A(ASEXP);
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type B(BSEXP);
rcpp_result_gen = Rcpp::wrap(EigenR_realQZ(A, B));
return rcpp_result_gen;
END_RCPP
}
// EigenR_realSchur
Rcpp::List EigenR_realSchur(const Eigen::MatrixXd& M);
RcppExport SEXP _EigenR_EigenR_realSchur(SEXP MSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type M(MSEXP);
rcpp_result_gen = Rcpp::wrap(EigenR_realSchur(M));
return rcpp_result_gen;
END_RCPP
}
// EigenR_complexSchur
Rcpp::List EigenR_complexSchur(const Eigen::MatrixXd& Re, const Eigen::MatrixXd& Im);
RcppExport SEXP _EigenR_EigenR_complexSchur(SEXP ReSEXP, SEXP ImSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type Re(ReSEXP);
Rcpp::traits::input_parameter< const Eigen::MatrixXd& >::type Im(ImSEXP);
rcpp_result_gen = Rcpp::wrap(EigenR_complexSchur(Re, Im));
return rcpp_result_gen;
END_RCPP
}
// EigenR_isInjective_real
bool EigenR_isInjective_real(const Eigen::MatrixXd& M);
RcppExport SEXP _EigenR_EigenR_isInjective_real(SEXP MSEXP) {
Expand Down Expand Up @@ -753,6 +788,9 @@ static const R_CallMethodDef CallEntries[] = {
{"_EigenR_EigenR_QR_cplx", (DL_FUNC) &_EigenR_EigenR_QR_cplx, 2},
{"_EigenR_EigenR_rank_real", (DL_FUNC) &_EigenR_EigenR_rank_real, 1},
{"_EigenR_EigenR_rank_cplx", (DL_FUNC) &_EigenR_EigenR_rank_cplx, 2},
{"_EigenR_EigenR_realQZ", (DL_FUNC) &_EigenR_EigenR_realQZ, 2},
{"_EigenR_EigenR_realSchur", (DL_FUNC) &_EigenR_EigenR_realSchur, 1},
{"_EigenR_EigenR_complexSchur", (DL_FUNC) &_EigenR_EigenR_complexSchur, 2},
{"_EigenR_EigenR_isInjective_real", (DL_FUNC) &_EigenR_EigenR_isInjective_real, 1},
{"_EigenR_EigenR_isInjective_cplx", (DL_FUNC) &_EigenR_EigenR_isInjective_cplx, 2},
{"_EigenR_EigenR_isSurjective_real", (DL_FUNC) &_EigenR_EigenR_isSurjective_real, 1},
Expand Down
22 changes: 22 additions & 0 deletions src/Schur.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "EigenR.h"

// [[Rcpp::export]]
Rcpp::List EigenR_realSchur(const Eigen::MatrixXd& M) {
Eigen::RealSchur<Eigen::MatrixXd> schur(M);
const Eigen::MatrixXd U = schur.matrixU();
const Eigen::MatrixXd T = schur.matrixT();
return Rcpp::List::create(Rcpp::Named("T") = T,
Rcpp::Named("U") = U);
}

// [[Rcpp::export]]
Rcpp::List EigenR_complexSchur(const Eigen::MatrixXd& Re,
const Eigen::MatrixXd& Im) {
const Eigen::MatrixXcd M = matricesToMatrixXcd(Re, Im);
Eigen::ComplexSchur<Eigen::MatrixXcd> schur(M.rows());
schur.compute(M);
const Eigen::MatrixXcd U = schur.matrixU();
const Eigen::MatrixXcd T = schur.matrixT();
return Rcpp::List::create(Rcpp::Named("U") = cplxMatrixToList(U),
Rcpp::Named("T") = cplxMatrixToList(T));
}

0 comments on commit c449952

Please sign in to comment.