Skip to content

Instantly share code, notes, and snippets.

@goldingn
Created March 25, 2017 02:39
Show Gist options
  • Save goldingn/5730efe0a4f49760375c71a99b7c933f to your computer and use it in GitHub Desktop.
Save goldingn/5730efe0a4f49760375c71a99b7c933f to your computer and use it in GitHub Desktop.
# coerce to greta_array class
as.greta_array <- function(x, ...) {
UseMethod('as.greta_array')
}
# node method (only one defined)
as.greta_array.node <- function (x, ...) {
ga <- list(node = x)
class(ga) <- 'greta_array'
ga
}
# short hand ffor use in functions
ga <- function (x) as.greta_array(x)
print.greta_array <- function (x, ...) {
text <- sprintf('greta array (%s)\n\n',
x$node$type)
cat(text)
print(x$node$value(), ...)
}
dim.greta_array <- function(x) x$node$dim
dim(x)
# need to change generics to act on greta_array S3 class, and change op to a
# function that takes greta_arrays, gets their nodes, creates an operation node,
# and wraps it in a greta_array object
# change all distribution etc. constructors to wrap in greta_array class too,
# e.g.:
beta <- function (shape1, shape2, dim = 1)
ga(greta:::beta_distribution$new(shape1, shape2, dim))
b <- beta(3, 2)
b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment