@@ -56,31 +56,117 @@ namespace mgis::function::algorithm {
5656
5757namespace mgis ::function::internals {
5858
59+ inline void assign_value (auto & lhs, const auto & rhs) {
60+ std::copy (rhs.begin (), rhs.end (), lhs.begin ());
61+ }
62+
63+ inline void assign_value (std::span<real> lhs, const auto & rhs) {
64+ std::copy (rhs.begin (), rhs.end (), lhs.begin ());
65+ }
66+
67+ inline void assign_value (std::span<real> lhs,
68+ const std::span<const real> rhs) {
69+ std::copy (rhs.begin (), rhs.end (), lhs.begin ());
70+ }
71+
72+ inline void assign_value (std::span<real> lhs, const std::span<real> rhs) {
73+ std::copy (rhs.begin (), rhs.end (), lhs.begin ());
74+ }
75+
76+ inline void assign_value (real& lhs, const std::span<real>& rhs) {
77+ lhs = rhs[0 ];
78+ }
79+
80+ inline void assign_value (real& lhs, const std::span<const real>& rhs) {
81+ lhs = rhs[0 ];
82+ }
83+
84+ inline void assign_value (real& lhs, const std::span<real, 1u >& rhs) {
85+ lhs = rhs[0 ];
86+ }
87+
88+ inline void assign_value (real& lhs, const std::span<const real, 1u >& rhs) {
89+ lhs = rhs[0 ];
90+ }
91+
92+ inline void assign_value (real& lhs, const std::array<real, 1u >& rhs) {
93+ lhs = rhs[0 ];
94+ }
95+
96+ inline void assign_value (std::array<real, 1u >& lhs, const real rhs) {
97+ lhs[0 ] = rhs;
98+ }
99+
100+ inline void assign_value (std::array<real, 1u >& lhs,
101+ const std::array<real, 1u > rhs) {
102+ lhs[0 ] = rhs[0 ];
103+ }
104+
105+ inline void assign_value (std::array<real, 1u >& lhs, const std::span<real> rhs) {
106+ lhs[0 ] = rhs[0 ];
107+ }
108+
109+ inline void assign_value (std::array<real, 1u >& lhs, const std::span<const real> rhs) {
110+ lhs[0 ] = rhs[0 ];
111+ }
112+
113+ inline void assign_value (std::array<real, 1u >& lhs, const std::span<real, 1u > rhs) {
114+ lhs[0 ] = rhs[0 ];
115+ }
116+
117+ inline void assign_value (std::array<real, 1u >& lhs, const std::span<const real, 1u > rhs) {
118+ lhs[0 ] = rhs[0 ];
119+ }
120+
121+ inline void assign_value (std::span<real, 1u > lhs, const real rhs) {
122+ lhs[0 ] = rhs;
123+ }
124+
125+ inline void assign_value (std::span<real> lhs, const real rhs) {
126+ lhs[0 ] = rhs;
127+ }
128+
129+ inline void assign_value (std::span<real> lhs, const std::span<real, 1u > rhs) {
130+ lhs[0 ] = rhs[0 ];
131+ }
132+
133+ inline void assign_value (std::span<real> lhs,
134+ const std::span<const real, 1u > rhs) {
135+ lhs[0 ] = rhs[0 ];
136+ }
137+
138+ inline void assign_value (std::span<real, 1u > lhs, const std::span<real> rhs) {
139+ lhs[0 ] = rhs[0 ];
140+ }
141+
142+ inline void assign_value (std::span<real, 1u > lhs,
143+ const std::span<const real> rhs) {
144+ lhs[0 ] = rhs[0 ];
145+ }
146+
147+ inline void assign_value (std::span<real, 1u > lhs,
148+ const std::span<real, 1u > rhs) {
149+ lhs[0 ] = rhs[0 ];
150+ }
151+
152+ inline void assign_value (std::span<real, 1u > lhs,
153+ const std::span<const real, 1u > rhs) {
154+ lhs[0 ] = rhs[0 ];
155+ }
156+
157+ inline void assign_value (std::span<real, 1u > lhs, const std::array<real, 1u >& rhs) {
158+ lhs[0 ] = rhs[0 ];
159+ }
160+
59161 template <typename FunctionType, EvaluatorConcept EvaluatorType>
60162 void assign_scalar_impl (FunctionType& f, EvaluatorType e) requires(
61163 (LinearElementSpaceConcept<std::decay_t <decltype (getSpace(f))>>)&&(
62164 !hasElementWorkspace<std::decay_t <decltype (getSpace(f))>>)) {
63165 using Space = std::decay_t <decltype (getSpace (f))>;
64- using value_type = std::invoke_result_t <FunctionType, size_type>;
65- using result_type = std::invoke_result_t <EvaluatorType, size_type>;
66166 const auto & space = getSpace (f);
67167 const auto ne = getSpaceSize (space);
68- if constexpr (internals::same_decay_type<result_type, real>) {
69- for (typename SpaceTraits<Space>::size_type i = 0 ; i != ne; ++i) {
70- if constexpr (internals::same_decay_type<value_type, real>) {
71- f (i) = e (i);
72- } else {
73- f (i)[0 ] = e (i);
74- }
75- }
76- } else {
77- for (typename SpaceTraits<Space>::size_type i = 0 ; i != ne; ++i) {
78- if constexpr (internals::same_decay_type<value_type, real>) {
79- f (i) = e (i)[0 ];
80- } else {
81- f (i)[0 ] = e (i)[0 ];
82- }
83- }
168+ for (typename SpaceTraits<Space>::size_type i = 0 ; i != ne; ++i) {
169+ f (i) = e (i);
84170 }
85171 } // end of assign_scalar_impl
86172
@@ -89,28 +175,11 @@ namespace mgis::function::internals {
89175 (LinearElementSpaceConcept<std::decay_t <decltype (getSpace(f))>>)&&(
90176 hasElementWorkspace<std::decay_t <decltype (getSpace(f))>>)) {
91177 using Space = std::decay_t <decltype (getSpace (f))>;
92- using value_type = std::invoke_result_t <FunctionType, size_type>;
93- using result_type = std::invoke_result_t <EvaluatorType, size_type>;
94178 const auto & space = getSpace (f);
95179 const auto ne = getSpaceSize (space);
96- if constexpr (internals::same_decay_type<result_type, real>) {
97- for (typename SpaceTraits<Space>::size_type i = 0 ; i != ne; ++i) {
98- const auto & wk = getElementWorkspace (space, i);
99- if constexpr (internals::same_decay_type<value_type, real>) {
100- f (wk, i) = e (wk, i);
101- } else {
102- f (wk, i)[0 ] = e (wk, i);
103- }
104- }
105- } else {
106- for (typename SpaceTraits<Space>::size_type i = 0 ; i != ne; ++i) {
107- const auto & wk = getElementWorkspace (space, i);
108- if constexpr (internals::same_decay_type<value_type, real>) {
109- f (wk, i) = e (wk, i)[0 ];
110- } else {
111- f (wk, i)[0 ] = e (wk, i)[0 ];
112- }
113- }
180+ for (typename SpaceTraits<Space>::size_type i = 0 ; i != ne; ++i) {
181+ const auto & wk = getElementWorkspace (space, i);
182+ f (wk, i) = e (wk, i);
114183 }
115184 } // end of assign_scalar_impl
116185
@@ -131,9 +200,7 @@ namespace mgis::function::internals {
131200 if constexpr (use_direct_assignement) {
132201 f (i) = e (i);
133202 } else {
134- auto lhs_values = f (i);
135- const auto & rhs_values = e (i);
136- std::copy (rhs_values.begin (), rhs_values.end (), lhs_values.begin ());
203+ assign_value (f (i), e (i));
137204 }
138205 }
139206 } // end of assign_impl
@@ -156,9 +223,7 @@ namespace mgis::function::internals {
156223 if constexpr (use_direct_assignement) {
157224 f (wk, i) = e (wk, i);
158225 } else {
159- auto lhs_values = f (wk, i);
160- const auto & rhs_values = e (wk, i);
161- std::copy (rhs_values.begin (), rhs_values.end (), lhs_values.begin ());
226+ assign_value (f (wk, i), e (wk, i));
162227 }
163228 }
164229 } // end of assign_impl
@@ -178,7 +243,8 @@ namespace mgis::function {
178243 internals::same_decay_type<
179244 decltype(getSpace(std::declval<FunctionType>())),
180245 decltype(getSpace(std::declval<EvaluatorType>()))>) {
181- using result_type = std::invoke_result_t <EvaluatorType, size_type>;
246+ using function_result_type = function_result<FunctionType>;
247+ using evaluator_result_type = evaluator_result<EvaluatorType>;
182248 if (!areEquivalent (getSpace (f), getSpace (e))) {
183249 return ctx.registerErrorMessage (" unmatched spaces" );
184250 }
@@ -190,13 +256,11 @@ namespace mgis::function {
190256 return false ;
191257 }
192258 e.allocateWorkspace ();
193- if (f.getNumberOfComponents () == 1 ) {
259+ if constexpr ((internals::same_decay_type<function_result_type, real>)&& //
260+ (internals::same_decay_type<evaluator_result_type, real>)) {
194261 internals::assign_scalar_impl (f, e);
195262 } else {
196- // this "if constexpr" is used to avoid the compilation of the body
197- if constexpr (!internals::same_decay_type<result_type, real>) {
198- internals::assign_impl (f, e);
199- }
263+ internals::assign_impl (f, e);
200264 }
201265 return true ;
202266 } // end of assign
0 commit comments