goldingn / gpe

Gaussian process everything - an R package to reimplement and combine common statistical models using GPs
MIT License
26 stars 5 forks source link

overloaded %x% operator #30

Closed goldingn closed 8 years ago

goldingn commented 8 years ago

Loading the package in a fresh environment currently yields:

> library(gpe)
Attaching package: ‘gpe’

The following object is masked from ‘package:base’:

    %x%

which is ugly.

This is because the Kronecker operator %x% is overwritten in gpe and reverts to the base version if the object is not a gpe kernel object. gpe also uses the function kron() for it's kernel kronecker operator, rather than the generic kronecker()

There must be a better way of overloading kronecker() than this!

Since %x% is defined as:

function (X, Y) kronecker(X, Y)

overloading kronecker() should be sufficient.

goldingn commented 8 years ago

Hmmm...

There is an S4 generic methods::kronecker.

There is a non-S4 function base::kronecker which calls methods::kronecker if X and Y are S4 objects. If not, it calls .kronecker (also in base) which is not S4....

%x% is base, so calls base::kronecker which calls .kronecker. So we can't just overload the S4 generic methods::kronecker, we need to deal with %x% too.

It would be great to overload the S3 %x% for our kernel class (to call methods::kronecker, or just skip straight to the real code), but it seems that %?% operators can't be overloaded.

Gnnnh.

goldingn commented 8 years ago

It looks like it is not possible to provide a working implementation of the %x% operator, without the startup message. However kron can be replaced with kronecker , as implemented in https://github.com/goldingn/gpe/commit/5c6655a034b21adce35bd7bdf83b9402a8824f98. Closing the rest of this issue now as it seems to be a limitation in R as currently implemented

goldingn commented 8 years ago

Adding a method for the S4 generic kronecker ruined the docs, because this: http://stackoverflow.com/questions/18604549/documenting-and-exporting-an-s4-generic-method-that-already-exists-in-base

So it's archived in the kronecker_bullshit branch and I reverted back to using the separate kron.

That was a fun afternoon.