Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some comparison errors for Jacobian functions #146

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/XAD/Hessian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ void computeHessian(const std::vector<AReal<FReal<T>>> &vec,
RowIterator first, RowIterator last,
Tape<FReal<T>> *tape = Tape<FReal<T>>::getActive())
{
unsigned int domain(static_cast<unsigned int>(vec.size()));
std::size_t domain(static_cast<std::size_t>(vec.size()));
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved

if (std::distance(first, last) != domain ||
std::distance(first->cbegin(), first->cend()) != domain)
if (static_cast<std::size_t>(std::distance(first, last)) != domain ||
static_cast<std::size_t>(std::distance(first->cbegin(), first->cend())) != domain)
throw OutOfRange("Iterator not allocated enough space");
static_assert(detail::has_begin<typename std::iterator_traits<RowIterator>::value_type>::value,
"RowIterator must dereference to a type that implements a begin() method");
Expand All @@ -72,7 +72,7 @@ void computeHessian(const std::vector<AReal<FReal<T>>> &vec,
tape->registerInputs(v);

auto row = first;
for (unsigned int i = 0; i < domain; i++, row++)
for (std::size_t i = 0; i < domain; i++, row++)
{
derivative(value(v[i])) = 1.0;
tape->newRecording();
Expand All @@ -82,7 +82,7 @@ void computeHessian(const std::vector<AReal<FReal<T>>> &vec,
tape->computeAdjoints();

auto col = row->begin();
for (unsigned int j = 0; j < domain; j++, col++)
for (std::size_t j = 0; j < domain; j++, col++)
{
*col = derivative(derivative(v[j]));
}
Expand All @@ -107,22 +107,22 @@ void computeHessian(const std::vector<FReal<FReal<T>>> &vec,
std::function<FReal<FReal<T>>(std::vector<FReal<FReal<T>>> &)> foo,
RowIterator first, RowIterator last)
{
unsigned int domain(static_cast<unsigned int>(vec.size()));
std::size_t domain(static_cast<std::size_t>(vec.size()));
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved

if (std::distance(first, last) != domain ||
std::distance(first->cbegin(), first->cend()) != domain)
if (static_cast<std::size_t>(std::distance(first, last)) != domain ||
static_cast<std::size_t>(std::distance(first->cbegin(), first->cend())) != domain)
throw OutOfRange("Iterator not allocated enough space");
static_assert(detail::has_begin<typename std::iterator_traits<RowIterator>::value_type>::value,
"RowIterator must dereference to a type that implements a begin() method");

auto v(vec);

auto row = first;
for (unsigned int i = 0; i < domain; i++, row++)
for (std::size_t i = 0; i < domain; i++, row++)
{
value(derivative(v[i])) = 1.0;
auto col = row->begin();
for (unsigned int j = 0; j < domain; j++, col++)
for (std::size_t j = 0; j < domain; j++, col++)
{
derivative(value(v[j])) = 1.0;
FReal<FReal<T>> y = foo(v);
Expand Down
22 changes: 11 additions & 11 deletions src/XAD/Jacobian.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void computeJacobian(const std::vector<AReal<T>> &vec,
std::function<std::vector<AReal<T>>(std::vector<AReal<T>> &)> foo,
RowIterator first, RowIterator last, Tape<T> *tape = Tape<T>::getActive())
{
if (std::distance(first->cbegin(), first->cend()) != vec.size())
if (static_cast<std::size_t>(std::distance(first->cbegin(), first->cend())) != vec.size())
throw OutOfRange("Iterator not allocated enough space (domain)");
static_assert(detail::has_begin<typename std::iterator_traits<RowIterator>::value_type>::value,
"RowIterator must dereference to a type that implements a begin() method");
Expand All @@ -69,19 +69,19 @@ void computeJacobian(const std::vector<AReal<T>> &vec,
tape->registerInputs(v);
tape->newRecording();
auto y = foo(v);
unsigned int domain = static_cast<unsigned int>(vec.size()),
codomain = static_cast<unsigned int>(y.size());
if (std::distance(first, last) != codomain)
std::size_t domain = static_cast<std::size_t>(vec.size()),
codomain = static_cast<std::size_t>(y.size());
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved
if (static_cast<std::size_t>(std::distance(first, last)) != codomain)
throw OutOfRange("Iterator not allocated enough space (codomain)");
tape->registerOutputs(y);

auto row = first;
for (unsigned int i = 0; i < codomain; i++, row++)
for (std::size_t i = 0; i < codomain; i++, row++)
{
auto col = row->begin();
derivative(y[i]) = 1.0;
tape->computeAdjoints();
for (unsigned int j = 0; j < domain; j++, col++) *col = derivative(v[j]);
for (std::size_t j = 0; j < domain; j++, col++) *col = derivative(v[j]);
tape->clearDerivatives();
}
}
Expand All @@ -104,25 +104,25 @@ void computeJacobian(const std::vector<FReal<T>> &vec,
std::function<std::vector<FReal<T>>(std::vector<FReal<T>> &)> foo,
RowIterator first, RowIterator last)
{
if (std::distance(first->cbegin(), first->cend()) != vec.size())
if (static_cast<std::size_t>(std::distance(first->cbegin(), first->cend())) != vec.size())
throw OutOfRange("Iterator not allocated enough space (domain)");
static_assert(detail::has_begin<typename std::iterator_traits<RowIterator>::value_type>::value,
"RowIterator must dereference to a type that implements a begin() method");

auto v(vec);
unsigned int domain = static_cast<unsigned int>(vec.size()),
codomain = static_cast<unsigned int>(foo(v).size());
std::size_t domain = static_cast<std::size_t>(vec.size()),
codomain = static_cast<std::size_t>(foo(v).size());
auto-differentiation-dev marked this conversation as resolved.
Show resolved Hide resolved

if (std::distance(first, last) != codomain)
throw OutOfRange("Iterator not allocated enough space (codomain)");

auto row = first;
for (unsigned int i = 0; i < domain; i++)
for (std::size_t i = 0; i < domain; i++)
{
derivative(v[i]) = 1.0;
auto y = foo(v);
derivative(v[i]) = 0.0;
for (unsigned int j = 0; j < codomain; j++)
for (std::size_t j = 0; j < codomain; j++)
{
row = first;
std::advance(row, j);
Expand Down
Loading