Why is this named ``valid_mask``?  It sounds more like a weight matrix, in which case it should be something like ``window_weights`` or ``template_weights`` or something like that.