Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Feb 18, 2022
1 parent d497560 commit 0061bae
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 101 deletions.
27 changes: 16 additions & 11 deletions include/openPMD/IO/ADIOS/CommonADIOS1IOHandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,25 +96,30 @@ class CommonADIOS1IOHandlerImpl : public AbstractIOHandlerImpl
{}

ADIOS_READ_METHOD m_readMethod;
std::unordered_map< Writable*, std::shared_ptr< std::string > > m_filePaths;
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_groups;
std::unordered_map< std::shared_ptr< std::string >, bool > m_existsOnDisk;
std::unordered_map< std::shared_ptr< std::string >, int64_t > m_openWriteFileHandles;
std::unordered_map< std::shared_ptr< std::string >, ADIOS_FILE* > m_openReadFileHandles;
std::unordered_map<Writable *, std::shared_ptr<std::string> > m_filePaths;
std::unordered_map<std::shared_ptr<std::string>, int64_t> m_groups;
std::unordered_map<std::shared_ptr<std::string>, bool> m_existsOnDisk;
std::unordered_map<std::shared_ptr<std::string>, int64_t>
m_openWriteFileHandles;
std::unordered_map<std::shared_ptr<std::string>, ADIOS_FILE *>
m_openReadFileHandles;
struct ScheduledRead
{
ADIOS_SELECTION* selection;
std::shared_ptr< void > data; // needed to avoid early freeing
ADIOS_SELECTION *selection;
std::shared_ptr<void> data; // needed to avoid early freeing
};
std::unordered_map< ADIOS_FILE*, std::vector< ScheduledRead > > m_scheduledReads;
std::unordered_map< int64_t, std::unordered_map< std::string, Attribute > > m_attributeWrites;
std::unordered_map<ADIOS_FILE *, std::vector<ScheduledRead> >
m_scheduledReads;
std::unordered_map<int64_t, std::unordered_map<std::string, Attribute> >
m_attributeWrites;
// config options
std::string m_defaultTransform;
/**
* Call this function to get adios file id for a Writable. Will create one if does not exist
* Call this function to get adios file id for a Writable. Will create one
* if does not exist
* @return returns an adios file id.
*/
int64_t GetFileHandle(Writable*);
int64_t GetFileHandle(Writable *);

void initJson(json::TracingJSON);
}; // ParallelADIOS1IOHandlerImpl
Expand Down
24 changes: 12 additions & 12 deletions include/openPMD/backend/Attribute.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,27 +229,27 @@ template <typename U> U Attribute::get() const

namespace std
{
inline string to_string( openPMD::Attribute const & attr )
inline string to_string(openPMD::Attribute const &attr)
{
return std::visit(
[]( auto const & val ) {
using Val_t = remove_cv_t< remove_reference_t< decltype( val ) > >;
[](auto const &val) {
using Val_t = remove_cv_t<remove_reference_t<decltype(val)> >;

std::stringstream os;
if constexpr(
openPMD::auxiliary::IsVector_v< Val_t > ||
openPMD::auxiliary::IsArray_v< Val_t > )
if constexpr (
openPMD::auxiliary::IsVector_v<Val_t> ||
openPMD::auxiliary::IsArray_v<Val_t>)
{
if( val.empty() )
if (val.empty())
{
os << "[]";
}
else
{
os << "[" << val[ 0 ];
for( size_t i = 1; i < val.size(); ++i )
os << "[" << val[0];
for (size_t i = 1; i < val.size(); ++i)
{
os << ", " << val[ i ];
os << ", " << val[i];
}
os << "]";
}
Expand All @@ -260,6 +260,6 @@ inline string to_string( openPMD::Attribute const & attr )
}
return os.str();
},
attr.getResource() );
}
attr.getResource());
}
} // namespace std
2 changes: 1 addition & 1 deletion src/IO/ADIOS/ADIOS1IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ std::future<void> ADIOS1IOHandlerImpl::flush()
"[ADIOS1] Internal error: Failed to perform ADIOS reads during "
"dataset reading");

for( auto &sel : file.second )
for (auto &sel : file.second)
adios_selection_delete(sel.selection);
}
m_scheduledReads.clear();
Expand Down
39 changes: 22 additions & 17 deletions src/binding/python/Attributable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,23 +458,28 @@ void init_Attributable(py::module &m)
// double, 7 > >)

