Skip to content

Commit 26e75b2

Browse files
committed
fix lambda signature participating in composite signature type resolution...
1 parent d7b5a79 commit 26e75b2

File tree

4 files changed

+32
-20
lines changed

4 files changed

+32
-20
lines changed

examples/misc/quick_test.inl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,19 @@ int main(int argv, char** argc)
140140
std::cout << Total( hydra::make_tuple( _x(1.0), _y(-1.0), _v(1.0), _u(-1.0))) << std::endl;
141141

142142

143+
auto myfunc = hydra::wrap_lambda( [] __hydra_dual__ (unsigned int npar, const hydra::Parameter* params, _x x, _y y) {
144+
145+
return x + params[0]*y;
146+
147+
}, exponent);
148+
149+
auto mycombination = Gx + myfunc * Gy;
150+
151+
std::cout << "mycombination: " << mycombination(_x(-1.0), _y(1.0)) << std::endl;
152+
143153
//What is the type of the natural signature of Total?
144154
//uncomment this
145-
//typename decltype(Total)::argument_type test{};
155+
// typename decltype(mycombination)::argument_type test{};
146156
//std::cout << test.dummy << '\n';
147157

148158
return 0;

hydra/Lambda.h

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,16 @@ template<typename LambdaType, size_t NPARAM>
302302
class Lambda : public detail::Parameters<NPARAM>
303303
{
304304

305-
typedef typename detail::lambda_traits<LambdaType>::argument_rvalue_type argument_rvalue_type;
305+
typedef typename detail::trimmed_lambda_signature<typename detail::lambda_traits<LambdaType>::argument_rvalue_type>::type argument_rvalue_type;
306306

307307
public:
308308

309309
typedef void hydra_lambda_type;
310310

311311
typedef typename detail::lambda_traits<LambdaType>::return_type return_type;
312-
typedef typename detail::lambda_traits<LambdaType>::argument_type argument_type;
312+
typedef typename detail::trimmed_lambda_signature<typename detail::lambda_traits<LambdaType>::argument_type>::type argument_type;
313313

314-
enum {arity=detail::lambda_traits<LambdaType>::arity};
314+
enum {arity=detail::lambda_traits<LambdaType>::arity-2};
315315

316316

317317
explicit Lambda()=delete;
@@ -391,8 +391,7 @@ class Lambda : public detail::Parameters<NPARAM>
391391
template<typename ...T>
392392
__hydra_host__ __hydra_device__
393393
inline typename std::enable_if<
394-
(!detail::is_valid_type_pack<argument_type, size_t,
395-
const hydra::Parameter*, T...>::value),
394+
(!detail::is_valid_type_pack<argument_type, T...>::value),
396395
return_type>::type
397396
operator()(T...x) const
398397
{
@@ -413,8 +412,7 @@ class Lambda : public detail::Parameters<NPARAM>
413412
template<typename ...T>
414413
__hydra_host__ __hydra_device__
415414
inline typename std::enable_if<
416-
(detail::is_valid_type_pack<argument_type, size_t,
417-
const hydra::Parameter*, T...>::value),
415+
(detail::is_valid_type_pack<argument_type, T...>::value),
418416
return_type>::type
419417
operator()(T...x) const
420418
{
@@ -426,13 +424,7 @@ class Lambda : public detail::Parameters<NPARAM>
426424
inline typename std::enable_if<
427425
( detail::is_tuple_type< typename std::decay<T>::type >::value ) &&
428426
(!detail::is_tuple_of_function_arguments< typename std::decay<T>::type >::value) &&
429-
( std::is_convertible<
430-
typename detail::tuple_cat_type<
431-
hydra::tuple<size_t, const Parameter*>,
432-
typename std::decay<T>::type
433-
>::type,
434-
argument_rvalue_type
435-
>::value ),
427+
( std::is_convertible<typename std::decay<T>::type, argument_rvalue_type>::value ),
436428
return_type >::type
437429
operator()( T x ) const
438430
{
@@ -500,30 +492,30 @@ class Lambda : public detail::Parameters<NPARAM>
500492

501493
return fLambda(this->GetNumberOfParameters(), this->GetParameters(),
502494
detail::get_tuple_element<
503-
typename hydra_thrust::tuple_element<I+2,argument_rvalue_type>::type >(x)...);
495+
typename hydra_thrust::tuple_element<I,argument_rvalue_type>::type >(x)...);
504496
}
505497

506498
template<typename T>
507499
__hydra_host__ __hydra_device__
508500
inline return_type call(T x) const
509501
{
510-
return call_helper(x, detail::make_index_sequence<arity-2>{});
502+
return call_helper(x, detail::make_index_sequence<arity>{});
511503
}
512504

513505
template<typename T, size_t ...I>
514506
__hydra_host__ __hydra_device__
515507
inline return_type raw_call_helper(T x, detail::index_sequence<I...> ) const
516508
{
517509
return fLambda(this->GetNumberOfParameters(), this->GetParameters(),
518-
static_cast<typename hydra_thrust::tuple_element<I+2,argument_rvalue_type>::type>(
510+
static_cast<typename hydra_thrust::tuple_element<I,argument_rvalue_type>::type>(
519511
hydra_thrust::get<I>(x))...);
520512
}
521513

522514
template<typename T>
523515
__hydra_host__ __hydra_device__
524516
inline return_type raw_call(T x) const
525517
{
526-
return raw_call_helper(x, detail::make_index_sequence<arity-2>{});
518+
return raw_call_helper(x, detail::make_index_sequence<arity>{});
527519
}
528520

529521

hydra/detail/FunctorTraits.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ struct functor_traits<ReturnType(ClassType::*)(Args...) const>
101101

102102
};
103103

104+
template<typename T>
105+
struct trimmed_lambda_signature;
106+
107+
template<typename Head, typename Neck, typename ...Tail>
108+
struct trimmed_lambda_signature< hydra_thrust::tuple<Head,Neck, Tail...> >
109+
{
110+
typedef hydra_thrust::tuple<Tail...> type;
111+
};
112+
113+
104114
template<typename Functor, typename T= hydra_thrust::void_t<> >
105115
struct is_hydra_functor:std::false_type{};
106116

hydra/detail/utility/MSB.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ msb( Integer x){
7373

7474
#else
7575

76-
Integer _x
76+
Integer _x;
7777
unsigned y;
7878
int n = 64;
7979

0 commit comments

Comments
 (0)