-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Typechecker: Allow predicate-based typechecking of library functions #1373
Comments
Right now an argument is specified as I think we could define another type which looks like: type argtype =
| Concrete of UnsizedType.t
| Predicate of (UnsizedType.t -> bool) (* think of this like a C++ concept *) We'd need to rewrite a fair amount of stuff to handle this but I don't think it would be too bad. The argument type of
Unfortunately this becomes very difficult to print. We could have |
I think we could do this with an API like (*Function that depends on two types*)
let matching_array_types x y =
match x, y with
| UnsizedType.UArray _, UnsizedType.UArray _ when x == y -> Valid
| _ -> Invalid
Fun ("append_array", matching_array_types)
(*Anything is valid*)
let all_valid _ = Valid
Fun ("size", all_valid)
(*For the distributions*)
let is_vectorizable x =
match x with
| UnsizedType.UArray (UReal, UInt) | UVector | URowVector | UReal | UInt -> true
| _ -> false
in
let is_all_vectorizable x, y, z =
if is_vectorizable x && is_vectorizable y && is_vectorizable z the
Valid
else
Invalid
in
Fun ("normal_lpdf", is_all_vectorizable) |
Some further thoughts:
|
Scalar only for now, see #1373 for partial reason
Scalar only for now, see #1373 for partial reason
This would allow Array functions to be able to accept arrays of tuples,
e.g.
size
And also allow vectorization of things like a 7-parameter function, which would currently be too expensive to enumerate
The text was updated successfully, but these errors were encountered: