-
Notifications
You must be signed in to change notification settings - Fork 20
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
Feature request: allow builder::name to take integers as template parameters #80
Comments
Hi @RadhikaG Currently
The variable template arg pack unfortunately cannot be of a mixed "kind". It has to either be all types or all values. We decided to go along with the type version since it is the most common use case. To make this work, you can fallback to the custom types approach. You can start by creating a struct as follows -
There are a couple of things happening here. I think you have already seen the behavior of You can see the example working here - https://buildit.so/tryit/?sample=shared&pid=3c23328edec2f3e1e9bf6b72d0870336 Would this work for you for now? As for big picture, if you are working on specializing Eigen for specific sizes, do you really need to generate Eigen::Matrix objects? Should you instead not make the internal array member dyn_var? That way the generated code will just have scalar types and their arrays? The last point is just a suggestion, please disregard if it doesn't fit your use case. I will also at some point add some of the helpers to BuildIt itself to simplify this and add an example. Thanks |
Thanks for the workaround @AjayBrahmakshatriya, will try it out and get back to you! ref big picture: there are two ways we're interested in using Eigen:
I had to pause dev on (1) for a little bit, but I will need to get around to it soon... I did however mean to schedule a meeting with you at some point to solicit some compiler design advice! Thanks once again for the help! We've managed to generate some interesting code using BuildIt for our larger research project already (which I'd be happy to talk more about), and we appreciate the number of examples you've provided! |
Hi @RadhikaG , Also, if this workaround helps with your use case, feel free to close the issue. I don't think otherwise a change is required to BuildIt right now. But I am open to suggestions if you think there is a better interface to expose to users. Thanks |
Hi @AjayBrahmakshatriya, took your solution for spin, it works well for us when we know the matrix size at compile-time! Do you by any chance have a good way to generate an Maybe this is quite hard because BuildIt can extract types only from template args? |
Hi @RadhikaG glad the solution works for compile time constants. As for first stage values as type parameters that can also be done. https://buildit.so/tryit/?sample=shared&pid=f5c939a7d6830ac609444dabba56df1d Basically you can create a helper function that can manipulate the type of the variable after it has been declared. As long it is called sometime during the lifetime of the variable it should work. If you accept such variable as function arguments they can be fixed at the beginning of the function. If you are wrapping these variable in another class, you can also do it in the constructor of the wrapper type. It is possible to do it in the constructor for Eigen too, but currently there is no way to forward constructor arguments to Eigen from dyn_var. However, you could also change the specialization for dyn_var<Eigen> and add a new constructor. Let me know if you want an example for that. This can also be made a member function inside Eigen if that is easier. Just remember to cast |
@AjayBrahmakshatriya thanks for your help! I took a stab at implementing a specialization for (this is an approximation of how we're using dyn_vars to emit instructions from another wrapper class This version is pretty darn close to what we want, but it messes up the copy (line 3 and 6 in generated code, should be Do you have any implementation tips for fixing the return type and the copied type? |
Hi @RadhikaG, If you do need deferred init for any reason, you might have to overload the deferred_init function in your specialization. Just call the original deferred_init and set the type like you would in the constructor.
Turns out the original variable in the generated code was getting the right type because when you call deferred_init a new block::var is created with a fresh new type. However the original block::decl_stmt is still pointing to the old variable. Let me know if this fixed version works for you. Thanks |
Thanks for your quick reply, your version fixed the copy issue! Do you have a good fix for the return type problem? The return type of bar is currently |
@RadhikaG , Right! Missed that part of your question. So that type isn't connected to any variable and is directly set here - https://github.com/BuildIt-lang/buildit/blob/master/include%2Fbuilder%2Fsignature_extract.h#L84 The easiest way to get the appropriate type could be to set it after the function has been extracted? The func_decl returned has a member called return_type. If it truly depends on the function body you could return the size through a ref argument (non-dyn_var) and then the calling code can patch in the type? I understand it's not the cleanest solution, but it should work. If you want a super cleam solution, you might have to extend the builder_context to derive the return type based on the return value. |
@RadhikaG closing this for now. But feel free to open it in case something comes up. Thanks |
Currently
builder::name
can only take typenames as template parameters.This prevents us from having types in the generated code that take integers as template params, so we can't generate variables with type, say
Eigen::Matrix<double, 5, 1>
(a matrix with size 5x1 fixed at compile time).Could you please add support for integer template type parameters? Thank you!
The text was updated successfully, but these errors were encountered: