
R version 2.13.1 (2011-07-08)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(mcmc)
> isotropic <- mcmc:::isotropic
> isotropic.logjacobian <- mcmc:::isotropic.logjacobian
> 
> # create identity test function
> identity <- function(x) x
> d.identity <- function(x) 1
> 
> # check that isotropic is length preserving for vectors of lengths 1--1000
> all(sapply(1:1000, function(x) length(isotropic(identity)(rep(1, x))) == x))
[1] TRUE
>     
> # test that isotropic(identity) is an identity function
> all.equal(isotropic(identity)(1:10), 1:10)
[1] TRUE
> x <- seq(0, 1, length.out=200)
> all.equal(isotropic(identity)(x), x)
[1] TRUE
> 
> # make sure that isotropic.logjacobian(identity, d.identity) is a 0 function
> all.equal(isotropic.logjacobian(identity, d.identity)(1:10), 0)
[1] TRUE
> 
> # make sure that 0 as an input does not cause divide-by-zero errors
> all.equal(isotropic(identity)(0), 0)
[1] TRUE
> all.equal(isotropic(identity)(0 * 1:4), rep(0, 4))
[1] TRUE
> all.equal(isotropic.logjacobian(identity, d.identity)(0), 0)
[1] TRUE
> all.equal(isotropic.logjacobian(identity, d.identity)(0 * 1:4), 0)
[1] TRUE
> 
> # try isotropic with f(x) = x^2, then we should get 
> # istropic(f)(x) := |x| * x
> f <- function(x) x^2
> all.equal(isotropic(f)(1), 1)
[1] TRUE
> all.equal(isotropic(f)(c(1, 1)), sqrt(2) * c(1, 1))
[1] TRUE
> all.equal(isotropic(f)(c(1, 0, 1)), sqrt(2) * c(1, 0, 1))
[1] TRUE
> 
> # make sure lazy-loading works properly.
> g <- function(x) x^2
> g.iso <- isotropic(g)
> g <- function(x) x
> all.equal(g.iso(2), 2*2)
[1] TRUE
> 
