Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added conversion functions for layouts of different coordinate types #125

Merged
merged 25 commits into from
Mar 2, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f76860b
:sparkles: functions to convert layouts to a new layout based on a ne…
Feb 12, 2023
dfa2269
Merge branch 'main' into siqad_coodinates_to_fiction_vs
Feb 12, 2023
e40fbc1
:sparkles: functions to convert layouts to a new layout based on a ne…
Feb 12, 2023
d7de6c3
:art: put functions in different header, added missing attributes, up…
Feb 13, 2023
514b990
:memo: docu updated
Feb 13, 2023
2a058a3
:art: new function to shift layout to positive coordinates
Feb 13, 2023
35e3728
:art: new function to shift layout to positive coordinates
Feb 13, 2023
f46f4e3
:art: updated Marcel's suggestions
Feb 13, 2023
c258e70
:art: reformat code
Feb 13, 2023
8ea6c24
:art: reformat code
Feb 13, 2023
1e04450
:art: reformat code
Feb 13, 2023
5139d74
Delete sidb_surface_analysis.hpp
Drewniok Feb 14, 2023
05111ad
:art: reformat code
Feb 14, 2023
1388803
:art: updated Marcel's suggestions
Feb 15, 2023
1bbf6a2
:memo: Adjusted docstrings
marcelwa Feb 15, 2023
abb53e5
:art: Renamed functions
marcelwa Feb 15, 2023
dd7b264
:art: Fixed code duplication
marcelwa Feb 15, 2023
432449d
:art: Restructured tests
marcelwa Feb 15, 2023
919ddd7
:test_tube: Added failing tests
marcelwa Feb 15, 2023
c26d134
:art: aspect-ratio added for copy process
Feb 15, 2023
c3fc617
:art: aspect-ratio added for copy process
Feb 15, 2023
bc6ed9e
:art: aspect-ratio added for copy process
Feb 16, 2023
04c7b66
Merge branch 'main' into siqad_coodinates_to_fiction_vs
Drewniok Feb 17, 2023
bbb9721
Merge branch 'main' into siqad_coodinates_to_fiction_vs
Drewniok Feb 19, 2023
23db248
Merge branch 'main' into siqad_coodinates_to_fiction_vs
marcelwa Mar 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions include/fiction/layouts/layout_fiction_coordinates_to_siqad.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Created by Jan Drewniok on 11.02.23.
//

#ifndef FICTION_LAYOUT_SIQAD_COORDINATES_TO_FICTION_HPP
#define FICTION_LAYOUT_SIQAD_COORDINATES_TO_FICTION_HPP

#include "fiction/layouts/cell_level_layout.hpp"
#include "fiction/layouts/coordinates.hpp"
#include "fiction/traits.hpp"
#include "fiction/types.hpp"

namespace fiction
{
/**
* The cell coordinates of a given layout are converted to SiQAD coordinates. A new layout with SiQAD coordinates is
* returned.
*
* @tparam Lyt Cell-level layout based on Fiction coordinates (Cube, Offset).
* @param lyt The given layout which is converted to a new layout based on SiQAD coordinates.
* @return new layout based on SiQAD coordinates.
*/
template <typename Lyt>
sidb_cell_clk_lyt_siqad lyt_coordinates_to_siqad(const Lyt& lyt)
{
sidb_cell_clk_lyt_siqad lyt_new{};
lyt.foreach_cell([&lyt_new, &lyt](const auto& c)
{ lyt_new.assign_cell_type(siqad::to_siqad_coord<cell<Lyt>>(c), lyt.get_cell_type(c)); });
return lyt_new;
}

} // namespace fiction

#endif // FICTION_LAYOUT_SIQAD_COORDINATES_TO_FICTION_HPP
35 changes: 35 additions & 0 deletions include/fiction/layouts/layout_siqad_coordinates_to_fiction.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by Jan Drewniok on 11.02.23.
//

#ifndef FICTION_LAYOUT_SIQAD_COORDINATES_TO_FICTION_HPP
#define FICTION_LAYOUT_SIQAD_COORDINATES_TO_FICTION_HPP

#include "fiction/layouts/cell_level_layout.hpp"
#include "fiction/layouts/coordinates.hpp"
#include "fiction/traits.hpp"
#include "fiction/types.hpp"

