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

Allow d.msg in DebugIfEntry to contain an identifier to print the field #351

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable Changes to the Julia package `Manopt.jl` will be documented in this
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [unreleased]

### Added

* Allow the `message=` of the `DebugIfEntry` debug action to contain a format element to print the field in the message as well.

## [0.4.50] January 26, 2024

### Fixed
Expand Down
16 changes: 11 additions & 5 deletions src/plans/debug.jl
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,11 @@ end
@doc raw"""
DebugIfEntry <: DebugAction

Issue a warning, info or error if a certain field does _not_ pass a check
Issue a warning, info or error if a certain field does _not_ pass a check.

The `message` is printed in this case. If it contains a `@printf` argument identifier,
that one will be filled with the value of the `field`.
That way you can print the vaule in this case as well.

# Fields

Expand Down Expand Up @@ -400,10 +404,12 @@ mutable struct DebugIfEntry{F} <: DebugAction
end
function (d::DebugIfEntry)(::AbstractManoptProblem, st::AbstractManoptSolverState, i)
if (i >= 0) && (!d.check(getfield(st, d.field)))
d.type === :warn && (@warn "$(d.msg)")
d.type === :info && (@info "$(d.msg)")
d.type === :error && error(d.msg)
d.type === :print && print(d.io, d.msg)
format = Printf.Format(d.msg)
msg = !('%' ∈ d.msg) ? d.msg : Printf.format(format, getfield(st, d.field))
d.type === :warn && (@warn "$(msg)")
d.type === :info && (@info "$(msg)")
d.type === :error && error(msg)
d.type === :print && print(d.io, msg)
end
return nothing
end
Expand Down
Loading