Multiple Tuple IFTI Syntactic Sugar

dsimcha dsimcha at yahoo.com
Tue Feb 3 06:58:14 PST 2009


== Quote from Christopher Wright (dhasenan at gmail.com)'s article
> dsimcha wrote:
> > I've been thinking about how IFTI works for variadic function templates.  I
> > use variadic functions heavily in the infotheory module of dstats, and am
> > looking to add some features here.  Currently, my mutual information function
> > looks like:
> >
> > real mutualInfo(T, U)(T[] x, U[] y);
> >
> > I'd like to generalize this so that both x and y can be any number of vectors,
> > yielding in standard mathematical notation, something like I(x, y; z, a),
> > which is the mutual information of (x, y) as a joint distribution with (z, a)
> > as a joint distribution.  However, trying to turn this into D code with decent
> > notation leads to some headaches:
> >
> > real mutualInfo(T..., U...)(T x, U y);
> How do you instantiate that?
> mutualInfo!(TypeTuple!(T1, T2, T3), TypeTuple!(T4, T5, T6))?
> No, the tuples would be flattened.
> Bearophile's suggestion can be implemented something like:
> struct MutualInfo(T...)
> {
> 	T x;
> 	auto opCall(U...)(U y) {}
> }
> MutualInfo!(T...) mutualInfo(T...)(T args)
> {
> 	// etc
> }

I guess the bottom line is that, yes, this is too much of a niche feature.  Oh
well.  Maybe when I have lot of free time I'll write a little compile time
interpreter that takes arbitrary info theory expressions as a string, rewrites
them in terms of joint entropies, combines terms, cancels stuff out, etc.  This
could lead to some interesting speedups when calculating complicated information
theory expressions where there are some hidden simplifications available.  I have
something like this already, except AFAIK it only works at runtime.



More information about the Digitalmars-d mailing list