same function for vector and scalar input