Fixed basis check in gradient