Skip to content

N-dim iteration #809

Answered by duvenaud
AriMKatz asked this question in Q&A
Discussion options

You must be logged in to vote

Great question. In some senses the answer is yes, in others it's no. Specifically, there's no way in the current type system to write a function that can take an arbitrarily-nested index set, like:

def reduce_over_arbitrary_dims (xs: m=>n=>o...=>y=>z=>Float) : Float = ...

However, there are three senses in which the answer is yes:

1. Nested index sets are isomorphic to products of index sets.

All for loops in Dex can already reduce over any index set that you can create, and index sets can be of arbitrary size and shape internally. For instance, here's the type of fsum:

def fsum {n} (xs:n=>Float) : Float = ...

As long as we can express your table indices as a single index set (here n), al…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by AriMKatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants