train function primitive