// C++ pass-through API: Getter
.def("get_attribute", []( Attributable & attr, std::string const& key ) {
auto v = attr.getAttribute(key);
std::cout << "Attribute '" << key << "' has type: " << v.dtype
<< std::endl
<< " and value: " << std::to_string(v) << std::endl;
return v.getResource();
// TODO instead of returning lists, return all arrays (ndim > 0) as numpy arrays?
})
.def_property_readonly("attribute_dtypes", []( Attributable const & attributable ) {
std::map< std::string, pybind11::dtype > dtypes;
for( auto const & attr : attributable.attributes() )
{
dtypes[ attr ] =
dtype_to_numpy( attributable.getAttribute( attr ).dtype );
}
return dtypes;
})
.def(
"get_attribute",
[](Attributable &attr, std::string const &key) {
auto v = attr.getAttribute(key);
std::cout << "Attribute '" << key << "' has type: " << v.dtype
<< std::endl
<< " and value: " << std::to_string(v) << std::endl;
return v.getResource();
// TODO instead of returning lists, return all arrays (ndim > 0)
// as numpy arrays?
})
.def_property_readonly(
"attribute_dtypes",
[](Attributable const &attributable) {
std::map<std::string, pybind11::dtype> dtypes;
for (auto const &attr : attributable.attributes())
{
dtypes[attr] =
dtype_to_numpy(attributable.getAttribute(attr).dtype);
}
return dtypes;
})
.def("delete_attribute", &Attributable::deleteAttribute)
.def("contains_attribute", &Attributable::containsAttribute)

Expand Down
12 changes: 6 additions & 6 deletions src/binding/python/PatchRecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ void init_PatchRecordComponent(py::module &m)

// allow one-element n-dimensional buffers as well
py::ssize_t numElements = 1;
if( buf.ndim > 0 )
if (buf.ndim > 0)
{
std::cout << "Buffer has dimensionality: " << buf.ndim
<< std::endl;
for( auto d = 0; d < buf.ndim; ++d )
<< std::endl;
for (auto d = 0; d < buf.ndim; ++d)
{
std::cout << "Extent of dimensionality " << d << ": "
<< buf.shape.at( d ) << std::endl;
numElements *= buf.shape.at( d );
<< buf.shape.at(d) << std::endl;
numElements *= buf.shape.at(d);
}
}

Expand Down Expand Up @@ -184,7 +184,7 @@ void init_PatchRecordComponent(py::module &m)
throw std::runtime_error(
"store: "
"Only scalar values supported! (found " +
std::to_string( numElements ) + "values)" );
std::to_string(numElements) + "values)");
}
},
py::arg("idx"),
Expand Down
107 changes: 53 additions & 54 deletions src/binding/python/RecordComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,54 +539,54 @@ void load_chunk(
}
}

auto load_data = [ &r, &buffer, &buffer_info, &offset, &extent ](
auto cxxtype ) {
using CXXType = decltype( cxxtype );
buffer.inc_ref();
// buffer_info.inc_ref();
void * data = buffer_info.ptr;
std::shared_ptr< CXXType > shared(
( CXXType * )data, [ buffer ]( CXXType * ) { buffer.dec_ref(); } );
r.loadChunk( std::move( shared ), offset, extent );
};
auto load_data =
[&r, &buffer, &buffer_info, &offset, &extent](auto cxxtype) {
using CXXType = decltype(cxxtype);
buffer.inc_ref();
// buffer_info.inc_ref();
void *data = buffer_info.ptr;
std::shared_ptr<CXXType> shared(
(CXXType *)data, [buffer](CXXType *) { buffer.dec_ref(); });
r.loadChunk(std::move(shared), offset, extent);
};

if( r.getDatatype() == Datatype::CHAR )
load_data( ( char )0 );
else if( r.getDatatype() == Datatype::UCHAR )
load_data( ( unsigned char )0 );
else if( r.getDatatype() == Datatype::SHORT )
load_data( ( short )0 );
else if( r.getDatatype() == Datatype::INT )
load_data( ( int )0 );
else if( r.getDatatype() == Datatype::LONG )
load_data( ( long )0 );
else if( r.getDatatype() == Datatype::LONGLONG )
load_data( ( long long )0 );
else if( r.getDatatype() == Datatype::USHORT )
load_data( ( unsigned short )0 );
else if( r.getDatatype() == Datatype::UINT )
load_data( ( unsigned int )0 );
else if( r.getDatatype() == Datatype::ULONG )
load_data( ( unsigned long )0 );
else if( r.getDatatype() == Datatype::ULONGLONG )
load_data( ( unsigned long long )0 );
else if( r.getDatatype() == Datatype::LONG_DOUBLE )
load_data( ( long double )0 );
else if( r.getDatatype() == Datatype::DOUBLE )
load_data( ( double )0 );
else if( r.getDatatype() == Datatype::FLOAT )
load_data( ( float )0 );
else if( r.getDatatype() == Datatype::CLONG_DOUBLE )
load_data( ( std::complex< long double > )0 );
else if( r.getDatatype() == Datatype::CDOUBLE )
load_data( ( std::complex< double > )0 );
else if( r.getDatatype() == Datatype::CFLOAT )
load_data( ( std::complex< float > )0 );
else if( r.getDatatype() == Datatype::BOOL )
load_data( ( bool )0 );
if (r.getDatatype() == Datatype::CHAR)
load_data((char)0);
else if (r.getDatatype() == Datatype::UCHAR)
load_data((unsigned char)0);
else if (r.getDatatype() == Datatype::SHORT)
load_data((short)0);
else if (r.getDatatype() == Datatype::INT)
load_data((int)0);
else if (r.getDatatype() == Datatype::LONG)
load_data((long)0);
else if (r.getDatatype() == Datatype::LONGLONG)
load_data((long long)0);
else if (r.getDatatype() == Datatype::USHORT)
load_data((unsigned short)0);
else if (r.getDatatype() == Datatype::UINT)
load_data((unsigned int)0);
else if (r.getDatatype() == Datatype::ULONG)
load_data((unsigned long)0);
else if (r.getDatatype() == Datatype::ULONGLONG)
load_data((unsigned long long)0);
else if (r.getDatatype() == Datatype::LONG_DOUBLE)
load_data((long double)0);
else if (r.getDatatype() == Datatype::DOUBLE)
load_data((double)0);
else if (r.getDatatype() == Datatype::FLOAT)
load_data((float)0);
else if (r.getDatatype() == Datatype::CLONG_DOUBLE)
load_data((std::complex<long double>)0);
else if (r.getDatatype() == Datatype::CDOUBLE)
load_data((std::complex<double>)0);
else if (r.getDatatype() == Datatype::CFLOAT)
load_data((std::complex<float>)0);
else if (r.getDatatype() == Datatype::BOOL)
load_data((bool)0);
else
throw std::runtime_error(
std::string( "Datatype not known in 'loadChunk'!" ) );
std::string("Datatype not known in 'loadChunk'!"));
}

/** Load Chunk
Expand Down Expand Up @@ -773,15 +773,15 @@ void init_RecordComponent(py::module &m)

// allow one-element n-dimensional buffers as well
py::ssize_t numElements = 1;
if( buf.ndim > 0 )
if (buf.ndim > 0)
{
std::cout << "Buffer has dimensionality: " << buf.ndim
<< std::endl;
for( auto d = 0; d < buf.ndim; ++d )
for (auto d = 0; d < buf.ndim; ++d)
{
std::cout << "Extent of dimensionality " << d << ": "
<< buf.shape.at( d ) << std::endl;
numElements *= buf.shape.at( d );
<< buf.shape.at(d) << std::endl;
numElements *= buf.shape.at(d);
}
}

Expand Down Expand Up @@ -866,19 +866,18 @@ void init_RecordComponent(py::module &m)
default:
throw std::runtime_error(
"make_constant: "
"Unknown Datatype!" );
"Unknown Datatype!");
}
}
else
{
throw std::runtime_error(
"make_constant: "
"Only scalar values supported! (found " +
std::to_string( numElements ) + "values)" );
std::to_string(numElements) + "values)");
}

}, py::arg("value")
)
},
py::arg("value"))
// allowed python intrinsics, after (!) buffer matching
.def(
"make_constant",
Expand Down

0 comments on commit 0061bae

Please sign in to comment.