diff --git a/include/etr_bits/Allocation.hpp b/include/etr_bits/Allocation.hpp index e04d050..df87c05 100644 --- a/include/etr_bits/Allocation.hpp +++ b/include/etr_bits/Allocation.hpp @@ -5,6 +5,7 @@ #include "Allocation/Colon.hpp" #include "Allocation/Matrix.hpp" #include "Allocation/Rep.hpp" +#include "Allocation/ScalarForDeriv.hpp" #include "Allocation/Vector.hpp" -#endif \ No newline at end of file +#endif diff --git a/include/etr_bits/Allocation/ScalarForDeriv.hpp b/include/etr_bits/Allocation/ScalarForDeriv.hpp new file mode 100644 index 0000000..4eab175 --- /dev/null +++ b/include/etr_bits/Allocation/ScalarForDeriv.hpp @@ -0,0 +1,19 @@ +#ifndef SCALAR_DERIV_ETR_H +#define SCALAR_DERIV_ETR_H + +#include "../Core.hpp" + +namespace etr { + +template + requires std::is_arithmetic_v +inline auto scalarDeriv(AV &av, T s) { + av.varConstants[Idx].resize(1); + av.varConstants[Idx][0] = s; + Vec, ConstantTypeTrait> ret(av); + return ret; +} + +} // namespace etr + +#endif diff --git a/tests/Derivatives_Tests.cpp b/tests/Derivatives_Tests.cpp index 8a79c13..a076695 100644 --- a/tests/Derivatives_Tests.cpp +++ b/tests/Derivatives_Tests.cpp @@ -33,7 +33,7 @@ int main() { // NOTE: test minus { std::cout << "test minus" << std::endl; - AllVars<2, 0, 0, 2> av(0, 0); + AllVars<2, 0, 0, 3> av(0, 0); Vec, VariableTypeTrait> a(av); Vec, VariableTypeTrait> b(av); @@ -69,7 +69,7 @@ int main() { std::cout << "\n" << "a = a / b" << std::endl; - a = a / b; + a = a / scalarDeriv<3>(av, 3.14); print(a, av); print(b, av); print(get_derivs(a));