namespace fiction
{
/**
* The cell coordinates of a given layout are converted to Fiction coordinates. A new layout with Fiction coordinates is
* returned.
*
* @tparam Lyt Cell-level layout based on SiQAD coordinates.
* @param lyt The given layout which is converted to a new layout based on Fiction coordinates.
* @return New layout based on Fiction coordinates.
*/
template <typename Lyt>
sidb_cell_clk_lyt lyt_coordinates_to_fiction(const Lyt& lyt)
{
sidb_cell_clk_lyt lyt_new{};
lyt.foreach_cell(
[&lyt_new, &lyt](const auto& c)
{ lyt_new.assign_cell_type(siqad::to_fiction_coord<sidb_cell_clk_lyt::cell>(c), lyt.get_cell_type(c)); });
return lyt_new;
}

} // namespace fiction

#endif // FICTION_LAYOUT_SIQAD_COORDINATES_TO_FICTION_HPP
44 changes: 44 additions & 0 deletions test/layouts/layout_fiction_coordinates_to_siqad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Created by Jan Drewniok on 12.02.23.
//

#include <catch2/catch_template_test_macros.hpp>

#include <fiction/layouts/cartesian_layout.hpp>
#include <fiction/layouts/cell_level_layout.hpp>
#include <fiction/layouts/layout_fiction_coordinates_to_siqad.hpp>
#include <fiction/technology/cell_technologies.hpp>

using namespace fiction;

TEMPLATE_TEST_CASE("Cell-level layout trait", "[layout_fiction_coordinates_to_siqad]", sidb_cell_clk_lyt)
{
SECTION("empty layout")
{
TestType lyt{{10, 10}};
auto lyt_transformed = lyt_coordinates_to_siqad<TestType>(lyt);
CHECK(lyt_transformed.is_empty());
}

SECTION("layout with one cell")
{
TestType lyt{};
lyt.assign_cell_type({5, 3}, TestType::cell_type::NORMAL);
auto lyt_transformed = lyt_coordinates_to_siqad<TestType>(lyt);
CHECK(lyt_transformed.num_cells() == 1);
CHECK(lyt_transformed.get_cell_type({5, 1, 1}) == TestType::cell_type::NORMAL);
}

SECTION("layout with three cells")
{
TestType lyt{};
lyt.assign_cell_type({0, 0}, TestType::cell_type::NORMAL);
lyt.assign_cell_type({5, 3}, TestType::cell_type::NORMAL);
lyt.assign_cell_type({5, 1}, TestType::cell_type::NORMAL);
auto lyt_transformed = lyt_coordinates_to_siqad<TestType>(lyt);
CHECK(lyt_transformed.num_cells() == 3);
CHECK(lyt_transformed.get_cell_type({0, 0, 0}) == TestType::cell_type::NORMAL);
CHECK(lyt_transformed.get_cell_type({5, 1, 1}) == TestType::cell_type::NORMAL);
CHECK(lyt_transformed.get_cell_type({5, 0, 1}) == TestType::cell_type::NORMAL);
}
}
44 changes: 44 additions & 0 deletions test/layouts/layout_siqad_coordinates_to_fiction.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Created by Jan Drewniok on 12.02.23.
//

#include <catch2/catch_template_test_macros.hpp>

#include <fiction/layouts/cartesian_layout.hpp>
#include <fiction/layouts/cell_level_layout.hpp>
#include <fiction/layouts/layout_siqad_coordinates_to_fiction.hpp>
#include <fiction/technology/cell_technologies.hpp>

using namespace fiction;

TEMPLATE_TEST_CASE("Cell-level layout traits", "[layout_siqad_coordinates_to_fiction]", sidb_cell_clk_lyt_siqad)
{
SECTION("empty layout")
{
TestType lyt{};
auto lyt_transformed = lyt_coordinates_to_fiction<TestType>(lyt);
CHECK(lyt_transformed.is_empty());
}

SECTION("layout with one cell")
{
TestType lyt{};
lyt.assign_cell_type({5, 3}, TestType::cell_type::NORMAL);
auto lyt_transformed = lyt_coordinates_to_fiction<TestType>(lyt);
CHECK(lyt_transformed.num_cells() == 1);
CHECK(lyt_transformed.get_cell_type({5, 6}) == TestType::cell_type::NORMAL);
}

SECTION("layout with three cells")
{
TestType lyt{};
lyt.assign_cell_type({5, 3}, TestType::cell_type::NORMAL);
lyt.assign_cell_type({0, 0}, TestType::cell_type::NORMAL);
lyt.assign_cell_type({5, 1}, TestType::cell_type::NORMAL);
auto lyt_transformed = lyt_coordinates_to_fiction<TestType>(lyt);
CHECK(lyt_transformed.num_cells() == 3);
CHECK(lyt_transformed.get_cell_type({5, 6}) == TestType::cell_type::NORMAL);
CHECK(lyt_transformed.get_cell_type({5, 2}) == TestType::cell_type::NORMAL);
CHECK(lyt_transformed.get_cell_type({0, 0}) == TestType::cell_type::NORMAL);
}
}