Here, also, is my implementation:
@uchida-takumi I would be interested in your thoughts on comparisons between the approaches.