Skip to content
Snippets Groups Projects
Commit 0ed3a8b3 authored by Dmitriy Morozov's avatar Dmitriy Morozov Committed by Kitware Robot
Browse files

Merge topic 'save-load-function'


cf458947 Change Create/Destroy/Save/Load to std::function<...>
b29893bb Add NumPy to tests/io.cpp

Acked-by: default avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !61
parents 0f1c3877 cf458947
No related branches found
No related tags found
No related merge requests found
......@@ -17,10 +17,10 @@ namespace diy
typedef std::vector<Element> Elements;
typedef critical_resource<int, recursive_mutex> CInt;
typedef void* (*Create)();
typedef void (*Destroy)(void*);
typedef detail::Save Save;
typedef detail::Load Load;
using Create = std::function<void*()>;
using Destroy = std::function<void(void*)>;
using Save = detail::Save;
using Load = detail::Load;
public:
Collection(Create create__,
......
......@@ -15,8 +15,8 @@ namespace diy
{
namespace detail
{
typedef void (*Save)(const void*, BinaryBuffer& buf);
typedef void (*Load)(void*, BinaryBuffer& buf);
using Save = std::function<void(const void*, BinaryBuffer&)>;
using Load = std::function<void(void*, BinaryBuffer&)>;
struct FileBuffer: public BinaryBuffer
{
......
......@@ -2,6 +2,7 @@
#include "catch.hpp"
#include <diy/io/bov.hpp>
#include <diy/io/numpy.hpp>
#include <diy/mpi.hpp>
int full_data[4][3] = { { 1, 2, 3 },
......@@ -47,6 +48,45 @@ TEST_CASE("Test BOV", "[io]")
}
}
TEST_CASE("Test NumPy", "[io]")
{
diy::mpi::communicator world;
SECTION("test NumPy io")
{
{
std::vector<int> shape(2); shape[0] = 4; shape[1] = 3;
diy::mpi::io::file out(world, "test.npy", diy::mpi::io::file::wronly | diy::mpi::io::file::create);
diy::io::NumPy writer(out);
writer.write_header<int>(shape);
diy::DiscreteBounds sub_box { 2 };
sub_box.min[0] = 0; sub_box.min[1] = 0;
sub_box.max[0] = 1; sub_box.max[1] = 2;
writer.write(sub_box, &block1[0][0], sub_box);
sub_box.min[0] = 2; sub_box.min[1] = 0;
sub_box.max[0] = 3; sub_box.max[1] = 2;
writer.write(sub_box, &block2[0][0], sub_box);
}
diy::mpi::io::file in(world, "test.npy", diy::mpi::io::file::rdonly);
diy::io::NumPy reader(in);
reader.read_header();
diy::DiscreteBounds full_box {2};
full_box.min[0] = 0; full_box.min[1] = 0;
full_box.max[0] = 3; full_box.max[1] = 2;
reader.read(full_box, (int*) restored_data);
for (int x = 0; x < 4; ++x)
for (int y = 0; y < 3; ++y)
{
INFO("Coordinates " << x << " " << y);
CHECK(restored_data[x][y] == full_data[x][y]);
}
}
}
TEST_CASE("Test MPI-IO", "[io]")
{
diy::mpi::communicator world;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment