Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More type deductions for matrix multiplication #66

Open
dirkschumacher opened this issue Aug 14, 2019 · 2 comments
Open

More type deductions for matrix multiplication #66

dirkschumacher opened this issue Aug 14, 2019 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@dirkschumacher
Copy link
Owner

dirkschumacher commented Aug 14, 2019

mat %*% colvec = colvec
rowvec %*% mat = rowvec
mat %*% mat = mat
T %*% <scalar> = T
<scalar> %*% T = T

@dirkschumacher
Copy link
Owner Author

The relevant code is here:

armacmp/R/ast-classes.R

Lines 830 to 858 in 5777a3f

get_cpp_type = function() {
arma_type <- find_arma_cpp_types(self$get_tail_elements())
arma_cpp_types <- vapply(arma_type, function(x) x$get_cpp_type(), character(1L))
if (length(arma_type) == 2L) {
is_integer_arma_type <- function(type) {
grepl("^arma::i", type)
}
is_unsigned_integer_arma_type <- function(type) {
grepl("^arma::u", type)
}
is_double_arma_type <- function(type) {
type %in% paste0("arma::", c("vec", "colvec", "rowvec", "mat"))
}
# TODO: revisit these rules and contemplate
if (any(sapply(arma_cpp_types, is_double_arma_type))) {
return("arma::mat")
}
if (any(sapply(arma_cpp_types, is_integer_arma_type))) {
return("arma::imat")
}
if (all(sapply(arma_cpp_types, is_unsigned_integer_arma_type))) {
return("arma::umat")
}
}
if (length(arma_type) == 1L) {
return(arma_type[[1L]]$get_cpp_type())
}
"arma::mat"
}

@dirkschumacher dirkschumacher added the good first issue Good for newcomers label Aug 15, 2019
@dirkschumacher
Copy link
Owner Author

There is also a lot of room for refactoring and making this stuff smarter :)

@dirkschumacher dirkschumacher changed the title More type deductions More type deductions for matrix multiplication Aug 15, 2019
@dirkschumacher dirkschumacher added the enhancement New feature or request label Oct 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant