Fixed calculate_histogram kernel