Add dtype helper macro#8140
Open
connortsui20 wants to merge 1 commit into
Open
Conversation
| ); | ||
|
|
||
| // SAFETY: `precision > 0` was asserted above. | ||
| let precision = unsafe { NonZero::new_unchecked(precision) }; |
Contributor
Author
There was a problem hiding this comment.
The safe one returns an option
Contributor
There was a problem hiding this comment.
so this that instead of an assert above.
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
94662fd to
6329248
Compare
Merging this PR will improve performance by 19.85%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | chunked_varbinview_opt_canonical_into[(1000, 10)] |
225.4 µs | 188.1 µs | +19.85% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing ct/dtype-macro (6329248) with develop (1cd5c27)
Comment on lines
+376
to
+385
| let inner = StructFields::from_iter([("mean", dtype!(f64?)), ("count", dtype!(u32))]); | ||
| let outer = StructFields::from_iter([ | ||
| ("id", dtype!(i64)), | ||
| ("label", dtype!(utf8?)), | ||
| ("values", dtype!(list(f32)?)), | ||
| ("codes", dtype!(fixed_size_list(u8?)[4])), | ||
| ("metrics", dtype!(struct(inner)?)), | ||
| ]); | ||
| let dt = dtype!(struct(outer.clone())?); | ||
| assert_eq!(dt, DType::Struct(outer, Nullable)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
I often have found myself getting annoyed at the amount of boilerplate needed to define different dtypes.
This is a simple macro that autogenerates dtypes and nested dtypes. I specifically exclude struct fields from this macro since people might have different opinions on what the syntax should be.
Also adds a
constversion ofDecimalDTypeconstruction since I would like to have the dtype macro fail if we try to construct something bad.Testing
Basic unit tests, including some deeper nested dtypes.