Conversation
8ae9d20 to
45b7e04
Compare
|
@C0nsultant Ping :) |
|
This make |
| template< typename U > | ||
| U Attribute::get() const | ||
| { | ||
| return getCast< U >( Variant::getResource() ); |
There was a problem hiding this comment.
I would hate to cast silently here and not notify the user about possible loss of precision.
There already is a function that does this (warnWrongDtype()). I'll push a patch shortly that will use that function if the resource dtype and U differ.
There was a problem hiding this comment.
That's actually not what I would like as a user.
If there is an attribute "attr" I can RT check it's dtype. If I want to get<> it as something, I want to get it as exactly such.
There was a problem hiding this comment.
Let's have a quick chat on the philosophy of that method if you like :) Gitter? VC?
In case you are busy today, we can also chat on Monday. I have to leave here around noon.
There was a problem hiding this comment.
Offline resolution:
C++ requires a certain effort from the user to put the type inside the brackets. Thus, he should be well aware of what he is requesting.
Information about the datatype can be obtained at run-time. If non-casting behavior is desired, we shift this obligation to the user.
There was a problem hiding this comment.
If non-casting behavior is desired, we shift this obligation to the user.
e.g. by checking the dtype at runtime, taking the resource directly or casting back to the underlying auxiliary::Variant that will throw.
test/SerialIOTest.cpp
Outdated
| REQUIRE(getCast< std::vector< long double > >(s.getAttribute("vecLongdouble")) == std::vector< long double >({0.L, std::numeric_limits<long double>::max()})); | ||
| REQUIRE(s.getAttribute("vecLongdouble").get< std::vector< long double > >() == std::vector< long double >({0.L, std::numeric_limits<long double>::max()})); | ||
| REQUIRE(s.getAttribute("vecString").get< std::vector< std::string > >() == std::vector< std::string >({"vector", "of", "strings"})); | ||
| // REQUIRE(s.getAttribute("bool").get< bool >() == true); |
There was a problem hiding this comment.
This should work as expected now, as the stored uint8_t can be cast to bool in the new get.
Implement `getCast<>()` in `Attribute::get<U>()`. Will now cast during get if convertible.
getCast is now convieniently implemented in ::get
Added this for being pedantic in case this causes a warning. Nevertheless, would have to create a factory here to properly init a `std::array`.
45b7e04 to
78c7a2f
Compare
test/SerialIOTest.cpp
Outdated
| REQUIRE(s.getAttribute("vecLongdouble").get< std::vector< long double > >() == std::vector< long double >({0.L, std::numeric_limits<long double>::max()})); | ||
| REQUIRE(s.getAttribute("vecString").get< std::vector< std::string > >() == std::vector< std::string >({"vector", "of", "strings"})); | ||
| REQUIRE(s.getAttribute("bool").get< unsigned char >() == true); | ||
| REQUIRE(s.getAttribute("boolF").get< unsigned char >() == false); |
There was a problem hiding this comment.
This now can be retrieved as bool, thanks to the casting get.
Have this in my staged set, will push soon.
There was a problem hiding this comment.
That sounds great, thanks! :)
50120b2 to
4b3a053
Compare
| Datatype store, | ||
| Datatype request) | ||
| { | ||
| std::cerr << "Warning: Attribute '" << key |
There was a problem hiding this comment.
loving MSVC:
error C2679: binary '<<': no operator found which takes a right-hand operand of type 'const std::string' (or there is no acceptable conversion
forgot to include <string>
The handling an casting of arbitrary-width floating-point Attributes is now redundant with the casting that is present in Attrbute::get.
4b3a053 to
f67e00e
Compare
In `pybind11`, overloads on types are order-dependent (first wins). pybind/pybind11#1512 We specialize `double` here generically and cast in read if needed (see openPMD#345 openPMD#1137). Later on, we could add support for 1D numpy arrays with distinct type.
In `pybind11`, overloads on types are order-dependent (first wins). pybind/pybind11#1512 We specialize `double` here generically and cast in read if needed (see #345 #1137). Later on, we could add support for 1D numpy arrays with distinct type.
Close #335: Implement
getCast<>()inAttribute::get<U>(). Will now castduring
::get<U>()if convertible.Implementations can now simply use
::get<>()again :)Final clean-up for refactoring started in #337