当前位置: 首页>>代码示例>>C++>>正文


C++ array::to_host方法代码示例

本文整理汇总了C++中dynd::nd::array::to_host方法的典型用法代码示例。如果您正苦于以下问题:C++ array::to_host方法的具体用法?C++ array::to_host怎么用?C++ array::to_host使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在dynd::nd::array的用法示例。


在下文中一共展示了array::to_host方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: AssertArrayNear

inline ::testing::AssertionResult AssertArrayNear(const char *expected_expr, const char *actual_expr,
                                                  const char *rel_error_max_expr, const dynd::nd::array &expected,
                                                  const dynd::nd::array &actual, double rel_error_max)
{
  const dynd::ndt::type &expected_tp = expected.get_type();
  const dynd::ndt::type &actual_tp = actual.get_type();
  if (expected_tp.get_type_id() == dynd::cuda_device_type_id && actual_tp.get_type_id() == dynd::cuda_device_type_id) {
    return AssertArrayNear(expected_expr, actual_expr, rel_error_max_expr, expected.to_host(), actual.to_host(),
                           rel_error_max);
  }

  std::unique_ptr<test_class<dynd::complex<double>>> c(new test_class<dynd::complex<double>>(rel_error_max));

  dynd::nd::callable af = dynd::nd::functional::elwise(dynd::nd::functional::apply(c.get()));
  af(expected, actual);

  bool res = c->flag;

  if (res) {
    return ::testing::AssertionSuccess();
  }

  return ::testing::AssertionFailure() << "the values do not match";
}
开发者ID:mdboom,项目名称:libdynd,代码行数:24,代码来源:dynd_assertions.hpp

示例2: CompareDyNDArrays

inline ::testing::AssertionResult CompareDyNDArrays(const char *expr1, const char *expr2, const dynd::nd::array &val1,
                                                    const dynd::nd::array &val2)
{
  using namespace dynd;

  if (val1.get_type().get_type_id() == cuda_device_type_id && val2.get_type().get_type_id() == cuda_device_type_id) {
    return CompareDyNDArrays(expr1, expr2, val1.to_host(), val2.to_host());
  }

  if (val1.equals_exact(val2)) {
    return ::testing::AssertionSuccess();
  }
  else {
    if (val1.get_type() != val2.get_type()) {
      return ::testing::AssertionFailure() << "The types of " << expr1 << " and " << expr2 << " do not match\n" << expr1
                                           << " has type " << val1.get_type() << ",\n" << expr2 << " has type "
                                           << val2.get_type() << ".";
    }
    else if (val1.get_shape() != val2.get_shape()) {
      return ::testing::AssertionFailure() << "The shapes of " << expr1 << " and " << expr2 << " do not match\n"
                                           << expr1 << " has shape " << ShapeFormatter(val1.get_shape()) << ",\n"
                                           << expr2 << " has shape " << ShapeFormatter(val2.get_shape()) << ".";
    }
    else if (val1.get_type().get_kind() == struct_kind) {
      const ndt::struct_type *bsd = val1.get_type().extended<ndt::struct_type>();
      intptr_t field_count = bsd->get_field_count();
      for (intptr_t i = 0; i < field_count; ++i) {
        nd::array field1 = val1(i), field2 = val2(i);
        if (!field1.equals_exact(field2)) {
          return ::testing::AssertionFailure()
                 << "The values of " << expr1 << " and " << expr2 << " do not match at field index " << i << ", name \""
                 << bsd->get_field_name(i) << "\"\n" << expr1 << " has field value " << field1 << ",\n" << expr2
                 << " has field value " << field2 << ".";
        }
      }
      return ::testing::AssertionFailure() << "DYND ASSERTION INTERNAL ERROR: One of the struct fields "
                                              "should have compared unequal";
    }
    else if (val1.get_type().get_kind() == tuple_kind) {
      const ndt::tuple_type *bsd = val1.get_type().extended<ndt::tuple_type>();
      intptr_t field_count = bsd->get_field_count();
      for (intptr_t i = 0; i < field_count; ++i) {
        nd::array field1 = val1(i), field2 = val2(i);
        if (!field1.equals_exact(field2)) {
          return ::testing::AssertionFailure()
                 << "The values of " << expr1 << " and " << expr2 << " do not match at field index " << i << "\"\n"
                 << expr1 << " has field value " << field1 << ",\n" << expr2 << " has field value " << field2 << ".";
        }
      }
      return ::testing::AssertionFailure() << "DYND ASSERTION INTERNAL ERROR: One of the tuple fields "
                                              "should have compared unequal";
    }
    else if (val1.get_ndim() > 0) {
      intptr_t dim_size = val1.get_dim_size();
      for (intptr_t i = 0; i < dim_size; ++i) {
        nd::array sub1 = val1(i), sub2 = val2(i);
        if (!sub1.equals_exact(sub2)) {
          return ::testing::AssertionFailure()
                 << "The values of " << expr1 << " and " << expr2 << " do not match at index " << i << "\"\n" << expr1
                 << " has subarray value " << sub1 << ",\n" << expr2 << " has subarray value " << sub2 << ".";
        }
      }
      return ::testing::AssertionFailure() << "DYND ASSERTION INTERNAL ERROR: One of the subarrays "
                                              "should have compared unequal\n"
                                           << expr1 << " has value " << val1 << ",\n" << expr2 << " has value " << val2
                                           << ".";
    }
    else {
      return ::testing::AssertionFailure() << "The values of " << expr1 << " and " << expr2 << " do not match\n"
                                           << expr1 << " has value " << val1 << ",\n" << expr2 << " has value " << val2
                                           << ".";
    }
  }
}
开发者ID:mdboom,项目名称:libdynd,代码行数:74,代码来源:dynd_assertions.hpp


注:本文中的dynd::nd::array::to_host方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。