temporary types

Feedback, comments, and suggestions regarding the library design.

temporary types

Postby arondight » Fri Feb 24, 2012 3:48 pm

I am new to expression templates so forgive my ignorance, but

in quaternion.h

Why is the imaginary type based on the temporary type and not on the vector type?

Why:
typedef typename vector_temporary::subvector_type imaginary_type;

Instead of
typedef typename vector_type::subvector_type imaginary_type;

?
arondight
 
Posts: 5
Joined: Tue Feb 21, 2012 10:59 am

Postby Jesse Anders » Fri Feb 24, 2012 7:49 pm

I had to look at the code a bit to refresh my memory, but it looks like the discrete 'temporary' type is there in support of the 'external' storage policy.

The quaternion class template can use either the 'fixed' or 'external' storage policy (a quaternion with dynamic storage wouldn't make any sense and so is not supported). Returning a temporary vector that shared storage with an 'external' quaternion would raise some technical and semantic issues, so in the case of the 'external' storage policy, fixed storage is used for temporaries instead.

If you're not using the external storage policy (which I'm guessing you're not), vector_temporary and vector_type should be the same type (in other words, there's no significance to the separate temporary type in this context).

No guarantees the above is exactly correct, but based on a quick review of the code, I'm pretty sure that's an accurate answer.
Jesse Anders
Site Admin
 
Posts: 313
Joined: Thu Jan 01, 1970 12:00 am

Re: temporary types

Postby dnave » Fri Feb 24, 2012 8:10 pm

Good question. This is mostly a future-proofing decision, since in the current implementation, quaternion<> can be created only with a fixed<> or a fixed-size external<> array type, both of which have fixed<> subvector (and temporary) types.

However, a vector type could have a subvector type that doesn't make sense as a temporary. A GPU-resident vector might be one example, since its subvector type should be a GPU-resident type, but its temporary type could arguably be a CPU-resident vector type . In the context of the quaternion<>, for example, this CPU temporary would be used to store a main-memory copy of the imaginary part of a quaternion living in GPU memory.

This example is admittedly contrived, since it would make more sense to have both a CPU and a GPU temporary, depending upon what type of operation was using the imaginary part. But, hopefully you get the point. :-)

Cheers,
Demian
dnave
 
Posts: 113
Joined: Fri Jun 29, 2007 12:46 am
Location: Pittsburgh, PA


Return to Design Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron