Skip to content

Commit

Permalink
Add initial version of cell_index
Browse files Browse the repository at this point in the history
  • Loading branch information
kordejong committed Mar 21, 2024
1 parent 03e5ee3 commit 28fa1f4
Show file tree
Hide file tree
Showing 11 changed files with 689 additions and 0 deletions.
1 change: 1 addition & 0 deletions environment/cmake/LueConfiguration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ set(LUE_TEMPLATIZE "${PROJECT_SOURCE_DIR}/environment/script/templatize.py")
# NOTE These can be made configurable later on
set(LUE_FRAMEWORK_CONDITION_ELEMENT uint8_t)
set(LUE_FRAMEWORK_BOOLEAN_ELEMENT uint8_t)
set(LUE_FRAMEWORK_INDEX_ELEMENT uint64_t)
set(LUE_FRAMEWORK_FLOW_DIRECTION_ELEMENT uint8_t)
set(LUE_FRAMEWORK_SIGNED_INTEGRAL_ELEMENTS int32_t int64_t)
set(LUE_FRAMEWORK_UNSIGNED_INTEGRAL_ELEMENTS uint8_t uint32_t uint64_t)
Expand Down
28 changes: 28 additions & 0 deletions source/framework/algorithm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,34 @@ block()
set(generated_source_files ${generated_source_files} PARENT_SCOPE)
endblock()

block()
set(count "0")

set(IndexElement ${LUE_FRAMEWORK_INDEX_ELEMENT})
set(ConditionElement ${LUE_FRAMEWORK_BOOLEAN_ELEMENT})

foreach(Policies IN LISTS LUE_FRAMEWORK_POLICIES)
foreach(rank IN LISTS ranks)
math(EXPR count "${count} + 1")

# Instantiate cell_index
set(output_pathname "${CMAKE_CURRENT_BINARY_DIR}/${offset}/cell_index-${count}.cpp")

generate_template_instantiation(
INPUT_PATHNAME
"${CMAKE_CURRENT_SOURCE_DIR}/${offset}/cell_index.cpp.in"
OUTPUT_PATHNAME
"${output_pathname}"
DICTIONARY
'{"Policies":"${Policies}","IndexElement":"${IndexElement}","ConditionElement":"${ConditionElement}","rank":"${rank}"}'
)
list(APPEND generated_source_files "${output_pathname}")
endforeach()
endforeach()

set(generated_source_files ${generated_source_files} PARENT_SCOPE)
endblock()

block()
set(count "0")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include "lue/framework/algorithm/policy.hpp"
#include "lue/framework/partitioned_array.hpp"


namespace lue {

template<typename Policies, Rank rank>
auto cell_index(
Policies const& policies,
PartitionedArray<policy::InputElementT<Policies, 0>, rank> const& condition,
Index dimension_idx) -> PartitionedArray<policy::OutputElementT<Policies, 0>, rank>;

} // namespace lue
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include "lue/framework/algorithm/cell_index.hpp"


namespace lue {
namespace policy::cell_index {

template<typename IndexElement, typename ConditionElement>
using DefaultPolicies = policy::DefaultPolicies<
AllValuesWithinDomain<ConditionElement>,
OutputElements<IndexElement>,
InputElements<ConditionElement>>;

} // namespace policy::cell_index


namespace default_policies {

template<typename IndexElement, typename ConditionElement, Rank rank>
auto cell_index(PartitionedArray<ConditionElement, rank> const& condition, Index const dimension_idx)
-> PartitionedArray<IndexElement, rank>
{
using Policies = policy::cell_index::DefaultPolicies<IndexElement, ConditionElement>;

return cell_index(Policies{}, condition, dimension_idx);
}

} // namespace default_policies
} // namespace lue

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include "lue/framework/algorithm/cell_index.hpp"


namespace lue {
namespace policy::cell_index {

template<typename IndexElement, typename ConditionElement>
using DefaultValuePolicies = policy::DefaultValuePolicies<
AllValuesWithinDomain<ConditionElement>,
OutputElements<IndexElement>,
InputElements<ConditionElement>>;

} // namespace policy::cell_index


namespace value_policies {

template<typename IndexElement, typename ConditionElement, Rank rank>
auto cell_index(PartitionedArray<ConditionElement, rank> const& condition, Index const dimension_idx)
-> PartitionedArray<IndexElement, rank>
{
using Policies = policy::cell_index::DefaultValuePolicies<IndexElement, ConditionElement>;

return cell_index(Policies{}, condition, dimension_idx);
}

} // namespace value_policies
} // namespace lue
13 changes: 13 additions & 0 deletions source/framework/algorithm/src/local_operation/cell_index.cpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "lue/framework/algorithm/default_policies/cell_index.hpp"
#include "lue/framework/algorithm/definition/cell_index.hpp"
#include "lue/framework/algorithm/value_policies/cell_index.hpp"


namespace lue {

LUE_INSTANTIATE_CELL_INDEX(
ESC(policy::cell_index::{{ Policies }}<{{ IndexElement }}, {{ ConditionElement }}>),
{{ rank }}
);

} // namespace lue
1 change: 1 addition & 0 deletions source/framework/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ add_library(lue_py_framework SHARED

src/algorithm/local_operation.cpp
src/algorithm/local_operation/ceil.cpp
src/algorithm/local_operation/cell_index.cpp
src/algorithm/local_operation/floor.cpp
src/algorithm/local_operation/log10.cpp
src/algorithm/local_operation/logical_and.cpp
Expand Down
2 changes: 2 additions & 0 deletions source/framework/python/src/algorithm/local_operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace lue::framework {
void bind_cast(pybind11::module& module);
void bind_cos(pybind11::module& module);
void bind_ceil(pybind11::module& module);
void bind_cell_index(pybind11::module& module);
void bind_d8_flow_direction(pybind11::module& module);
void bind_divide(pybind11::module& module);
void bind_downstream(pybind11::module& module);
Expand Down Expand Up @@ -87,6 +88,7 @@ namespace lue::framework {
bind_atan2(module);
bind_cast(module);
bind_ceil(module);
bind_cell_index(module);
bind_cos(module);
bind_d8_flow_direction(module);
bind_divide(module);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "lue/framework/algorithm/value_policies/cell_index.hpp"
#include <pybind11/pybind11.h>


namespace lue::framework {
namespace {

using ConditionElement = std::uint8_t;
using IndexElement = std::uint64_t;

template<Rank rank>
auto cell_index(PartitionedArray<ConditionElement, rank> const& condition, Index const dimension_idx)
-> PartitionedArray<IndexElement, rank>
{
return value_policies::cell_index<IndexElement>(condition, dimension_idx);
}

} // Anonymous namespace


void bind_cell_index(pybind11::module& module)
{
module.def("cell_idx", cell_index<2>);
}

} // namespace lue::framework
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import numpy as np

import lue.framework as lfr
import lue_test


def setUpModule():
lue_test.start_hpx_runtime()


def tearDownModule():
lue_test.stop_hpx_runtime()


class CellIndexTest(lue_test.TestCase):
@lue_test.framework_test_case
def test_overloads(self):
array_shape = (60, 40)
condition = lfr.create_array(array_shape, np.uint8, 1)
lfr.cell_index(condition, 0)

0 comments on commit 28fa1f4

Please sign in to comment.