-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial setup for integrate_and_allocate
- Loading branch information
Showing
13 changed files
with
802 additions
and
96 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
597 changes: 597 additions & 0 deletions
597
...ramework/image_land/include/lue/framework/algorithm/definition/integrate_and_allocate.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
source/framework/image_land/include/lue/framework/algorithm/integrate_and_allocate.hpp
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,27 @@ | ||
#pragma once | ||
#include "lue/framework/algorithm/policy.hpp" | ||
#include "lue/framework/partitioned_array.hpp" | ||
#include "lue/framework/serial_route.hpp" | ||
#include <functional> | ||
#include <map> | ||
#include <tuple> | ||
#include <vector> | ||
|
||
|
||
namespace lue { | ||
|
||
template<typename Policies, Rank rank> | ||
auto integrate_and_allocate( | ||
Policies const& policies, | ||
SerialRoute<policy::InputElementT<Policies, 0>, rank> const& route, | ||
PartitionedArray<policy::InputElementT<Policies, 1>, rank> const& zone, | ||
std::vector< | ||
std::reference_wrapper<PartitionedArray<policy::InputElementT<Policies, 2>, rank> const>> const& | ||
crop_fractions) | ||
-> std::tuple< | ||
// Crop fractions | ||
std::vector<PartitionedArray<policy::OutputElementT<Policies, 0>, rank>>, | ||
// Zonal production | ||
std::map<policy::InputElementT<Policies, 1>, policy::OutputElementT<Policies, 1>>>; | ||
|
||
} // namespace lue |
90 changes: 0 additions & 90 deletions
90
source/framework/image_land/include/lue/framework/algorithm/integration_allocation.hpp
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...work/image_land/include/lue/framework/algorithm/value_policies/integrate_and_allocate.hpp
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,36 @@ | ||
#pragma once | ||
#include "lue/framework/algorithm/integrate_and_allocate.hpp" | ||
|
||
|
||
namespace lue { | ||
namespace policy::integrate_and_allocate { | ||
|
||
template<typename ZoneElement, typename FloatingPointElement> | ||
using DefaultValuePolicies = policy::DefaultValuePolicies< | ||
AllValuesWithinDomain<ZoneElement, ZoneElement, FloatingPointElement>, | ||
OutputElements<FloatingPointElement, FloatingPointElement>, | ||
InputElements<ZoneElement, ZoneElement, FloatingPointElement>>; | ||
|
||
} // namespace policy::integrate_and_allocate | ||
|
||
|
||
namespace value_policies { | ||
|
||
template<typename ZoneElement, typename FloatingPointElement, Rank rank> | ||
auto integrate_and_allocate( | ||
SerialRoute<ZoneElement, rank> const& route, | ||
PartitionedArray<ZoneElement, rank> const& zone, | ||
std::vector<std::reference_wrapper<PartitionedArray<FloatingPointElement, rank> const>> const& | ||
crop_fractions) | ||
-> std::tuple< | ||
std::vector<PartitionedArray<FloatingPointElement, rank>>, | ||
std::map<ZoneElement, FloatingPointElement>> | ||
{ | ||
using Policies = | ||
policy::integrate_and_allocate::DefaultValuePolicies<ZoneElement, FloatingPointElement>; | ||
|
||
return integrate_and_allocate(Policies{}, route, zone, crop_fractions); | ||
} | ||
|
||
} // namespace value_policies | ||
} // namespace lue |
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
50 changes: 50 additions & 0 deletions
50
source/framework/image_land/python/src/integrate_and_allocate.cpp
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,50 @@ | ||
#include "lue/framework/algorithm/value_policies/integrate_and_allocate.hpp" | ||
// #include "lue/py/framework/core/partitioned_array.hpp" | ||
// #include "lue/py/framework/core/vector_of_array.hpp" | ||
#include <pybind11/stl.h> | ||
|
||
|
||
namespace lue::image_land { | ||
namespace detail { | ||
|
||
template<typename ZoneElement, typename FloatingPointElement, Rank rank> | ||
auto integrate_and_allocate( | ||
SerialRoute<ZoneElement, rank> const& route, | ||
PartitionedArray<ZoneElement, rank> const& zone, | ||
std::vector<std::reference_wrapper<PartitionedArray<FloatingPointElement, rank> const>> const& | ||
crop_fractions) | ||
{ | ||
return lue::value_policies::integrate_and_allocate(route, zone, crop_fractions); | ||
} | ||
|
||
|
||
template<typename ZoneElement, typename FloatingPointElement, Rank rank> | ||
void bind_integrate_and_allocate(pybind11::module& module) | ||
{ | ||
module.def( | ||
"integrate_and_allocate", | ||
lue::image_land::detail::integrate_and_allocate<ZoneElement, FloatingPointElement, rank>, | ||
pybind11::return_value_policy::move); | ||
} | ||
|
||
} // namespace detail | ||
|
||
|
||
void bind_integrate_and_allocate(pybind11::module& module) | ||
{ | ||
Rank const rank{2}; | ||
|
||
detail::bind_integrate_and_allocate<std::uint8_t, float, rank>(module); | ||
detail::bind_integrate_and_allocate<std::uint32_t, float, rank>(module); | ||
detail::bind_integrate_and_allocate<std::uint64_t, float, rank>(module); | ||
detail::bind_integrate_and_allocate<std::int32_t, float, rank>(module); | ||
detail::bind_integrate_and_allocate<std::int64_t, float, rank>(module); | ||
|
||
detail::bind_integrate_and_allocate<std::uint8_t, double, rank>(module); | ||
detail::bind_integrate_and_allocate<std::uint32_t, double, rank>(module); | ||
detail::bind_integrate_and_allocate<std::uint64_t, double, rank>(module); | ||
detail::bind_integrate_and_allocate<std::int32_t, double, rank>(module); | ||
detail::bind_integrate_and_allocate<std::int64_t, double, rank>(module); | ||
} | ||
|
||
} // namespace lue::image_land |
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
48 changes: 48 additions & 0 deletions
48
source/framework/image_land/python/test/integrate_and_allocate_test.py
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,48 @@ | ||
import numpy as np | ||
|
||
import lue.framework as lfr | ||
import lue.image_land as img | ||
import lue_test | ||
|
||
|
||
def setUpModule(): | ||
lue_test.start_hpx_runtime() | ||
|
||
|
||
def tearDownModule(): | ||
lue_test.stop_hpx_runtime() | ||
|
||
|
||
class IntegrateAndAllocateTest(lue_test.TestCase): | ||
@lue_test.framework_test_case | ||
def test_overloads(self): | ||
array_shape = (60, 40) | ||
zone_fill_value = 1 | ||
suitability_fill_value = 5.5 | ||
max_nr_cells = 10 | ||
nr_crops = 3 | ||
|
||
for zone_dtype in [np.uint8, np.uint32, np.uint64, np.int32, np.int64]: | ||
for floating_point_type in [np.float32, np.float64]: | ||
zone = lfr.create_array(array_shape, zone_dtype, zone_fill_value) | ||
suitability = lfr.create_array( | ||
array_shape, floating_point_type, suitability_fill_value | ||
) | ||
route = lfr.decreasing_order(zone, suitability, max_nr_cells) | ||
|
||
crop_fractions = [ | ||
lfr.create_array(array_shape, floating_point_type, zone_fill_value), | ||
lfr.create_array(array_shape, floating_point_type, zone_fill_value), | ||
lfr.create_array(array_shape, floating_point_type, zone_fill_value), | ||
] | ||
|
||
( | ||
crop_fractions_we_got, | ||
zonal_production_we_got, | ||
) = img.integrate_and_allocate(route, zone, crop_fractions) | ||
|
||
self.assertTrue(isinstance(crop_fractions_we_got, list)) | ||
# TODO self.assertEqual(len(crop_fractions_we_got), nr_crops) | ||
|
||
self.assertTrue(isinstance(zonal_production_we_got, dict)) | ||
# TODO self.assertEqual(len(zonal_production_we_got), nr_crops) |
11 changes: 11 additions & 0 deletions
11
source/framework/image_land/src/integrate_and_allocate.cpp.in
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,11 @@ | ||
#include "lue/framework/algorithm/definition/integrate_and_allocate.hpp" | ||
#include "lue/framework/algorithm/value_policies/integrate_and_allocate.hpp" | ||
|
||
|
||
namespace lue { | ||
|
||
LUE_INSTANTIATE_INTEGRATE_AND_ALLOCATE( | ||
ESC(policy::integrate_and_allocate::{{ Policies }}<{{ ZoneElement }}, {{ FloatingPointElement }}>), | ||
{{ rank }}); | ||
|
||
} // namespace lue |
11 changes: 11 additions & 0 deletions
11
source/framework/image_land/test/integrate_and_allocate_test.cpp
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,11 @@ | ||
#define BOOST_TEST_MODULE lue framework image_land integrate_and_allocate | ||
#include "lue/framework/algorithm/value_policies/integrate_and_allocate.hpp" | ||
#include "lue/framework/test/array.hpp" | ||
#include "lue/framework/test/compare.hpp" | ||
#include "lue/framework/test/hpx_unit_test.hpp" | ||
|
||
|
||
BOOST_AUTO_TEST_CASE(use_case_01) | ||
{ | ||
// TODO | ||
} |
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