def apply_cos_deriv(self, val, target = None):
        """
        Apply cos derivative, where val is the activation of cos units.
        """

        if not target:
            target = self

        if isinstance(val, CUDAMatrix):
            err_code = _cudamat.apply_cos_deriv(self.p_mat, val.p_mat, target.p_mat)
        else:
            raise ValueError, "Value must be of type CUDAMatrix."

        if err_code:
            raise generate_exception(err_code)

        return target

        Apply cos derivative, where val is the activation of cos units.
        
cudamat/cudamat.py