Hi,
This is quite a lot of code, with a lot of TODOs in it.
You would need to give the exact stack trace.
Also you can try to print the size of the inputs you give your criterion to make sure that they are the shape you expect.