Re: [eigen] generic argument declaration taking a matrix, vector or expression |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] generic argument declaration taking a matrix, vector or expression
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Mon, 16 Jan 2012 07:43:49 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=yU1BAZaHIotdxcvbFZdr7MfWKVxvL2YtEMOFgnlkG10=; b=skK6ev9W4WolVRcbFBqZF+yr1wffooBdin10i7GayAuUlsKhtVvvMvIrj6ZwgjpHxZ 9RxScAG1BOkMhyogGKBcEu1tcP14jiTV5tqJ4WUcxSJzzoh0HOApoT10AmIEB+ubmyyb BE7N/MQKqm9pweSlQShKY5jkXNjQ8gwDwXpvY=
2012/1/16 Martin Senst <martin.senst@xxxxxx>:
> Am Donnerstag, 12. Januar 2012, 01:24:30 schrieb Benoit Jacob:
>> 2012/1/11 Bernhard Zeisl <bzeisl@xxxxxxxxxxxxxxxx>:
>> > Christoph, thanks a lot for your hint. That solved the problem.
>> >
>> > I agree with you that with the new declaration we lost type safety.
>> > Effectively A, b and x now can be of a different scalar type each.
>> > While it's fine in our case that the function is templated over different
>> > scalar types, it should be required that all arguments are of the same
>> > type. Also it would be nice if that shows up in the interface. As of
>> > now, I guess this is not possible?
>>
>> As Christoph said, the only way to enforce that is by a static
>> assertion, and that won't show up in the interface (if by interface
>> you mean prototype). "Concepts" were supposed to make that possible
>> but they got dropped from c++11, sadly.
>
>
> You could use boost::enable_if to enforce that the scalar types of the
> function parameters match. The following is C++11, but it should be possible
> to make this work in C++03, too:
Do these macros really work? I don't see how they can expand to a
valid function prototype. Anyway, C++03 is what we need to target and
there I don't think it's possible at all to implement enable_if in a
way that doesn't require modifying function prototypes, as I meant
above.
Benoit
>
> #define EIGEN_ENABLE_IF(condition) typename boost::enable_if_c< condition, int
>>::type = 0
>
> #define EIGEN_ENABLE_IF_SAME_SCALAR(T1, T2)
> EIGEN_ENABLE_IF((std::is_same<typename T1::Scalar, typename
> T2::Scalar>::value))
>
> #define EIGEN_ENABLE_IF_SAME_SCALAR3(T1, T2, T3)
> EIGEN_ENABLE_IF((std::is_same<typename T1::Scalar, typename T2::Scalar>::value
> && std::is_same<typename T1::Scalar, typename T3::Scalar>::value))
>
> template <typename T1, typename T2, typename T3,
> EIGEN_ENABLE_IF_SAME_SCALAR3(T1, T2, T3)>
> void f(Eigen::MatrixBase<T1> t1, Eigen::MatrixBase<T2> t2,
> Eigen::MatrixBase<T3> t3);
>
> Cheers,
> Martin
>
>