Skip to content

Commit

Permalink
Remove static_cast in array assignment, instead fix all assigment war…
Browse files Browse the repository at this point in the history
…nings
  • Loading branch information
Wentzell committed Aug 23, 2023
1 parent ff2ef88 commit 25ad6bc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions c++/nda/_impl_basic_array_view_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void assign_from_ndarray(RHS const &rhs) { // FIXME noexcept {
static constexpr bool both_1d_strided = has_layout_strided_1d<self_t> and has_layout_strided_1d<RHS>;

if constexpr (mem::on_host<self_t, RHS> and both_1d_strided) { // -> vectorizable host copy
for (long i = 0; i < size(); ++i) (*this)(_linear_index_t{i}) = static_cast<value_type>(rhs(_linear_index_t{i}));
for (long i = 0; i < size(); ++i) (*this)(_linear_index_t{i}) = rhs(_linear_index_t{i});
return;
} else if constexpr (!mem::on_host<self_t, RHS> and have_same_value_type_v<self_t, RHS>) {
// Check for block-layout and use mem::memcpy2D if possible
Expand Down Expand Up @@ -383,9 +383,10 @@ void assign_from_ndarray(RHS const &rhs) { // FIXME noexcept {
if constexpr (mem::on_device<self_t> || mem::on_device<RHS>)
NDA_RUNTIME_ERROR << "Fallback to elementwise assignment not implemented for arrays on the GPU";
// Fallback to elementwise assignment
auto l = [this, &rhs](auto const &...args) { (*this)(args...) = static_cast<value_type>(rhs(args...)); };
auto l = [this, &rhs](auto const &...args) { (*this)(args...) = rhs(args...); };
nda::for_each(shape(), l);
}

// -----------------------------------------------------

template <typename Scalar>
Expand Down
12 changes: 7 additions & 5 deletions c++/nda/h5.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,13 @@ namespace nda {
auto lt = h5::array_interface::get_h5_lengths_type(g, name);

// Allow to read non-complex data into array<complex>
if (is_complex && !lt.has_complex_attribute) {
array<double, A::rank> tmp;
h5_read(g, name, tmp);
a = tmp;
return;
if constexpr (is_complex) {
if (!lt.has_complex_attribute) {
array<double, A::rank> tmp;
h5_read(g, name, tmp);
a = tmp;
return;
}
}

std::array<long, A::rank> shape{};
Expand Down
1 change: 1 addition & 0 deletions test/c++/nda_arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
//
// Authors: Olivier Parcollet, Nils Wentzell

#pragma GCC diagnostic ignored "-Wfloat-conversion"
#include "./test_common.hpp"

TEST(NDA, ExprTemplate) { //NOLINT
Expand Down
2 changes: 1 addition & 1 deletion test/c++/nda_expr_template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ TEST(NDA, DanglingScalarProtection) { //NOLINT
nda::array<long, 1> a{4, 2, 3}, b{8, 4, 6};

auto f = [&a]() {
double x = 2;
long x = 2;
return x * a;
};

Expand Down

0 comments on commit 25ad6bc

Please sign in to comment.