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

Meta-programming tools and arrow types traits support. #49

Merged
merged 21 commits into from
Apr 9, 2024

Conversation

Klaim
Copy link
Collaborator

@Klaim Klaim commented Mar 27, 2024

Fix #67
Fix #68
Part of the effort for #15

  • added various metaprogramming basic algorithms and tools;
  • added concepts to check arrow-supported types;
  • added arrow_traits to extract information about arrow-supported types, including custom ones;
  • related tests.
  • added float16_t support, using copy-pasted dependency in C++20, standard library in C++23

include/sparrow/data_traits.hpp Outdated Show resolved Hide resolved
include/sparrow/data_type.hpp Outdated Show resolved Hide resolved
include/sparrow/mp_utils.hpp Outdated Show resolved Hide resolved
include/sparrow/mp_utils.hpp Show resolved Hide resolved
include/sparrow/mp_utils.hpp Outdated Show resolved Hide resolved
include/sparrow/mp_utils.hpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

A first pass.

, float32_t
, float64_t
, std::string
//, std::vector<std::byte> // REVIEW should this be uint8_t? char? buffer<unit8_t>?
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's true that we have used uint8_t over std::byte for the buffer.

Is uint8_t use for interoperability with C, or are there other reason not to use std::byte?

Also, if we use uint8_t we must:

static_assert(CHAR_BIT == 8);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The main "classic" issue is that because std::byte has a strong type, not implicitly converted to other similar types, it's not automatically compatible with functions working with char or char-like types, in particular when interfacing with C. Lots of explicit casts ensures. Not a big problem if you like correctness but it does obfuscate the code. It's the main criticism I'm aware of.

In this library, I'm not sure what would be best, but the C api kinds of forces us with at least some of the types?

Also, if we use uint8_t we must:

hmm actually shouldnt we always check that? I'll add it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think, @JohanMabille?

Copy link
Collaborator

Choose a reason for hiding this comment

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

The C Api uses void* for the buffers, so we'll have to cast anyway. I would actually be in favor of replacing the uint8_t with byte in the array_data buffers.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ok I went with an alias byte_t so that we can change that easilly, and added vector<byte_t> and I suppose we'll see how it goes from here.

include/sparrow/details/3rdparty/README.md Outdated Show resolved Hide resolved
include/sparrow/details/3rdparty/float16_t.hpp Outdated Show resolved Hide resolved
include/sparrow/data_type.hpp Outdated Show resolved Hide resolved
test/test_mpl.cpp Show resolved Hide resolved
include/sparrow/data_traits.hpp Show resolved Hide resolved
include/sparrow/data_type.hpp Show resolved Hide resolved
include/sparrow/data_type.hpp Outdated Show resolved Hide resolved
test/test_mpl.cpp Outdated Show resolved Hide resolved
test/test_traits.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

Looks neat to me!

I have few comments and questions.

include/sparrow/data_traits.hpp Outdated Show resolved Hide resolved
include/sparrow/data_type.hpp Show resolved Hide resolved
include/sparrow/mp_utils.hpp Outdated Show resolved Hide resolved
include/sparrow/data_type.hpp Outdated Show resolved Hide resolved
, float32_t
, float64_t
, std::string
//, std::vector<std::byte> // REVIEW should this be uint8_t? char? buffer<unit8_t>?
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think, @JohanMabille?

test/test_mpl.cpp Outdated Show resolved Hide resolved
test/test_traits.cpp Outdated Show resolved Hide resolved
test/test_traits.cpp Show resolved Hide resolved
include/sparrow/mp_utils.hpp Outdated Show resolved Hide resolved
include/sparrow/mp_utils.hpp Outdated Show resolved Hide resolved
Klaim and others added 13 commits April 5, 2024 16:20
- added various metaprogramming basic algorithms and tools;
- added concepts to check arrow-supported types;
- added `arrow_traits` to extract information about arrow-supported types, including custom ones;
- related tests.
- added `float16_t` support, using copy-pasted dependency in C++20, standard library in C++23
Co-authored-by: Julien Jerphanion <[email protected]>
Co-authored-by: Julien Jerphanion <[email protected]>
Co-authored-by: Julien Jerphanion <[email protected]>
Co-authored-by: Alexis Placet <[email protected]>
test/test_mpl.cpp Show resolved Hide resolved
include/sparrow/data_type.hpp Outdated Show resolved Hide resolved
@JohanMabille
Copy link
Collaborator

LGTM except the minor comment I left.

or
requires(std::decay_t<P> predicate)
{
{ predicate(std::type_identity_t<T>{}) } -> std::convertible_to<bool>;
Copy link
Collaborator

@JohanMabille JohanMabille Apr 8, 2024

Choose a reason for hiding this comment

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

I don't remember why we need to support both type_identity_t and typelist.Would the support of type_identity be enough? It looks like predicates will be evaluated over types in a typelist via the evaluate function, resulting in a pattern like (evaluate<T> OP ... OP init); therefore evaluate could accept type_identity_t only and that would simplify the code. But as always when I have this feeling, I probably missed something.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't remember why we need to support both type_identity_t and typelist.

I started with typelist because that's what the algorithms in this PR work with as argument, to not deviate too far. The support for type_identity you suggested simply allows for code taht dont depend on sparrow to still add new type-predicates as callable objects.

Would the support of type_identity be enough?

Both are fine to me, or do you see a cost I'm not seeing?

It looks like predicates will be evaluated over types in a typelist via the evaluate function, resulting in a pattern like (evaluate OP ... OP init); therefore evaluate could accept type_identity_t only and taht would simplify the code. But as always when I have this feeling, I probably issed something.

No you're right, both typelist and type_identity works here so I support both and other than the potential extension without being dependent on sparrow, it would indeed simplify some of the code.

Not sure what to do here. I have a slight preference toward supporting "anything that can act as a type wrapper" so that's why I switched to using the mpl::type_wrapper concept instead of being too specific. The implementations of the algorithms could be rewritten with any type wrappers.

Choices. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Both are fine to me, or do you see a cost I'm not seeing?

Not really, it was really for simplifying the code. Also concepts with or clauses don't subsume, but I guess it's not really importnat here since we'll probably won'r refine the callable_type_predicate concept.

I would say let's keep it as is for now, and use it. And we'll see later if we can really simplify it (if that's really worth it, and it it does not break any code using it).

@Klaim Klaim marked this pull request as ready for review April 8, 2024 15:21
Copy link
Collaborator

@jjerphan jjerphan left a comment

Choose a reason for hiding this comment

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

LGTM.

Minor suggestion which need not be adressed: we could reference the thread of discussions so that we can more easily refer to them in the future.

@Klaim Klaim merged commit 2a07414 into man-group:main Apr 9, 2024
20 checks passed
@jjerphan jjerphan mentioned this pull request Apr 9, 2024
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.

Add support for float16_t type Implement basic metaprogramming tools and arrow_traits
4 participants