We have implement cos_sim_operator. And we use a reduce operation sum to get (x1 * x1 + x2 * x2 + ...). The reduce operations in Eigen will reduce dimensions, please refer to https://github.com/RLovelett/eigen/blob/master/unsupported/Eigen/CXX11/src/Tensor/README.md#reduction-operations.
And this means we will get a column vector(batch_size) instead of a matrix(batch_size * 1).
Now, cos_sim operator return a matrix(batch_size * 1), and it can pass unittest in ubuntu/gcc, but can not pass in mac/clang. In clang, it will cause a error.
Assertion failed: (dimensions_match(m_leftImpl.dimensions(), m_rightImpl.dimensions())), function evalSubExprsIfNeeded
And it's obvious:
auto x = EigenMatrix<T>::From(*input_x, new_dims);
auto x_norm = EigenMatrix<T>::From(*input_x_norm);
x_norm.device(place) = x.square().sum(Eigen::array<int, 1>({1})).sqrt();
The result of sum is a rank 1 vector, and x_norm is a rank 2 matrix.
So, I suggest that the output of loss operator is a rank 1 vector, it's more reasonable and can pass unittest in clang build version.