Skip to content

Conversation

@upsj
Copy link
Member

@upsj upsj commented Oct 28, 2025

The iteration stopping criterion currently requires that we specify the iteration count using an unsigned integer type, and fails even with integer literals like with_iterations(1) with a hard-to-understand error message based on narrowing conversions in {} brace initialization. With residual norm criteria, the same happens when specifying double values for float parameters.

This PR turns the error into a normal signed-unsigned/lossy conversion conversion warning and hopefully makes it easier to use:

Before:

include/ginkgo/core/stop/iteration.hpp:39:36: error: non-constant-expression cannot be narrowed from type 'int' to 'type' (aka 'unsigned long') in initializer list [-Wc++11-narrowing]
   39 |             this->max_iters = type{value};
      |                                    ^~~~~
examples/simple-solver/simple-solver.cpp:107:47: note: in instantiation of function template specialization 'gko::stop::Iteration::parameters_type::with_max_iters<int &>' requested here
  107 |                 gko::stop::Iteration::build().with_max_iters(max_iters),
      |                                               ^
include/ginkgo/core/stop/iteration.hpp:39:36: note: insert an explicit cast to silence this issue
   39 |             this->max_iters = type{value};
      |                                    ^~~~~
      |                                    static_cast<type>( )

After:

examples/simple-solver/simple-solver.cpp:107:62: warning: implicit conversion changes signedness: 'int' to 'size_type' (aka 'unsigned long') [-Wsign-conversion]
  107 |                 gko::stop::Iteration::build().with_max_iters(max_iters),

@upsj upsj requested a review from a team October 28, 2025 14:39
@upsj upsj self-assigned this Oct 28, 2025
@upsj upsj added the 1:ST:ready-for-review This PR is ready for review label Oct 28, 2025
@ginkgo-bot ginkgo-bot added mod:core This is related to the core module. type:stopping-criteria This is related to the stopping criteria labels Oct 28, 2025
@upsj upsj force-pushed the iteration_interface_improvement branch from ca11e21 to 9aa42af Compare October 28, 2025 14:41
@upsj upsj changed the title Allow iteration counts in any integer type Relax type requirements for stopping criterion parameters Oct 28, 2025
Copy link
Member

@yhmtsai yhmtsai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also share the message old vs new?

Co-authored-by: Yu-Hsiang Tsai <yhmtsai@gmail.com>
@upsj upsj added 1:ST:ready-to-merge This PR is ready to merge. and removed 1:ST:ready-for-review This PR is ready for review labels Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1:ST:ready-to-merge This PR is ready to merge. mod:core This is related to the core module. type:stopping-criteria This is related to the stopping criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants