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

Add error checkers 529 #645

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/as_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ as_data <- function(x) {
as_data.greta_array <- function(x) {
# nolint end
non_data_greta_array <- !is.data_node(get_node(x))
## TODO checker-fun check for similar error messages
if (non_data_greta_array) {
cli::cli_abort(
"cannot coerce a non-data greta_array to data"
Expand Down
7 changes: 7 additions & 0 deletions R/checkers.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ check_tf_version <- function(alert = c("none",


# check dimensions of arguments to ops, and return the maximum dimension
## TODO checker-fun
## this should not return max dimension, that should be a separate
## function. This function should only error if dimensions are not appropriate
check_dims <- function(..., target_dim = NULL) {

# coerce args to greta arrays
Expand Down Expand Up @@ -173,6 +176,8 @@ check_dims <- function(..., target_dim = NULL) {
output_dim
}

## TODO checker-fun
## This is specific to multivariate distributions?
# make sure a greta array is 2D
check_2d <- function(x) {
if (!is_2d(x)) {
Expand All @@ -187,6 +192,7 @@ check_2d <- function(x) {
}
}

## TODO checker-fun
check_square <- function(x) {
dim <- dim(x)
ndim <- length(dim)
Expand All @@ -202,6 +208,7 @@ check_square <- function(x) {
}
}

## TODO checker-fun
check_sigma_square_2d_greta_array <- function(sigma){
# check dimensions of Sigma
not_square <- nrow(sigma) != ncol(sigma)
Expand Down
2 changes: 2 additions & 0 deletions R/operators.R
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ NULL

# check the dimensions match
incompatible_dimensions <- dim(x)[2] != dim(y)[1]
## TODO checker-fun
## check function for incompatible dims
if (incompatible_dimensions) {
cli::cli_abort(
c(
Expand Down
2 changes: 2 additions & 0 deletions R/probability_distributions.R
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,8 @@ lkj_correlation_distribution <- R6Class(
eta <- as.greta_array(eta)

if (!is_scalar(eta)) {
## TODO checker-fun
## Add check for scalar
cli::cli_abort(
c(
"{.arg eta} must be a scalar",
Expand Down
6 changes: 6 additions & 0 deletions R/variable.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ cholesky_variable <- function(dim, correlation = FALSE) {
} else if (n_dim == 2) {
not_square <- dim[1] != dim[2]
if (not_square) {
## TODO checker-fun
## replace with check_square?
msg <- cli::cli_abort(
c(
"cholesky variables must be square",
Expand All @@ -87,6 +89,8 @@ cholesky_variable <- function(dim, correlation = FALSE) {
)
}
} else {
## TODO checker-fun
## replace with check scalar?
msg <- cli::cli_abort(
c(
"{.arg dim} can either be a scalar or a vector of length 2",
Expand Down Expand Up @@ -196,6 +200,8 @@ ordered_variable <- function(dim) {
last_dim <- dim[n_dim]

if (!last_dim > 1) {
## TODO checker-fun
## Very similar error message above - can these be combined?
cli::cli_abort(
"the final dimension of an ordered variable must have more than \\
one element",
Expand Down
Loading