-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Use Case
In a part of a guide on creating job templates we want to talk about how you can "prechunk" your frame range to create tasks that render more than one frame at a time. The ideal way to be doing this is with some range expressions like so:
parameterSpace:
taskParameterDefinitions:
- name: RangeStart
type: INT
range: "{{Param.FrameStart}}-{{Param.FrameEnd}}:{{Param.FramesPerTask}}"
- name: RangeEnd
type: INT
range: "{{Param.FramesPerTask}}-{{Param.FrameEnd}}:{{Param.FramesPerTask}},{{Param.FrameEnd}}"
combination: "(RangeStart,RangeEnd)"This is pretty generic and can be used for a variety of inputs. The alternative is to programmatically generate the template instead and use an array of strings for the frame ranges ("1-10", "11-20", ... and so on), but that is not a great experience and requires that the template be uniquely generated for each input.
This way of using range expressions is not currently supported by the implementation in this library; though the specification allows it.
Proposed Solution
The limitation originates here. This initial implementation accepted a simplistic overlap check for the ranges just to get something working, but it can be enhanced. The main constraint is that the solution cannot be linear time in the number of elements of a range.
For example, the following is perfectly valid input and would result in a potential denial of service if validated naively by generating the sets of values for each component of the range and checking for overlap:
range: "-99999999999999 - 99999999999999:2,-99999999999998 - 99999999999999:2"So, the solution needs to be closed form. After a little bit of digging, the solution seems to be related to solutions of Linear Diophantine equations (math stackexchange refs: here, and here).
Basically, denoting a range by the triple
We have two ranges, that we'll denote by
which is equivalent to determining the lattice points of the line on the
If any such
Notes:
- Python has a gcd function:
math.gcd() - The multiplicative inverse of
$n (mod m)$ can be calculated in Python aspow(n, -1, m)