Skip to content

Commit ffece1a

Browse files
committed
[advalue] Fix a bug in initialization for dim=0
1 parent 8d912dd commit ffece1a

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

ADOL-C/include/adolc/advalue.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ template <class V, std::size_t m, std::size_t dim> class ADValue {
346346
ADValue(const T &value, I k) : jet_() {
347347
partial() = value;
348348
if constexpr (maxOrder >= 1)
349-
partial(k) = 1;
349+
if (dim > 0)
350+
partial(k) = 1;
350351
}
351352

352353
/**
@@ -368,18 +369,18 @@ template <class V, std::size_t m, std::size_t dim> class ADValue {
368369
ADValue(const T &value, I k, std::size_t d) : jet_(d) {
369370
partial() = value;
370371
if constexpr (maxOrder >= 1)
371-
partial(k) = 1;
372+
if (d > 0)
373+
partial(k) = 1;
372374
}
373375

374376
/**
375377
* \brief Assignment from raw value
376378
*
377379
* This will treat this as a constant afterwards.
378380
*/
379-
// template<class T,
380-
// std::enable_if_t<std::is_convertible_v<T, Value>, int> = 0>
381-
// ADValue& operator=(const T& value)
382-
ADValue &operator=(const Value &value) {
381+
template <class T, std::enable_if_t<std::is_convertible_v<T, Value>, int> = 0>
382+
ADValue &operator=(const T &value) {
383+
// ADValue &operator=(const Value &value) {
383384
forEachDerivativeIndex([&](auto... i) { partial(i...) = 0; });
384385
partial() = value;
385386
return *this;

0 commit comments

Comments
 (0)