Simplify and fix template parameters

This commit is contained in:
Matti Eskelinen
2026-01-26 09:25:07 +00:00
parent e9485e0ecb
commit 0a43ee37b4
2 changed files with 28 additions and 37 deletions

View File

@@ -9,41 +9,6 @@
namespace ck_tile {
template <typename ComputeDataType>
void sinkhorn_knopp_ref_single_iter(HostTensor<ComputeDataType>& c_n_n,
HostTensor<ComputeDataType>& acc_n)
{
const index_t input_n = acc_n.get_length(0);
// Sum and scale rowwise
for(index_t i = 0; i < input_n; ++i)
{
acc_n(i) = 0;
for(index_t j = 0; j < input_n; ++j)
{
acc_n(i) += c_n_n(i, j);
}
for(index_t j = 0; j < input_n; ++j)
{
c_n_n(i, j) /= acc_n(i);
}
}
// Repeat columnwise
for(index_t i = 0; i < input_n; ++i)
{
acc_n(i) = 0;
for(index_t j = 0; j < input_n; ++j)
{
acc_n(i) += c_n_n(j, i);
}
for(index_t j = 0; j < input_n; ++j)
{
c_n_n(j, i) /= acc_n(i);
}
}
}
template <typename XDataType, typename ComputeDataType, typename YDataType>
void sinkhorn_knopp_ref(const HostTensor<XDataType>& x_n_n,
HostTensor<YDataType>& y_n_n,
@@ -65,7 +30,33 @@ void sinkhorn_knopp_ref(const HostTensor<XDataType>& x_n_n,
// Iterate normalization on rows and columns
for(auto it = 0; it < n_iter; ++it)
{
sinkhorn_knopp_ref_single_iter(c_n_n, c_n_n);
// Sum and scale rowwise
for(index_t i = 0; i < input_n; ++i)
{
acc_n(i) = 0;
for(index_t j = 0; j < input_n; ++j)
{
acc_n(i) += c_n_n(i, j);
}
for(index_t j = 0; j < input_n; ++j)
{
c_n_n(i, j) /= acc_n(i);
}
}
// Repeat columnwise
for(index_t i = 0; i < input_n; ++i)
{
acc_n(i) = 0;
for(index_t j = 0; j < input_n; ++j)
{
acc_n(i) += c_n_n(j, i);
}
for(index_t j = 0; j < input_n; ++j)
{
c_n_n(j, i) /= acc_n(i);
}
}
}
// Copy and cast to output type