-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d0efbe
commit cd9af9b
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#pragma once | ||
|
||
#include "../ProxyRefOpMixin.hpp" | ||
|
||
namespace llama::mapping | ||
{ | ||
namespace internal | ||
{ | ||
template<typename T> | ||
struct NullReference : ProxyRefOpMixin<NullReference<T>, T> | ||
{ | ||
// NOLINTNEXTLINE(google-explicit-constructor,hicpp-explicit-conversions) | ||
LLAMA_FN_HOST_ACC_INLINE constexpr operator T() const | ||
{ | ||
return T{}; // this might not be the best design decision | ||
} | ||
|
||
LLAMA_FN_HOST_ACC_INLINE constexpr auto operator=(T) -> NullReference& | ||
{ | ||
return *this; | ||
} | ||
}; | ||
} // namespace internal | ||
|
||
/// The Null mappings maps all elements to nothing. Writing data through a reference obtained from the Null mapping | ||
/// discards the value. Reading through such a reference returns a default constructed object. | ||
template<typename TArrayExtents, typename TRecordDim> | ||
struct Null : TArrayExtents | ||
{ | ||
using ArrayExtents = TArrayExtents; | ||
using ArrayIndex = typename ArrayExtents::Index; | ||
using RecordDim = TRecordDim; | ||
static constexpr std::size_t blobCount = 0; | ||
|
||
constexpr Null() = default; | ||
|
||
LLAMA_FN_HOST_ACC_INLINE | ||
constexpr Null(ArrayExtents extents, RecordDim = {}) : ArrayExtents(extents) | ||
{ | ||
} | ||
|
||
LLAMA_FN_HOST_ACC_INLINE constexpr auto extents() const -> ArrayExtents | ||
{ | ||
return *this; // NOLINT(cppcoreguidelines-slicing) | ||
} | ||
|
||
LLAMA_FN_HOST_ACC_INLINE | ||
constexpr auto blobSize(std::size_t /*blobIndex*/) const -> std::size_t | ||
{ | ||
return 0; | ||
} | ||
|
||
template<std::size_t... RecordCoords> | ||
static constexpr auto isComputed(RecordCoord<RecordCoords...>) | ||
{ | ||
return true; | ||
} | ||
|
||
template<std::size_t... RecordCoords, typename Blobs> | ||
LLAMA_FN_HOST_ACC_INLINE constexpr auto compute(ArrayIndex, RecordCoord<RecordCoords...>, Blobs&) const | ||
{ | ||
using FieldType = GetType<RecordDim, RecordCoord<RecordCoords...>>; | ||
return internal::NullReference<FieldType>{}; | ||
} | ||
}; | ||
} // namespace llama::mapping |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include "common.hpp" | ||
|
||
#include <cstdint> | ||
|
||
TEST_CASE("mapping.Null") | ||
{ | ||
auto mapping = llama::mapping::Null<llama::ArrayExtents<128>, Particle>{{}}; | ||
STATIC_REQUIRE(decltype(mapping)::blobCount == 0); | ||
|
||
auto view = llama::allocView(mapping); | ||
iotaFillView(view); | ||
|
||
for(auto ai : llama::ArrayIndexRange{view.mapping().extents()}) | ||
llama::forEachLeafCoord<Particle>( | ||
[&](auto rc) | ||
{ | ||
CAPTURE(ai, rc); | ||
using Type = llama::GetType<Particle, decltype(rc)>; | ||
CHECK(view(ai)(rc) == Type{}); | ||
}); | ||
} |