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


C++ ArrayView类代码示例

本文整理汇总了C++中ArrayView的典型用法代码示例。如果您正苦于以下问题:C++ ArrayView类的具体用法?C++ ArrayView怎么用?C++ ArrayView使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: TEST

TEST(ArrayRefTests, arrayView) {
  uint8_t data[4] = {2, 3, 5, 7};
  const ArrayRef<> ref(data);
  ArrayView<> view = ref;
  ASSERT_EQ(ref.getData(), view.getData());
  ASSERT_EQ(ref.getSize(), view.getSize());
}
开发者ID:HBNCoins,项目名称:cryptonote,代码行数:7,代码来源:ArrayRefTests.cpp

示例2:

void DefaultProductMultiVector<Scalar>::initializeImpl(
    const RCP<const DefaultProductVectorSpace<Scalar> > &productSpace_in,
    const ArrayView<const RCP<MultiVectorType> > &multiVecs
)
{
    // This function provides the "strong" guarantee (i.e. if an exception is
    // thrown, then *this will be left in the original state as before the
    // function was called)!
#ifdef TEUCHOS_DEBUG
    TEUCHOS_ASSERT(nonnull(productSpace_in));
    TEUCHOS_ASSERT_EQUALITY(multiVecs.size(), productSpace_in->numBlocks());
#endif // TEUCHOS_DEBUG
    const RCP<const VectorSpaceBase<Scalar> >
    theDomain = multiVecs[0]->domain();
    const int numBlocks = productSpace_in->numBlocks();
#ifdef TEUCHOS_DEBUG
    for ( int k = 0; k < numBlocks; ++k ) {
        THYRA_ASSERT_VEC_SPACES(
            Teuchos::TypeNameTraits<DefaultProductMultiVector<Scalar> >::name(),
            *theDomain, *multiVecs[k]->domain()
        );
    }
#endif
    productSpace_ = productSpace_in;
    numBlocks_ = numBlocks;
    multiVecs_.assign(multiVecs.begin(),multiVecs.end());
}
开发者ID:00liujj,项目名称:trilinos,代码行数:27,代码来源:Thyra_DefaultProductMultiVector_def.hpp

示例3: rawMpiRequests

void MpiComm<Ordinal>::waitAll(
    const ArrayView<RCP<CommRequest> > &requests
) const
{
    TEUCHOS_COMM_TIME_MONITOR(
        "Teuchos::MpiComm<"<<OrdinalTraits<Ordinal>::name()<<">::waitAll(...)"
    );
    const int count = requests.size();
#ifdef TEUCHOS_DEBUG
    TEST_FOR_EXCEPT( requests.size() == 0 );
#endif

    Array<MPI_Request> rawMpiRequests(count, MPI_REQUEST_NULL);
    for (int i = 0; i < count; ++i) {
        RCP<CommRequest> &request = requests[i];
        if (!is_null(request)) {
            const RCP<MpiCommRequest> mpiCommRequest =
                rcp_dynamic_cast<MpiCommRequest>(request);
            rawMpiRequests[i] = mpiCommRequest->releaseRawMpiRequest();
        }
        // else already null
        request = null;
    }

    Array<MPI_Status> rawMpiStatuses(count);
    MPI_Waitall( count, rawMpiRequests.getRawPtr(), rawMpiStatuses.getRawPtr() );
    // ToDo: We really should check the status?

}
开发者ID:haripandey,项目名称:trilinos,代码行数:29,代码来源:Teuchos_DefaultMpiComm.hpp

示例4: apply_op_validate_input

void Thyra::apply_op_validate_input(
  const std::string &func_name,
  const VectorSpaceBase<Scalar> &domain,
  const VectorSpaceBase<Scalar> &range,
  const RTOpPack::RTOpT<Scalar> &primary_op,
  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
  const Ordinal primary_global_offset_in
  )
{
  using Teuchos::as;
  // Validate primary range arguments
  TEST_FOR_EXCEPTION(
    primary_global_offset_in < 0, std::logic_error
    ,func_name << " : Error! primary_global_offset_in = "
    <<primary_global_offset_in<<" is not valid" );
  // Validate secondary domain arguments
  // Validate spaces
  for (int k = 0; k < multi_vecs.size(); ++k) {
    THYRA_ASSERT_VEC_SPACES(func_name,domain,*multi_vecs[k]->domain());
    THYRA_ASSERT_VEC_SPACES(func_name,range,*multi_vecs[k]->range());
  }
  for (int k = 0; k < targ_multi_vecs.size(); ++k) {
    THYRA_ASSERT_VEC_SPACES(func_name,domain,*targ_multi_vecs[k]->domain());
    THYRA_ASSERT_VEC_SPACES(func_name,range,*targ_multi_vecs[k]->range());
  }
}
开发者ID:haripandey,项目名称:trilinos,代码行数:28,代码来源:Thyra_apply_op_helper_def.hpp

示例5: get_sm

ble_error_t nRF5xGap::update_identities_list(bool resolution_enabled)
{
    uint32_t err;

    if (resolution_enabled) {
        ArrayView<ble_gap_id_key_t> entries = get_sm().get_resolving_list();
        size_t limit = std::min(
            entries.size(), (size_t) YOTTA_CFG_IRK_TABLE_MAX_SIZE
        );
        ble_gap_id_key_t* id_keys_pp[YOTTA_CFG_IRK_TABLE_MAX_SIZE];

        for (size_t i = 0; i < limit; ++i) {
            id_keys_pp[i] = &entries[i];
        }

        err = sd_ble_gap_device_identities_set(
            limit ? id_keys_pp : NULL,
            /* use the local IRK for all devices */ NULL,
            limit
        );
    } else {
        err = sd_ble_gap_device_identities_set(
            NULL,
            /* use the local IRK for all devices */ NULL,
            0
        );
    }

    return err ? BLE_ERROR_INVALID_STATE : BLE_ERROR_NONE;
}
开发者ID:sg-,项目名称:mbed-os,代码行数:30,代码来源:nRF5xGap.cpp

示例6:

void MpiComm<Ordinal>::readySend(
    const ArrayView<const char> &sendBuffer,
    const int destRank
) const
{
    TEUCHOS_COMM_TIME_MONITOR(
        "Teuchos::MpiComm<"<<OrdinalTraits<Ordinal>::name()<<">::readySend(...)"
    );
#ifdef TEUCHOS_DEBUG
    TEST_FOR_EXCEPTION(
        ! ( 0 <= destRank && destRank < size_ ), std::logic_error
        ,"Error, destRank = " << destRank << " is not < 0 or is not"
        " in the range [0,"<<size_-1<<"]!"
    );
#endif // TEUCHOS_DEBUG
#ifdef TEUCHOS_MPI_COMM_DUMP
    if(show_dump) {
        dumpBuffer<Ordinal,char>(
            "Teuchos::MpiComm<Ordinal>::readySend(...)"
            ,"sendBuffer", bytes, sendBuffer
        );
    }
#endif // TEUCHOS_MPI_COMM_DUMP
    MPI_Rsend(
        const_cast<char*>(sendBuffer.getRawPtr()),sendBuffer.size(),MPI_CHAR,destRank,tag_,*rawMpiComm_
    );
    // ToDo: What about error handling???
}
开发者ID:haripandey,项目名称:trilinos,代码行数:28,代码来源:Teuchos_DefaultMpiComm.hpp

示例7:

  void
  AbstractConcreteMatrixAdapter<
    Epetra_RowMatrix,
    DerivedMat>::getGlobalRowCopy_impl(global_ordinal_t row,
                                       const ArrayView<global_ordinal_t>& indices,
                                       const ArrayView<scalar_t>& vals,
                                       size_t& nnz) const
  {
    using Teuchos::as;

    local_ordinal_t local_row = this->row_map_->getLocalElement(row);
    int nnz_ret = 0;
    int rowmatrix_return_val
      = this->mat_->ExtractMyRowCopy(as<int>(local_row),
                                     as<int>(std::min(indices.size(), vals.size())),
                                     nnz_ret,
                                     vals.getRawPtr(),
                                     indices.getRawPtr());
    TEUCHOS_TEST_FOR_EXCEPTION( rowmatrix_return_val != 0,
                        std::runtime_error,
                        "Epetra_RowMatrix object returned error code "
                        << rowmatrix_return_val << " from ExtractMyRowCopy." );
    nnz = as<size_t>(nnz_ret);

    // Epetra_CrsMatrix::ExtractMyRowCopy returns local column
    // indices, so transform these into global indices
    for( size_t i = 0; i < nnz; ++i ){
      indices[i] = this->col_map_->getGlobalElement(indices[i]);
    }
  }
开发者ID:KineticTheory,项目名称:Trilinos,代码行数:30,代码来源:Amesos2_EpetraRowMatrix_AbstractMatrixAdapter_def.hpp

示例8: copy

    std::pair<CudaEvent, view_type>
    copy(const ArrayView<
                value_type,
                HostCoordinator<
                    value_type,
                    PinnedAllocator<
                        value_type,
                        alignment>>> &from,
         view_type &to) {
        assert(from.size()==to.size());

        #ifdef VERBOSE
        using oType = ArrayView< value_type, HostCoordinator< value_type, PinnedAllocator< value_type, alignment>>>;
        std::cout << util::pretty_printer<DeviceCoordinator>::print(*this)
                  << "::" << util::blue("copy") << "(asynchronous, " << from.size() << ")"
                  << "\n  " << util::type_printer<oType>::print() << " @ " << from.data()
                  << util::yellow(" -> ")
                  << util::type_printer<view_type>::print() << " @ " << to.data() << std::endl;
        #endif

        auto status = cudaMemcpy(
                reinterpret_cast<void*>(to.begin()),
                reinterpret_cast<const void*>(from.begin()),
                from.size()*sizeof(value_type),
                cudaMemcpyHostToDevice
        );
        if(status != cudaSuccess) {
            std::cerr << util::red("error") << " bad CUDA memcopy, unable to copy " << sizeof(T)*from.size() << " bytes from host to device";
            exit(-1);
        }

        CudaEvent event;
        return std::make_pair(event, to);
    }
开发者ID:w-klijn,项目名称:vector,代码行数:34,代码来源:DeviceCoordinator.hpp

示例9: dolfin_assert

//-----------------------------------------------------------------------------
void Function::restrict(double* w, const FiniteElement& element,
                        const Cell& dolfin_cell,
                        const double* coordinate_dofs,
                        const ufc::cell& ufc_cell) const
{
  dolfin_assert(w);
  dolfin_assert(_function_space);
  dolfin_assert(_function_space->dofmap());

  // Check if we are restricting to an element of this function space
  if (_function_space->has_element(element)
      && _function_space->has_cell(dolfin_cell))
  {
    // Get dofmap for cell
    const GenericDofMap& dofmap = *_function_space->dofmap();
    const ArrayView<const dolfin::la_index> dofs
      = dofmap.cell_dofs(dolfin_cell.index());

    // Note: We should have dofmap.max_element_dofs() == dofs.size() here.
    // Pick values from vector(s)
    _vector->get_local(w, dofs.size(), dofs.data());
  }
  else
  {
    // Restrict as UFC function (by calling eval)
    restrict_as_ufc_function(w, element, dolfin_cell, coordinate_dofs,
                             ufc_cell);
  }
}
开发者ID:MollyRaver,项目名称:dolfin,代码行数:30,代码来源:Function.cpp

示例10: getEpetraCrsGraph

RCP<Epetra_CrsMatrix> UserInputForTests::getEpetraCrsMatrix()
{
  if (M_.is_null())
    throw std::runtime_error("could not read mtx file");
  RCP<Epetra_CrsGraph> egraph = getEpetraCrsGraph();
  eM_ = rcp(new Epetra_CrsMatrix(Copy, *egraph));

  size_t maxRow = M_->getNodeMaxNumRowEntries();
  int nrows = egraph->NumMyRows();
  int base = egraph->IndexBase();
  const Epetra_BlockMap &rowMap = egraph->RowMap();
  const Epetra_BlockMap &colMap = egraph->ColMap();
  Array<int> colGid(maxRow);

  for (int i=0; i < nrows; i++){
    ArrayView<const int> colLid;
    ArrayView<const scalar_t> nz;
    M_->getLocalRowView(i+base, colLid, nz);
    size_t rowSize = colLid.size();
    int rowGid = rowMap.GID(i+base);
    for (size_t j=0; j < rowSize; j++){
      colGid[j] = colMap.GID(colLid[j]);
    }
    eM_->InsertGlobalValues(
      rowGid, rowSize, nz.getRawPtr(), colGid.getRawPtr());
  }
  eM_->FillComplete();
  return eM_;
}
开发者ID:gitter-badger,项目名称:quinoa,代码行数:29,代码来源:UserInputForTests.hpp

示例11:

  void EpetraCrsMatrixT<EpetraGlobalOrdinal>::getLocalRowCopy(LocalOrdinal LocalRow, const ArrayView<LocalOrdinal> &Indices, const ArrayView<Scalar> &Values, size_t &NumEntries) const {
    XPETRA_MONITOR("EpetraCrsMatrixT::getLocalRowCopy");

    int numEntries = -1;
    XPETRA_ERR_CHECK(mtx_->ExtractMyRowCopy(LocalRow, Indices.size(), numEntries, Values.getRawPtr(), Indices.getRawPtr()));
    NumEntries = numEntries;
  }
开发者ID:abhishek4747,项目名称:trilinos,代码行数:7,代码来源:Xpetra_EpetraCrsMatrix.cpp

示例12: compute_weight

 void compute_weight(Function& DG)
 { // Compute weights for averaging with neighboring cells
     
   // Get the mesh, element and dofmap
   std::shared_ptr<const FunctionSpace> V = DG.function_space(); 
   std::shared_ptr<const Mesh> mesh = V->mesh();
   std::shared_ptr<const FiniteElement> element = V->element();
   std::shared_ptr<const GenericDofMap> dofmap_u = V->dofmap();
   
   // Allocate storage for weights on one cell
   std::vector<double> ws(element->space_dimension()); 
       
   // Compute weights
   GenericVector& dg_vector = *DG.vector();  
   dg_vector.zero();
   for (CellIterator cell(*mesh, "all"); !cell.end(); ++cell)
   {
     const ArrayView<const dolfin::la_index> dofs
       = dofmap_u->cell_dofs(cell->index());
       
     std::fill(ws.begin(), ws.end(), 1./cell->volume());
     dg_vector.add_local(ws.data(), dofs.size(), dofs.data());    
   }  
   dg_vector.apply("insert"); 
 }
开发者ID:BijanZarif,项目名称:fenicstools,代码行数:25,代码来源:gradient_weight.cpp

示例13:

REFCOUNTPTR_INLINE
Teuchos::ArrayView<T2>
Teuchos::av_const_cast(const ArrayView<T1>& p1)
{
  T2 *ptr2 = const_cast<T2*>(p1.getRawPtr());
  return ArrayView<T2>(ptr2, p1.size());
  // Note: Above is just fine even if p1.get()==NULL!
}
开发者ID:crtrott,项目名称:Trilinos,代码行数:8,代码来源:Teuchos_ArrayView.hpp

示例14:

TestLagrPolyMeritFunc1D<Scalar>::TestLagrPolyMeritFunc1D(
  const ArrayView<const Scalar> &alpha,
  const ArrayView<const Scalar> &phi
  )
  : alpha_(alpha), phi_(phi)
{
  TEUCHOS_ASSERT_EQUALITY(alpha.size(), phi.size());
}
开发者ID:00liujj,项目名称:trilinos,代码行数:8,代码来源:GlobiPack_TestLagrPolyMeritFunc1D_def.hpp

示例15: assign

template<class T> inline
void ArrayRCP<T>::deepCopy(const ArrayView<const T>& av)
{
  if (av.size() == 0) {
    *this = null;
    return;
  }
  assign(av.begin(), av.end());
}
开发者ID:haripandey,项目名称:trilinos,代码行数:9,代码来源:Teuchos_ArrayRCP.hpp


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