This adds a second parameter `kernel`. When `affinity != kernel`, this gives inconsistent results.