From 0ddc7e8ed9e0326f11f18ef495709a47e6cbc34f Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Tue, 31 Jul 2018 22:06:09 -0400 Subject: [PATCH 01/12] csc_hdf5_write first pass --- phylanx/plugins/fileio/csc_hdf5_write.hpp | 55 ++++++ src/plugins/fileio/csc_write_hdf5.cpp | 194 ++++++++++++++++++++++ 2 files changed, 249 insertions(+) create mode 100644 phylanx/plugins/fileio/csc_hdf5_write.hpp create mode 100644 src/plugins/fileio/csc_write_hdf5.cpp diff --git a/phylanx/plugins/fileio/csc_hdf5_write.hpp b/phylanx/plugins/fileio/csc_hdf5_write.hpp new file mode 100644 index 000000000..b84b6b38a --- /dev/null +++ b/phylanx/plugins/fileio/csc_hdf5_write.hpp @@ -0,0 +1,55 @@ +// Copyright (c) 2017 Alireza Kheirkhahan +// Copyright (c) 2018 Chris Taylor +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#pragma once +#ifndef __CSCHDF5WRITE__ +#define __CSCHDF5WRITE__ + +#include + +#if defined(PHYLANX_HAVE_HIGHFIVE) +#include +#include + +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace phylanx { namespace execution_tree { namespace primitives +{ + class csc_write_hdf5 : public primitive_component_base + { + public: + static match_pattern_type const match_data; + + csc_write_hdf5() = default; + + csc_write_hdf5(std::vector&& operands, + std::string const& name, std::string const& codename); + + hpx::future eval( + std::vector const& args) const override; + }; + + inline primitive create_csc_write_hdf5(hpx::id_type const& locality, + std::vector&& operands, + std::string const& name = "", std::string const& codename = "") + { + return create_primitive_component( + locality, "csc_write_hdf5", std::move(operands), name, codename); + } +}}} + +#endif +#endif diff --git a/src/plugins/fileio/csc_write_hdf5.cpp b/src/plugins/fileio/csc_write_hdf5.cpp new file mode 100644 index 000000000..f8809fe3a --- /dev/null +++ b/src/plugins/fileio/csc_write_hdf5.cpp @@ -0,0 +1,194 @@ +// Copyright (c) 2018 Alireza Kheirkhahan +// Copyright (c) 2018 Chris Taylor +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +#if defined(PHYLANX_HAVE_HIGHFIVE) +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +namespace phylanx { namespace execution_tree { namespace primitives +{ + + template + void writeDataSpace(HighFive::File & file + , std::string const& hdf5_group_name + , blaze::CompressedMatrix const& data); + + template + void writeDataSpace(HighFive::File & file + , std::string const& hdf5_group_name + , blaze::CompressedMatrix const& data) { + + using namespace HighFive; + + Group grp = file.createGroup(hdf5_group_name); + std::string const desc("csc"); + std::string const fmtkey("h5sparse_format"); + Attribute fmt = grp.createAttribute< std::string >(fmtkey, DataSpace::From(desc)); + fmt.write(desc); + + std::string const shapekey("h5sparse_shape"); + std::vector< std::int64_t > const dims{ + static_cast(data.rows()) + , static_cast(data.columns()) + }; + + Attribute shape = grp.createAttribut(shapekey, DataSpace::From(dims)); + shape.write(dims); + + std::vector values; + std::vector indices; + std::vector indptr{0}; + + for(std::int64_t i = 0; i < dims[0]; ++i) { + for(std::int64_t j = 0; j < dims[1]; ++j) { + if(data(i,j) != 0) { + values.push_back(data(i,j)); + indices.push_back(j); + } + + indptr.push_back(indices.size()); + } + } + + std::string const indiceskey("indices"); + DataSet dset_indices = grp.createDataSet(indiceskey, DataSpace::From(indices)); + + std::string const datakey("data"); + DataSet dset_data = grp.createDataSet(datakey, DataSpace::From(values)); + + std::string const indptrkey("indptr"); + DataSet dset_indptr = grp.createDataSet(indptrkey, DataSpace::From(indptr)); + + dset_indices.write(indices); + dset_data.write(values); + dset_indptr.write(indptr); + + file.flush(); + } + + /////////////////////////////////////////////////////////////////////////// + match_pattern_type const csc_write_hdf5::match_data = + { + hpx::util::make_tuple("csc_write_hdf5", + std::vector{"csc_write_hdf5(_1, _2, _3)"}, + &create_csc_write_hdf5, &create_primitive) + }; + + /////////////////////////////////////////////////////////////////////////// + csc_write_hdf5::csc_write_hdf5( + std::vector && operands, + std::string const& name, std::string const& codename) + : primitive_component_base(std::move(operands), name, codename) + { + } + + void csc_write_hdf5::write_to_file_hdf5(ir::node_data const& val, + std::string const& filename, std::string const& dataset_name) const + { + HighFive::File outfile(filename, + HighFive::File::ReadWrite | HighFive::File::Create | + HighFive::File::Truncate); + + auto const dims = val.num_dimensions(); + if(dims > 0 && dims < 3) + { + auto matrix = val.matrix(); + HighFive::DataSet dataSet = + outfile.createDataSet( + dataset_name, HighFive::DataSpace(dims)); + + writeDataSpace(outfile, dataset_name, matrix); + } + } + + hpx::future csc_write_hdf5::eval( + std::vector const& operands, + std::vector const& args) const + { + if (operands.size() != 3) + { + HPX_THROW_EXCEPTION(hpx::bad_parameter, + "phylanx::execution_tree::primitives::file_write::csc_write_hdf5", + util::generate_error_message( + "the file_write primitive requires exactly three operands", + name_, codename_)); + } + + if (!valid(operands[0]) || !valid(operands[1]) || + !valid(operands[2])) + { + HPX_THROW_EXCEPTION(hpx::bad_parameter, + "phylanx::execution_tree::primitives::file_write::csc_write_hdf5", + util::generate_error_message( + "the file_write primitive requires that the given operands " + "are valid", + name_, codename_)); + } + + std::string filename = + string_operand_sync(operands[0], args, name_, codename_); + std::string dataset_name = + string_operand_sync(operands[1], args, name_, codename_); + + auto this_ = this->shared_from_this(); + return numeric_operand(operands[2], args, name_, codename_) + .then(hpx::launch::sync, hpx::util::unwrapping( + [this_, filename = std::move(filename), + dataset_name = std::move(dataset_name)]( + ir::node_data&& val) -> primitive_argument_type + { + if (!valid(val)) + { + HPX_THROW_EXCEPTION(hpx::bad_parameter, + "csc_write_hdf5::eval", + util::generate_error_message( + "the csc_write_hdf5 primitive requires that " + "the argument value given by the operand is " + "non-empty", + this_->name_, this_->codename_)); + } + + this_->write_to_file_hdf5(val, std::move(filename), + std::move(dataset_name)); + return primitive_argument_type(std::move(val)); + })); + } + + /////////////////////////////////////////////////////////////////////////// + // write data to given file in hdf5 format and return content + hpx::future csc_write_hdf5::eval( + std::vector const& args) const + { + if (this->no_operands()) + { + return eval(args, noargs); + } + return eval(this->operands(), args); + } +}}} + +#endif From 47288c421b254f3227ae4c6ddfc1ba9c0a087e99 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Tue, 31 Jul 2018 22:20:43 -0400 Subject: [PATCH 02/12] added readops --- phylanx/plugins/fileio/csc_read_hdf5.hpp | 55 ++++++ ...{csc_hdf5_write.hpp => csc_write_hdf5.hpp} | 0 src/plugins/fileio/csc_read_hdf5.cpp | 184 ++++++++++++++++++ 3 files changed, 239 insertions(+) create mode 100644 phylanx/plugins/fileio/csc_read_hdf5.hpp rename phylanx/plugins/fileio/{csc_hdf5_write.hpp => csc_write_hdf5.hpp} (100%) create mode 100644 src/plugins/fileio/csc_read_hdf5.cpp diff --git a/phylanx/plugins/fileio/csc_read_hdf5.hpp b/phylanx/plugins/fileio/csc_read_hdf5.hpp new file mode 100644 index 000000000..93a922d56 --- /dev/null +++ b/phylanx/plugins/fileio/csc_read_hdf5.hpp @@ -0,0 +1,55 @@ +// Copyright (c) 2017 Alireza Kheirkhahan +// Copyright (c) 2018 Chris Taylor +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#pragma once +#ifndef __CSCHDF5WRITE__ +#define __CSCHDF5WRITE__ + +#include + +#if defined(PHYLANX_HAVE_HIGHFIVE) +#include +#include + +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +namespace phylanx { namespace execution_tree { namespace primitives +{ + class csc_read_hdf5 : public primitive_component_base + { + public: + static match_pattern_type const match_data; + + csc_read_hdf5() = default; + + csc_read_hdf5(std::vector&& operands, + std::string const& name, std::string const& codename); + + hpx::future eval( + std::vector const& args) const override; + }; + + inline primitive create_csc_read_hdf5(hpx::id_type const& locality, + std::vector&& operands, + std::string const& name = "", std::string const& codename = "") + { + return create_primitive_component( + locality, "csc_read_hdf5", std::move(operands), name, codename); + } +}}} + +#endif +#endif diff --git a/phylanx/plugins/fileio/csc_hdf5_write.hpp b/phylanx/plugins/fileio/csc_write_hdf5.hpp similarity index 100% rename from phylanx/plugins/fileio/csc_hdf5_write.hpp rename to phylanx/plugins/fileio/csc_write_hdf5.hpp diff --git a/src/plugins/fileio/csc_read_hdf5.cpp b/src/plugins/fileio/csc_read_hdf5.cpp new file mode 100644 index 000000000..0cdb54147 --- /dev/null +++ b/src/plugins/fileio/csc_read_hdf5.cpp @@ -0,0 +1,184 @@ +// Copyright (c) 2018 Alireza Kheirkhahan +// Copyright (c) 2018 Chris Taylor +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +#if defined(PHYLANX_HAVE_HIGHFIVE) +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +namespace phylanx { namespace execution_tree { namespace primitives +{ + + template + void marshal(HighFive::File & file + , std::string const& hdf5_group_name + , blaze::CompressedMatrix & data); + + template + void marshal(HighFive::File & file + , std::string const& hdf5_group_name + , blaze::CompressedMatrix & data) { + + using namespace HighFive; + + Group grp = file.getGroup(hdf5_group_name); + std::string const desc("csc"); + + std::string const fmtkey("h5sparse_format"); + Attribute fmt = grp.getAttribute< std::string >(fmtkey, DataSpace::From(desc)); + std:string smat_fmt; + fmt.read(smat_fmt); + + if(!smat_fmt.equals(desc)) { + //TODO: how does error handling work? + } + + std::string const shapekey("h5sparse_shape"); + std::vector< std::int64_t > dims(2); + Attribute shape = grp.getAttribute(shapekey); + shape.read(dims); + + data.resize(dims[0], dims[1], false); + + std::string const indiceskey("indices"); + DataSet dset_indices = grp.getDataSet(indiceskey); + std::string const datakey("data"); + DataSet dset_data = grp.getDataSet(datakey); + std::string const indptrkey("indptr"); + DataSet dset_indptr = grp.getDataSet(indptrkey); + + std::vector values; + std::vector indices; + std::vector indptr; + + dset_data.read(values); + dset_indices.read(indices); + dset_indptr.read(indptr); + + for(std::int64_t i = 0; i < dims[1]; ++i) { + for(std::int64_t j = indptr[i]; j < indptr[i+1]; ++j) { + data(i, indices[j]) = values[j]; + } + } + } + + /////////////////////////////////////////////////////////////////////////// + match_pattern_type const csc_read_hdf5::match_data = + { + hpx::util::make_tuple("csc_read_hdf5", + std::vector{"csc_read_hdf5(_1, _2, _3)"}, + &create_csc_read_hdf5, &create_primitive) + }; + + /////////////////////////////////////////////////////////////////////////// + csc_read_hdf5::csc_read_hdf5( + std::vector && operands, + std::string const& name, std::string const& codename) + : primitive_component_base(std::move(operands), name, codename) + { + } + + void csc_read_hdf5::read_to_file_hdf5(ir::node_data const& val, + std::string const& filename, std::string const& dataset_name) const + { + HighFive::File infile(filename, HighFive::File::ReadOnly); + + auto const dims = val.num_dimensions(); + if(dims > 0 && dims < 3) + { + blaze::DynamicMatrix matrix; + marshal(infile, dataset_name, matrix); + } + // TODO: error handling? + } + + hpx::future csc_read_hdf5::eval( + std::vector const& operands, + std::vector const& args) const + { + if (operands.size() != 3) + { + HPX_THROW_EXCEPTION(hpx::bad_parameter, + "phylanx::execution_tree::primitives::file_read::csc_read_hdf5", + util::generate_error_message( + "the csc_read_hdf5 primitive requires exactly three operands", + name_, codename_)); + } + + if (!valid(operands[0]) || !valid(operands[1]) || + !valid(operands[2])) + { + HPX_THROW_EXCEPTION(hpx::bad_parameter, + "phylanx::execution_tree::primitives::csc_read_hdf5::csc_read_hdf5", + util::generate_error_message( + "the csc_read_hdf5 primitive requires that the given operands " + "are valid", + name_, codename_)); + } + + std::string filename = + string_operand_sync(operands[0], args, name_, codename_); + std::string dataset_name = + string_operand_sync(operands[1], args, name_, codename_); + + auto this_ = this->shared_from_this(); + return numeric_operand(operands[2], args, name_, codename_) + .then(hpx::launch::sync, hpx::util::unwrapping( + [this_, filename = std::move(filename), + dataset_name = std::move(dataset_name)]( + ir::node_data&& val) -> primitive_argument_type + { + if (!valid(val)) + { + HPX_THROW_EXCEPTION(hpx::bad_parameter, + "csc_read_hdf5::eval", + util::generate_error_message( + "the csc_read_hdf5 primitive requires that " + "the argument value given by the operand is " + "non-empty", + this_->name_, this_->codename_)); + } + + this_->write_to_file_hdf5(val, std::move(filename), + std::move(dataset_name)); + return primitive_argument_type(std::move(val)); + })); + } + + /////////////////////////////////////////////////////////////////////////// + // write data to given file in hdf5 format and return content + hpx::future csc_read_hdf5::eval( + std::vector const& args) const + { + if (this->no_operands()) + { + return eval(args, noargs); + } + return eval(this->operands(), args); + } +}}} + +#endif From 95948d1453ba39b021f8caf6598c0c0353871e9e Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Tue, 31 Jul 2018 22:22:40 -0400 Subject: [PATCH 03/12] renamed write op --- src/plugins/fileio/csc_write_hdf5.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/plugins/fileio/csc_write_hdf5.cpp b/src/plugins/fileio/csc_write_hdf5.cpp index f8809fe3a..b029d910d 100644 --- a/src/plugins/fileio/csc_write_hdf5.cpp +++ b/src/plugins/fileio/csc_write_hdf5.cpp @@ -33,12 +33,12 @@ namespace phylanx { namespace execution_tree { namespace primitives { template - void writeDataSpace(HighFive::File & file + void serialize(HighFive::File & file , std::string const& hdf5_group_name , blaze::CompressedMatrix const& data); template - void writeDataSpace(HighFive::File & file + void serialize(HighFive::File & file , std::string const& hdf5_group_name , blaze::CompressedMatrix const& data) { @@ -121,7 +121,7 @@ namespace phylanx { namespace execution_tree { namespace primitives outfile.createDataSet( dataset_name, HighFive::DataSpace(dims)); - writeDataSpace(outfile, dataset_name, matrix); + serialize(outfile, dataset_name, matrix); } } From d9ec53941b73842e250c4209e6e3b84480b65766 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Tue, 31 Jul 2018 22:24:34 -0400 Subject: [PATCH 04/12] small fix; removed unnecessary code --- src/plugins/fileio/csc_write_hdf5.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/plugins/fileio/csc_write_hdf5.cpp b/src/plugins/fileio/csc_write_hdf5.cpp index b029d910d..8885235ab 100644 --- a/src/plugins/fileio/csc_write_hdf5.cpp +++ b/src/plugins/fileio/csc_write_hdf5.cpp @@ -117,11 +117,7 @@ namespace phylanx { namespace execution_tree { namespace primitives if(dims > 0 && dims < 3) { auto matrix = val.matrix(); - HighFive::DataSet dataSet = - outfile.createDataSet( - dataset_name, HighFive::DataSpace(dims)); - - serialize(outfile, dataset_name, matrix); + serialize(filename, dataset_name, matrix); } } From 6fff8fa8beb8aa8512db96223a473a0b5de3c6dd Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Tue, 31 Jul 2018 22:27:56 -0400 Subject: [PATCH 05/12] fixed define bug --- phylanx/plugins/fileio/csc_read_hdf5.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phylanx/plugins/fileio/csc_read_hdf5.hpp b/phylanx/plugins/fileio/csc_read_hdf5.hpp index 93a922d56..dfe81aa92 100644 --- a/phylanx/plugins/fileio/csc_read_hdf5.hpp +++ b/phylanx/plugins/fileio/csc_read_hdf5.hpp @@ -4,8 +4,8 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #pragma once -#ifndef __CSCHDF5WRITE__ -#define __CSCHDF5WRITE__ +#ifndef __CSCHDF5READ__ +#define __CSCHDF5READ__ #include From 7d0feb91cc1509d622f6a7baf039af68faea55a9 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Tue, 31 Jul 2018 22:29:18 -0400 Subject: [PATCH 06/12] renamed defines --- phylanx/plugins/fileio/csc_read_hdf5.hpp | 4 ++-- phylanx/plugins/fileio/csc_write_hdf5.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/phylanx/plugins/fileio/csc_read_hdf5.hpp b/phylanx/plugins/fileio/csc_read_hdf5.hpp index dfe81aa92..317283ab0 100644 --- a/phylanx/plugins/fileio/csc_read_hdf5.hpp +++ b/phylanx/plugins/fileio/csc_read_hdf5.hpp @@ -4,8 +4,8 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #pragma once -#ifndef __CSCHDF5READ__ -#define __CSCHDF5READ__ +#ifndef __CSCREADHDF5__ +#define __CSCREADHDF5__ #include diff --git a/phylanx/plugins/fileio/csc_write_hdf5.hpp b/phylanx/plugins/fileio/csc_write_hdf5.hpp index b84b6b38a..b48b1d6e9 100644 --- a/phylanx/plugins/fileio/csc_write_hdf5.hpp +++ b/phylanx/plugins/fileio/csc_write_hdf5.hpp @@ -4,8 +4,8 @@ // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #pragma once -#ifndef __CSCHDF5WRITE__ -#define __CSCHDF5WRITE__ +#ifndef __CSCWRITEHDF5__ +#define __CSCWRITEHDF5__ #include From 2598b1021bda164e23dda04afb1715bb402a93f3 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Tue, 31 Jul 2018 22:56:35 -0400 Subject: [PATCH 07/12] renamed things --- src/plugins/fileio/csc_write_hdf5.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/plugins/fileio/csc_write_hdf5.cpp b/src/plugins/fileio/csc_write_hdf5.cpp index 8885235ab..431f4da4b 100644 --- a/src/plugins/fileio/csc_write_hdf5.cpp +++ b/src/plugins/fileio/csc_write_hdf5.cpp @@ -128,9 +128,9 @@ namespace phylanx { namespace execution_tree { namespace primitives if (operands.size() != 3) { HPX_THROW_EXCEPTION(hpx::bad_parameter, - "phylanx::execution_tree::primitives::file_write::csc_write_hdf5", + "phylanx::execution_tree::primitives::csc_write_hdf5::csc_write_hdf5", util::generate_error_message( - "the file_write primitive requires exactly three operands", + "the csc_write_hdf5 primitive requires exactly three operands", name_, codename_)); } @@ -138,9 +138,9 @@ namespace phylanx { namespace execution_tree { namespace primitives !valid(operands[2])) { HPX_THROW_EXCEPTION(hpx::bad_parameter, - "phylanx::execution_tree::primitives::file_write::csc_write_hdf5", + "phylanx::execution_tree::primitives::csc_write_hdf5::csc_write_hdf5", util::generate_error_message( - "the file_write primitive requires that the given operands " + "the csc_write_hdf5 primitive requires that the given operands " "are valid", name_, codename_)); } From 92747031b84e2fd9171c988ac737c60bbc50a1b4 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Wed, 1 Aug 2018 07:44:15 -0400 Subject: [PATCH 08/12] added headers --- phylanx/plugins/fileio/fileio.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phylanx/plugins/fileio/fileio.hpp b/phylanx/plugins/fileio/fileio.hpp index fbe346288..25bdfcfb0 100644 --- a/phylanx/plugins/fileio/fileio.hpp +++ b/phylanx/plugins/fileio/fileio.hpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #endif From c33c25c3a95b56caaf526ea5e23783fdeab0d727 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Wed, 1 Aug 2018 22:19:20 -0400 Subject: [PATCH 09/12] typeoh --- phylanx/plugins/fileio/csc_read_hdf5.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phylanx/plugins/fileio/csc_read_hdf5.hpp b/phylanx/plugins/fileio/csc_read_hdf5.hpp index 317283ab0..c57611a7a 100644 --- a/phylanx/plugins/fileio/csc_read_hdf5.hpp +++ b/phylanx/plugins/fileio/csc_read_hdf5.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include From 686d52efeac42f5fd614aa893c0368781ddfd771 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Thu, 2 Aug 2018 00:24:09 -0400 Subject: [PATCH 10/12] header file typeoh --- phylanx/plugins/fileio/csc_write_hdf5.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phylanx/plugins/fileio/csc_write_hdf5.hpp b/phylanx/plugins/fileio/csc_write_hdf5.hpp index b48b1d6e9..f1e0f4cad 100644 --- a/phylanx/plugins/fileio/csc_write_hdf5.hpp +++ b/phylanx/plugins/fileio/csc_write_hdf5.hpp @@ -16,7 +16,7 @@ #include #include -#include +#include #include #include From d0f56ccd7408011ff66380a3450e405e46d645d4 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Thu, 2 Aug 2018 00:31:30 -0400 Subject: [PATCH 11/12] integration with cmake --- src/plugins/fileio/CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/plugins/fileio/CMakeLists.txt b/src/plugins/fileio/CMakeLists.txt index 923cad48d..a44ce149d 100644 --- a/src/plugins/fileio/CMakeLists.txt +++ b/src/plugins/fileio/CMakeLists.txt @@ -22,8 +22,10 @@ if(PHYLANX_WITH_HIGHFIVE) set(headers ${headers} "${PROJECT_SOURCE_DIR}/phylanx/plugins/fileio/file_read_hdf5.hpp" "${PROJECT_SOURCE_DIR}/phylanx/plugins/fileio/file_write_hdf5.hpp" + "${PROJECT_SOURCE_DIR}/phylanx/plugins/fileio/csc_read_hdf5.hpp" + "${PROJECT_SOURCE_DIR}/phylanx/plugins/fileio/csc_write_hdf5.hpp" ) - set(sources ${sources} "file_read_hdf5.cpp" "file_write_hdf5.cpp") + set(sources ${sources} "file_read_hdf5.cpp" "file_write_hdf5.cpp" "csc_read_hdf5.cpp" "csc_write_hdf5.cpp") endif() add_phylanx_primitive_plugin(fileio From 31d6d1013c80eb5103040abe79e054302652c415 Mon Sep 17 00:00:00 2001 From: ct-clmsn Date: Thu, 2 Aug 2018 07:26:13 -0400 Subject: [PATCH 12/12] compressedmatrix not supported? --- src/plugins/fileio/csc_read_hdf5.cpp | 85 +++++++--------------------- 1 file changed, 22 insertions(+), 63 deletions(-) diff --git a/src/plugins/fileio/csc_read_hdf5.cpp b/src/plugins/fileio/csc_read_hdf5.cpp index 0cdb54147..6cb1c60e0 100644 --- a/src/plugins/fileio/csc_read_hdf5.cpp +++ b/src/plugins/fileio/csc_read_hdf5.cpp @@ -48,11 +48,11 @@ namespace phylanx { namespace execution_tree { namespace primitives std::string const desc("csc"); std::string const fmtkey("h5sparse_format"); - Attribute fmt = grp.getAttribute< std::string >(fmtkey, DataSpace::From(desc)); - std:string smat_fmt; + Attribute fmt = grp.getAttribute(fmtkey); + std::string smat_fmt; fmt.read(smat_fmt); - if(!smat_fmt.equals(desc)) { + if(smat_fmt.compare(desc) == 0) { //TODO: how does error handling work? } @@ -101,83 +101,42 @@ namespace phylanx { namespace execution_tree { namespace primitives { } - void csc_read_hdf5::read_to_file_hdf5(ir::node_data const& val, - std::string const& filename, std::string const& dataset_name) const - { - HighFive::File infile(filename, HighFive::File::ReadOnly); - - auto const dims = val.num_dimensions(); - if(dims > 0 && dims < 3) - { - blaze::DynamicMatrix matrix; - marshal(infile, dataset_name, matrix); - } - // TODO: error handling? - } - hpx::future csc_read_hdf5::eval( - std::vector const& operands, std::vector const& args) const { - if (operands.size() != 3) + if (operands_.size() != 2) { HPX_THROW_EXCEPTION(hpx::bad_parameter, - "phylanx::execution_tree::primitives::file_read::csc_read_hdf5", + "phylanx::execution_tree::primitives::file_read_hdf5::eval", util::generate_error_message( - "the csc_read_hdf5 primitive requires exactly three operands", + "the file_read_hdf5 primitive requires exactly two " + "literal arguments", name_, codename_)); } - if (!valid(operands[0]) || !valid(operands[1]) || - !valid(operands[2])) + if (!valid(operands_[0]) || !valid(operands_[1])) { HPX_THROW_EXCEPTION(hpx::bad_parameter, - "phylanx::execution_tree::primitives::csc_read_hdf5::csc_read_hdf5", + "phylanx::execution_tree::primitives::file_read_hdf5::eval", util::generate_error_message( - "the csc_read_hdf5 primitive requires that the given operands " - "are valid", + "the file_read_hdf5 primitive requires that the given " + "operand is valid", name_, codename_)); } std::string filename = - string_operand_sync(operands[0], args, name_, codename_); - std::string dataset_name = - string_operand_sync(operands[1], args, name_, codename_); - - auto this_ = this->shared_from_this(); - return numeric_operand(operands[2], args, name_, codename_) - .then(hpx::launch::sync, hpx::util::unwrapping( - [this_, filename = std::move(filename), - dataset_name = std::move(dataset_name)]( - ir::node_data&& val) -> primitive_argument_type - { - if (!valid(val)) - { - HPX_THROW_EXCEPTION(hpx::bad_parameter, - "csc_read_hdf5::eval", - util::generate_error_message( - "the csc_read_hdf5 primitive requires that " - "the argument value given by the operand is " - "non-empty", - this_->name_, this_->codename_)); - } - - this_->write_to_file_hdf5(val, std::move(filename), - std::move(dataset_name)); - return primitive_argument_type(std::move(val)); - })); - } + string_operand_sync(operands_[0], args, name_, codename_); + std::string datasetName = + string_operand_sync(operands_[1], args, name_, codename_); - /////////////////////////////////////////////////////////////////////////// - // write data to given file in hdf5 format and return content - hpx::future csc_read_hdf5::eval( - std::vector const& args) const - { - if (this->no_operands()) - { - return eval(args, noargs); - } - return eval(this->operands(), args); + HighFive::File infile(filename, HighFive::File::ReadOnly); + // matrix + blaze::CompressedMatrix matrix; + marshal(infile, datasetName, matrix); + + return hpx::make_ready_future(primitive_argument_type{ + ir::node_data< blaze::CompressedMatrix >{std::move(matrix)}}); + }; } }}}