• Docs >
  • Program Listing for File offset_to.hpp
Shortcuts

Program Listing for File offset_to.hpp

Return to documentation for file (include/ripple/space/offset_to.hpp)

#ifndef RIPPLE_SPACE_OFFSET_TO_HPP
#define RIPPLE_SPACE_OFFSET_TO_HPP

#include "multidim_space.hpp"
#include <ripple/algorithm/unrolled_for.hpp>

namespace ripple {

template <typename SpatialImpl, typename... Indices>
ripple_all auto offset_to_soa(
  const MultidimSpace<SpatialImpl>& space,
  size_t                            element_size,
  Indices&&... indices) -> size_t {
  constexpr auto num_indices      = sizeof...(Indices);
  const size_t   ids[num_indices] = {static_cast<size_t>(indices)...};
  size_t         offset           = ids[0];
  unrolled_for<num_indices - 1>([&](auto i) {
    constexpr auto dim = static_cast<size_t>(i) + 1;
    offset += ids[dim] * element_size * space.step(dim);
  });
  return offset;
}

template <typename SpatialImpl, typename... Indices>
ripple_all auto offset_to_aos(
  const MultidimSpace<SpatialImpl>& space,
  size_t                            element_size,
  Indices&&... indices) -> size_t {
  constexpr auto num_indices      = sizeof...(Indices);
  const size_t   ids[num_indices] = {static_cast<size_t>(indices)...};
  std::size_t    offset           = ids[0] * element_size;
  unrolled_for<num_indices - 1>([&](auto i) {
    constexpr auto dim = static_cast<size_t>(i) + 1;
    offset += ids[dim] * element_size * space.step(dim);
  });
  return offset;
}

} // namespace ripple

#endif // RIPPLE_SPACE_OFFSET_TO_HPP

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples