elementwise operations for (eg sin, cos, abs, conj).
I am trying to implement most of these in terms of standard library
functions. Unfortunately, not all functions in the standard library are
constructed the same (eg some are template functions, some use
pass-by-value where others use pass by reference). To get around this,
I have tried to come up with an adaptor function. The main routine
looks like this:
template <typename T, typename S, S Func(T)>
Tensor<S> ElementwiseTens orOp( const Tensor<T> &subject ) {
Tensor<S> newTensor(subje ct.dimensions() );
size_t n = subject.size();
S *newData = newTensor.data( );
T *subjectData = subject.data();
for ( size_t i = 0; i < n; ++i ) newData[i] = Func(subjectDat a[i]);
}
I have written an adaptor function that converts pass by reference
functions to pass by value, like this:
template <typename T, typename S, S Func(const T&)>
S ArgTypeAdaptor( T arg) {
return Func(arg);
}
Now I try to use this in my Tensor functions, like so:
template <typename T>
Tensor<complex< T> > conj( const Tensor<complex< T> > &v ) {
return
ElementwiseTens orOp<
complex<T>,
complex<T>,
ArgTypeAdaptor< complex<T>, complex<T>, std::conj<T> >
( v );
}
This gives me the following error, which I don't understand:
error: no matching function for call to 'ElementwiseTen sorOp(const
Periphery::Tens or<std::complex <double> >&)'
I am using gcc 4.0 on Mac OS X. Can anyone explain this to me? Is there
a better way to handle the argument type discrepancies than what I am
doing (eg STL adaptors)?
Drew McCormack