Skip to content

Add xtl::select overload for complex values.#293

Merged
JohanMabille merged 1 commit into
xtensor-stack:masterfrom
Ivorforce:complex-select
Jul 6, 2026
Merged

Add xtl::select overload for complex values.#293
JohanMabille merged 1 commit into
xtensor-stack:masterfrom
Ivorforce:complex-select

Conversation

@Ivorforce

@Ivorforce Ivorforce commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Checklist

  • The title and the commit message(s) are descriptive
  • Small commits made to fix your PR have been squashed to avoid history pollution
  • Tests have been added for new features or bug fixes
  • API of new functions and classes are documented

Description

Implements xtl::select for complex operands, e.g. for downstream use:

xt::xarray<std::complex<double>> r = xt::where(cond, a, b);

Code implemented with AI assistance (claude code). PR is human-made.

xtl::select is constrained to scalar types, so xt::where
(xt::detail::conditional_ternary, which calls xtl::select on its scalar
path) does not compile for complex operands, e.g.:

    xt::xarray<std::complex<double>> r = xt::where(cond, a, b);

    xoperation.hpp:136:24: error: no matching function for call to 'select'

Add an overload in xcomplex.hpp covering std::complex and xtl::xcomplex,
where at least one of the value arguments is complex and the other may be
a scalar. Mirrors how xoptional.hpp hosts the select overload for its own
types.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@JohanMabille

Copy link
Copy Markdown
Member

Thanks for the fix!

@JohanMabille JohanMabille merged commit b73dcdf into xtensor-stack:master Jul 6, 2026
13 checks passed
@Ivorforce Ivorforce deleted the complex-select branch July 6, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants