octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [CHANGESET]: First attempt at a single precision type.


From: Jaroslav Hajek
Subject: Re: [CHANGESET]: First attempt at a single precision type.
Date: Mon, 28 Apr 2008 11:11:40 +0200

On Mon, Apr 28, 2008 at 9:04 AM, David Bateman <address@hidden> wrote:
> John W. Eaton wrote:
>  > On 27-Apr-2008, David Bateman wrote:
>  >
>  > | Basically, as this is just a copy of the double precision type I'd
>  > | always thought it would be relatively easy to add this. With that idea I
>  > | didn't attempt to make template versions of the copied code to reuse it
>  > | and just copied it as the easier fashion to get this working. Therefore,
>  > | there might be some simplifications that might be done..
>  >
>  > I'd been hoping to do this with templates and specializations.  Do you
>  > think it is worth doing that eventually?  It seems you should now have
>  > all (or most) of the specializations.
>
>  In fact most of the stuff in liboctave it probably doesn't make sense to
>  have templates as there is a lot of cases where the underlying code is
>  different (eg a call to sgetrf rather than dgetrf)..
>

still, the code duplication seems to be massive. The different Fortran
function names can be handled by overloaded wrappers. OTOH, it is
certainly desirable to have as much code compiled as possible, and
users aren't supposed to instantiate Matrix for anything other than
float and double.
Is there any possibility to put a template for a method in a .cc file,
explicitly instantiate there, and just export the explicit instances?

I'm thinking about something like this:
file RealMatrix.h:

template <typename T>
class RealMatrix
{
  bool is_symmetric(void) const;
};

template class RealMatrix<float>;
typedef RealMatrix<float> FloatMatrix;

template class RealMatrix<double>;
typedef RealMatrix<double> Matrix;

// external explicit instances ????
template void RealMatrix<float>::is_symmetric();
template void RealMatrix<double>::is_symmetric();

file RealMatrix.cc:

# include RealMatrix.h
template<typename T>
void
RealMatrix<T>:: is_symmetric(void)
{
 // code here
}


It seems not to be possible with g++. In that case, the best way to
keep maximum code precompiled is probably David's, despite the code
duplication.


>  There are probably lots of case in the oct-files that might be templated
>  but I didn't bother with. The octave-value classes themselves are
>  templated as they rely on octave_base_mat and octave_base_scalar.
>



>
>  >
>  > | I've assumed that the correct mixed double/single behavior is to promote
>  > | the single type to double,
>  >
>  > Yeah, you would think that would be the way it should work, but of
>  > course Matlab converts to single.
>
>  You're kidding.... That is just incorrect in terms of ensuring a
>  consistent precision. I assume the reason they did this is to allow
>  something like
>
>  single_arg + function_that_returns_double_for_single_arg(single_arg)
>
>  to return single. This allows some functions not to be converted to
>  handle singles and the majority of the calculation remaining in single
>  precision. If this is the case there might be a difference between the
>  treatment of operators and functions. For example, what about a mix of
>  single/double arguments to a function like  filter or betainc for
>  example, does it promote or demote the returned argument?
>
>  D.
>



-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]