NamedTuples failing for zipvmap - #144
Draft
benikm91 wants to merge 1 commit into
Draft
Conversation
Replaced the `PrependAxis` match type with a typeclass to overcome resolution limitations and explicitly support Scala 3 NamedTuples. Functions passed to `vmap` and `zipvmap` can now return named tuples (e.g., `(first = x, second = y)`), and the operation will correctly prepend the mapped axis to all enclosed tensors. Added test coverage to verify the new behavior.
benikm91
force-pushed
the
zipvmap-named-tuples
branch
from
August 13, 2026 11:14
5d6a928 to
281b11c
Compare
Contributor
|
I wonder if there is a disadvantage of given up match types in terms of type inference. Have you noticed anything? We could always work around it by manually calling to tuple val res = zipvmap(Axis[A])(params.toTuple) { case (x1, x2) => x1 + x2 }
val (t1, t2) = t.vmap(Axis[A])(x => (x +! 5f, x -! 5f))
val named = (name1= t1, name2 = t2)However, if cost is only implementation complexity, I am all in for it. What is your experience? |
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.
The current zipvmap and vmap do not yet support named tuples as the return type of f. I failed to achieve this by extending the PrependAxis match type. This PR provides a solution, but I am unsure whether removing the match type is necessary. This PR is a conversation starter about whether and how we can add named tuple support more cleanly with match types. And highlighting the lack of support.
Named tuples could be quite powerful, as the tuple names can be tracked across vmap and zipvmap operations. This is not possible for case classes with a fixed tensor structure. Here with explicit type alias to clarify what is (automatically) happening: