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


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

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


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

示例1: view

nd::array nd::view(const nd::array &arr, const ndt::type &tp)
{
  if (arr.get_type() == tp) {
    // If the types match exactly, simply return 'arr'
    return arr;
  } else if (tp.get_type_id() == bytes_type_id) {
    // If it's a request to view the data as raw bytes
    nd::array result = view_as_bytes(arr, tp);
    if (!result.is_null()) {
      return result;
    }
  } else if (arr.get_type().get_type_id() == bytes_type_id) {
    // If it's a request to view raw bytes as something else
    nd::array result = view_from_bytes(arr, tp);
    if (!result.is_null()) {
      return result;
    }
  } else if (arr.get_ndim() == tp.get_ndim()) {
    // If the type is symbolic, e.g. has a "Fixed" symbolic dimension,
    // first substitute in the shape from the array
    if (tp.is_symbolic()) {
      dimvector shape(arr.get_ndim());
      arr.get_shape(shape.get());
      return view_concrete(arr, substitute_shape(tp, arr.get_ndim(), shape.get()));
    } else {
      return view_concrete(arr, tp);
    }
  }

  stringstream ss;
  ss << "Unable to view nd::array of type " << arr.get_type();
  ss << " as type " << tp;
  throw type_error(ss.str());
}
开发者ID:hainm,项目名称:libdynd,代码行数:34,代码来源:view.cpp

示例2: view

nd::array nd::view(const nd::array& arr, const ndt::type& tp)
{
    // If the types match exactly, simply return 'arr'
    if (arr.get_type() == tp) {
        return arr;
    } else if (arr.get_ndim() == tp.get_ndim()) {
        // Allocate a result array to attempt the view in it
        array result(make_array_memory_block(tp.get_metadata_size()));
        // Copy the fields
        result.get_ndo()->m_data_pointer = arr.get_ndo()->m_data_pointer;
        if (arr.get_ndo()->m_data_reference == NULL) {
            // Embedded data, need reference to the array
            result.get_ndo()->m_data_reference = arr.get_memblock().release();
        } else {
            // Use the same data reference, avoid producing a chain
            result.get_ndo()->m_data_reference = arr.get_data_memblock().release();
        }
        result.get_ndo()->m_type = ndt::type(tp).release();
        result.get_ndo()->m_flags = arr.get_ndo()->m_flags;
        // Now try to copy the metadata as a view
        if (try_view(arr.get_type(), arr.get_ndo_meta(), tp,
                     result.get_ndo_meta(), arr.get_memblock().get())) {
            // If it succeeded, return it
            return result;
        }
        // Otherwise fall through, let it get destructed, and raise an error
    }

    stringstream ss;
    ss << "Unable to view nd::array of type " << arr.get_type();
    ss << "as type " << tp;
    throw type_error(ss.str());
}
开发者ID:talumbau,项目名称:libdynd,代码行数:33,代码来源:view.cpp

示例3: ifft

inline nd::array ifft(const nd::array &x, std::vector<intptr_t> shape) {
    std::vector<intptr_t> axes;
    for (intptr_t i = 0; i < x.get_ndim(); ++i) {
        axes.push_back(i);
    }

    return ifft(x, shape, axes);
}
开发者ID:aterrel,项目名称:libdynd,代码行数:8,代码来源:fft.hpp

示例4: fftshift

nd::array nd::fftshift(const nd::array &x)
{
  nd::array y = x;
  for (intptr_t i = 0; i < x.get_ndim(); ++i) {
    intptr_t p = y.get_dim_size();
    intptr_t q = (p + 1) / 2;
    y = take(y, nd::concatenate(nd::range(q, p), nd::range(q)));
    y = y.rotate();
  }
  return y;
}
开发者ID:Laeeth,项目名称:libdynd,代码行数:11,代码来源:fft.cpp

示例5: invalid_argument

/**
 * Computes the discrete inverse Fourier transform of a complex array, under the
 * assumption that the result is a real array.
 *
 * @param x An array of real numbers with arbitrary dimensions.
 * @param shape The shape of the Fourier transform. If any dimension is less than
 *              the corresponding dimension of 'x', that dimension will be truncated.
 *
 * @return A complex array with dimensions specified by 'shape'. By default, the shape
 *         is the same as that of 'x', except the last dimension is '2 * (x.get_shape[x.get_ndim() - 1] - 1)'.
 */
inline nd::array irfft(const nd::array &x, std::vector<intptr_t> shape) {
    if (x.get_ndim() != static_cast<intptr_t>(shape.size())) {
        throw std::invalid_argument("dimensions provided for irfft do not match");
    }

#ifdef DYND_FFTW
    return fftw::irfft(x, shape);
#else
    throw std::runtime_error("irfft is not implemented");
#endif
}
开发者ID:aterrel,项目名称:libdynd,代码行数:22,代码来源:fft.hpp


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