Skip to content

jacobian returns wrong results in some situations #278

@wds15

Description

@wds15

Summary:

The jacobian function returns in special situations the wrong gradients.

Description:

The jacobian function in Stan uses the nested AD system to calculate gradients. As such the

set_zero_all_adjoints_nested();

function is used. Apparently, this leads to wrong results if the AD stack was never initialized before. So results are wrong if no stan::math::var was declared before the jacobian call. Replacing calls to set_zero_all_adjoints_nested(); with set_zero_all_adjoints(); seem to make the bug go away.

Reproducible Steps:

I am sending a cpp file to the dev list which shows the issue. When one uncomments the dummy definition of a var instance, then results are correct.

Current Output:

Current output depends on what happened before the call as described.

Expected Output:

Results should not depend on a first declaration of a dummy variable.

Additional Information:

Reported on stan-users from Oleg Shirokobrod.

Current Version:

develop

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions