Skip to content

Commit

Permalink
sum( ) > 0 -> any( )
Browse files Browse the repository at this point in the history
  • Loading branch information
Banana1530 committed Jun 24, 2019
1 parent 781db8a commit efcf3cb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/moma_svd.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ moma_svd <- function(
all_para <- c(alpha_u, alpha_v, lambda_u, lambda_v)

# verify all alphas and lambdas are positive numbers
if (sum(all_para < 0) > 0 || sum(!is.finite(all_para)) > 0) {
if (any(all_para < 0) || any(!is.finite(all_para))) {
moma_error(
"All penalty levels (",
sQuote("lambda_u"), ", ",
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test_arguments.R
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ test_that("Negative penalty", {
fixed = TRUE
)

# Prompt error when penalty contains Infty
expect_error(moma_svd(X = X, lambda_v = c(1:3, Inf)),
paste0(
"All penalty levels (",
sQuote("lambda_u"), ", ",
sQuote("lambda_v"), ", ",
sQuote("alpha_u"), ", ",
sQuote("alpha_v"), ") must be non-negative numeric."
),
fixed = TRUE
)

# Prompt error when passing a matrix
expect_error(moma_svd(X = X, lambda_v = matrix(1:12, 3)),
Expand Down

0 comments on commit efcf3cb

Please sign in to comment.