Course 1 week 2 Custom loss function. How to return value?

I don’t completely understand how to return the calculated loss in a custom loss function. As I know the returned value should be scalar. So when calculating loss in the function should I consider that there is a batch with multiple samples fed to this function? or I should write the code for calculating loss for just one sample and Tensorflow will take the average or mean if it finds there are multiple inputs on the loss function returned value? I
Huber Loss and Contrastive Loss they both works. But Huber loss function doesn’t take mean of the output (dosen’t consider there are multiple sample input and for a given batch input will return a vector) and the Contrastive loss considered it and took a mean to return scalar. Apparently both of them work.

@Kooshan
You should ideally write your loss function for a single example and let TensorFlow handle the reduction step on the batch.