Skip to content

Commit

Permalink
Remove unused utility
Browse files Browse the repository at this point in the history
  • Loading branch information
aprokop committed Aug 2, 2024
1 parent 94d3248 commit 810f2d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,49 +226,6 @@ KOKKOS_FUNCTION void symmetricPseudoInverseSVDKernel(Matrix &mat, Diag &diag,
}
}

template <typename ExecutionSpace, typename InOutMatrices>
void symmetricPseudoInverseSVD(ExecutionSpace const &space,
InOutMatrices &matrices)
{
auto guard =
Kokkos::Profiling::ScopedRegion("ArborX::SymmetricPseudoInverseSVD");

// InOutMatrices is a list of square symmetric matrices (3D view)
static_assert(Kokkos::is_view_v<InOutMatrices>, "matrices must be a view");
static_assert(!std::is_const_v<typename InOutMatrices::value_type>,
"matrices must be writable");
static_assert(InOutMatrices::rank == 3,
"matrices must be a list of square matrices");
static_assert(
ArborX::Details::KokkosExt::is_accessible_from<
typename InOutMatrices::memory_space, ExecutionSpace>::value,
"matrices must be accessible from the execution space");

KOKKOS_ASSERT(matrices.extent(1) == matrices.extent(2)); // Must be square

using Value = typename InOutMatrices::non_const_value_type;
using MemorySpace = typename InOutMatrices::memory_space;

Kokkos::View<Value **, MemorySpace> diags(
Kokkos::view_alloc(space, Kokkos::WithoutInitializing,
"ArborX::SymmetricPseudoInverseSVD::diags"),
matrices.extent(0), matrices.extent(1));
Kokkos::View<Value ***, MemorySpace> units(
Kokkos::view_alloc(space, Kokkos::WithoutInitializing,
"ArborX::SymmetricPseudoInverseSVD::units"),
matrices.extent(0), matrices.extent(1), matrices.extent(2));

Kokkos::parallel_for(
"ArborX::SymmetricPseudoInverseSVD::computations",
Kokkos::RangePolicy<ExecutionSpace>(space, 0, matrices.extent(0)),
KOKKOS_LAMBDA(int const i) {
auto mat = Kokkos::subview(matrices, i, Kokkos::ALL, Kokkos::ALL);
auto diag = Kokkos::subview(diags, i, Kokkos::ALL);
auto unit = Kokkos::subview(units, i, Kokkos::ALL, Kokkos::ALL);
symmetricPseudoInverseSVDKernel(mat, diag, unit);
});
}

} // namespace ArborX::Interpolation::Details

#endif
42 changes: 21 additions & 21 deletions test/tstInterpDetailsSVD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,39 @@
#include "BoostTest_CUDA_clang_workarounds.hpp"
#include <boost/test/unit_test.hpp>

template <typename MS, typename ES, typename V, int M, int N>
void makeCase(ES const &es, V const (&src_arr)[M][N][N],
V const (&ref_arr)[M][N][N])
template <typename MemorySpace, typename ExecutionSpace, typename Value, int M,
int N>
void makeCase(ExecutionSpace const &exec, Value const (&src_arr)[M][N][N],
Value const (&ref_arr)[M][N][N])
{
using DeviceView = Kokkos::View<V[M][N][N], MS>;
using DeviceView = Kokkos::View<Value[N][N], MemorySpace>;
using HostView = typename DeviceView::HostMirror;

HostView src("Testing::src");
HostView ref("Testing::ref");

DeviceView inv("Testing::inv");
DeviceView unit("Testing::unit");
Kokkos::View<Value[N], MemorySpace> diag("Testing::diag");

for (int i = 0; i < M; i++)
{
for (int j = 0; j < N; j++)
for (int k = 0; k < N; k++)
{
src(i, j, k) = src_arr[i][j][k];
ref(i, j, k) = ref_arr[i][j][k];
src(j, k) = src_arr[i][j][k];
ref(j, k) = ref_arr[i][j][k];
}

Kokkos::deep_copy(es, inv, src);
ArborX::Interpolation::Details::symmetricPseudoInverseSVD(es, inv);
ARBORX_MDVIEW_TEST_TOL(ref, inv, Kokkos::Experimental::epsilon_v<float>);
Kokkos::deep_copy(exec, inv, src);

Kokkos::parallel_for(
"Testing::run_case", Kokkos::RangePolicy<ExecutionSpace>(exec, 0, 1),
KOKKOS_LAMBDA(int) {
ArborX::Interpolation::Details::symmetricPseudoInverseSVDKernel(
inv, diag, unit);
});
ARBORX_MDVIEW_TEST_TOL(ref, inv, Kokkos::Experimental::epsilon_v<float>);
}
}

// Pseudo-inverses were computed using numpy's "linalg.pinv" solver and
Expand Down Expand Up @@ -115,14 +126,3 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(pseudo_inv_scalar_like, DeviceType,
double inv[2][1][1] = {{{1 / 2.}}, {{0}}};
makeCase<MemorySpace>(space, mat, inv);
}

BOOST_AUTO_TEST_CASE_TEMPLATE(pseudo_inv_empty, DeviceType, ARBORX_DEVICE_TYPES)
{
using ExecutionSpace = typename DeviceType::execution_space;
using MemorySpace = typename DeviceType::memory_space;
ExecutionSpace space{};

Kokkos::View<double ***, MemorySpace> mat("mat", 0, 0, 0);
ArborX::Interpolation::Details::symmetricPseudoInverseSVD(space, mat);
BOOST_TEST(mat.size() == 0);
}

0 comments on commit 810f2d2

Please sign in to comment.