map

Header: "NeoN/fields/fieldFreeFunctions.hpp"

Description

The function map applies a function to each element of the field or a subfield if a range is defined.

Definition

template<typename T, typename Inner>
void NeoN::map(Vector<T> &a, const Inner inner, std::pair<size_t, size_t> range = {0, 0})

Map a field using a specific executor.

Parameters:
  • a – The field to map.

  • inner – The function to apply to each element of the field.

  • range – The range to map the field in. If not provided, the whole field is mapped.

Example

// or any other executor CPUExecutor, SerialExecutor
NeoN::Executor = NeoN::GPUExecutor{};

NeoN::Vector<NeoN::scalar> field(exec, 2);
NeoN::map(field, KOKKOS_LAMBDA(const std::size_t i) { return 1.0; });
NeoN::map(field, KOKKOS_LAMBDA(const std::size_t i) { return 2.0; }, {1, 2}); // apply a function to a subfield
// copy to host
auto hostVector = field.copyToHost();
for (auto i = 0; i < field.size(); ++i)
{
    std::cout << hostVector[i] << std::endl;
}
// prints:
// 1.0
// 2.0