Skip to content

Factor integer traits and disentangle traits headers#1314

Merged
AntoinePrv merged 1 commit intoxtensor-stack:masterfrom
AntoinePrv:factoring
Apr 22, 2026
Merged

Factor integer traits and disentangle traits headers#1314
AntoinePrv merged 1 commit intoxtensor-stack:masterfrom
AntoinePrv:factoring

Conversation

@AntoinePrv
Copy link
Copy Markdown
Contributor

@AntoinePrv AntoinePrv commented Apr 21, 2026

Factor integer trait at a higher level to avoid repeated work of explicitly defining something for all sizes.
Basically avoid repeating the following kind of logic all over:

struct sized_int<1> {
    using type = int8_t;
};
struct sized_int<2> {
    using type = int16_t;
};
...

This is added in xsimd/type_traits.hpp.
This PR as a lot of noise as I needed to fix a few circular header inclusion.

This PR is still imperfect. IMHO we still have some work work to properly factor utilities and ensure all header inclusion are non circular, order independent, and do not depend on leaking behavior (or transitively dependent).

@AntoinePrv AntoinePrv force-pushed the factoring branch 5 times, most recently from 8d85e7f to cc29bd4 Compare April 22, 2026 12:30
using signed_type = std::int64_t;
using unsigned_type = std::uint64_t;
using floating_point_type = double;
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like this!

struct widen;

template <typename T>
struct widen<T, std::enable_if_t<std::is_floating_point<T>::value>>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: you could inherit from `detail::sized_num_types::floating_point_type|

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure to understand the benefit of it since we would still need to define type as base::floating_point_type in the struct.

};

template <typename T>
struct widen<T, std::enable_if_t<!std::is_floating_point<T>::value && std::is_unsigned<T>::value>>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

!std::is_floating_point seems redundant here

#include "xtl/xcomplex.hpp"
#endif

#include "./xsimd_batch_fwd.hpp"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

good point.

Copy link
Copy Markdown
Contributor

@serge-sans-paille serge-sans-paille left a comment

Choose a reason for hiding this comment

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

While you're at it, maybe you could make all internal includes absolute instead of relative?

@AntoinePrv
Copy link
Copy Markdown
Contributor Author

@serge-sans-paille I definitely want to do a pass on header but I think this is PR is ugly enough (and I am already spending too much time on xsimd 😅 )

@JohanMabille
Copy link
Copy Markdown
Member

While you're at it, maybe you could make all internal includes absolute instead of relative?

I think we should keep them relativem this makes it easier for projects vendoring xsimd.

struct widen;

template <typename T>
struct widen<T, std::enable_if_t<std::is_floating_point<T>::value>>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure to understand the benefit of it since we would still need to define type as base::floating_point_type in the struct.

****************************************************************************/

#ifndef XSIMD_TYPE_TRAITS_HPP
#define XSIMD_TYPE_TRAITS_HPP
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This file should be named xsimd_type_traits.hpp for consistency, and should probably live in xsimd/types. Only xsimd.hpp should be at the "root" of the project

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file should be named xsimd_type_traits.hpp for consistency

Ok, though I think we should get rid of that convention in the next major release.

and should probably live in xsimd/types. Only xsimd.hpp should be at the "root" of the project

@JohanMabille
This is weird to me. Why would everything need to live in type? IMHO this participate in the general confusion about header organization and weird "../../type" inclusion.
How about "xsimd/utils"?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

though I think we should get rid of that convention in the next major release.

Not sure to understand why, having a single "include-all" header at the root of the project is a convenient pattern; having many headers at the same level would be weird.

How about "xsimd/utils"?

Works for me, as long as it is not at the sane level as xsimd.hpp

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

though I think we should get rid of that convention in the next major release.

Not sure to understand why, having a single "include-all" header at the root of the project is a convenient pattern; having many headers at the same level would be weird.

How about "xsimd/utils"?

Works for me, as long as it is not at the sane level as xsimd.hpp

I meant the xsimd_ prefix convention for filenames which I think is needlessly verbose and very much C-style.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can see to remove it in next major release, but for now let's stay consistent.

@AntoinePrv
Copy link
Copy Markdown
Contributor Author

I think we should keep them relativem this makes it easier for projects vendoring xsimd.

I think we should settle on either #include "xsimd/header.h" or #include "./header.h" but #include "header.h" should be forbidden.

****************************************************************************/

#ifndef XSIMD_TYPE_TRAITS_HPP
#define XSIMD_TYPE_TRAITS_HPP
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We can see to remove it in next major release, but for now let's stay consistent.

@AntoinePrv AntoinePrv merged commit 368f358 into xtensor-stack:master Apr 22, 2026
75 checks passed
@AntoinePrv AntoinePrv deleted the factoring branch April 22, 2026 16:51
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.

3 participants