本文整理汇总了C++中teuchos::ArrayView::size方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayView::size方法的具体用法?C++ ArrayView::size怎么用?C++ ArrayView::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类teuchos::ArrayView
的用法示例。
在下文中一共展示了ArrayView::size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createMeshMap
Teuchos::RCP<const Tpetra::Map<LO,GO,Node> >
createMeshMap (const LO& blockSize, const Tpetra::Map<LO,GO,Node>& pointMap)
{
typedef Teuchos::OrdinalTraits<Tpetra::global_size_t> TOT;
typedef Tpetra::Map<LO,GO,Node> map_type;
//calculate mesh GIDs
Teuchos::ArrayView<const GO> pointGids = pointMap.getNodeElementList();
Teuchos::Array<GO> meshGids;
GO indexBase = pointMap.getIndexBase();
// Use hash table to track whether we've encountered this GID previously. This will happen
// when striding through the point DOFs in a block. It should not happen otherwise.
// I don't use sort/make unique because I don't want to change the ordering.
meshGids.reserve(pointGids.size());
Tpetra::Details::HashTable<GO,int> hashTable(pointGids.size());
for (int i=0; i<pointGids.size(); ++i) {
GO meshGid = (pointGids[i]-indexBase) / blockSize + indexBase;
if (hashTable.get(meshGid) == -1) {
hashTable.add(meshGid,1); //(key,value)
meshGids.push_back(meshGid);
}
}
Teuchos::RCP<const map_type> meshMap = Teuchos::rcp( new map_type(TOT::invalid(), meshGids(), 0, pointMap.getComm()) );
return meshMap;
}
示例2: pack
void
RowGraph<LocalOrdinal,GlobalOrdinal,Node>::
pack (const Teuchos::ArrayView<const LocalOrdinal>& exportLIDs,
Teuchos::Array<GlobalOrdinal>& exports,
const Teuchos::ArrayView<size_t>& numPacketsPerLID,
size_t& constantNumPackets,
Distributor& distor) const
{
using Teuchos::Array;
typedef LocalOrdinal LO;
typedef GlobalOrdinal GO;
typedef Map<LO, GO, Node> map_type;
const char tfecfFuncName[] = "packAndPrepare";
(void) distor; // forestall "unused argument" compiler warning
TEUCHOS_TEST_FOR_EXCEPTION_CLASS_FUNC(
exportLIDs.size() != numPacketsPerLID.size(), std::runtime_error,
": exportLIDs and numPacketsPerLID must have the same size.");
const map_type& srcMap = * (this->getRowMap ());
constantNumPackets = 0;
// Set numPacketsPerLID[i] to the number of entries owned by the
// calling process in (local) row exportLIDs[i] of the graph, that
// the caller wants us to send out. Compute the total number of
// packets (that is, entries) owned by this process in all the
// rows that the caller wants us to send out.
size_t totalNumPackets = 0;
Array<GO> row;
for (LO i = 0; i < exportLIDs.size (); ++i) {
const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
size_t row_length = this->getNumEntriesInGlobalRow (GID);
numPacketsPerLID[i] = row_length;
totalNumPackets += row_length;
}
exports.resize (totalNumPackets);
// Loop again over the rows to export, and pack rows of indices
// into the output buffer.
size_t exportsOffset = 0;
for (LO i = 0; i < exportLIDs.size (); ++i) {
const GO GID = srcMap.getGlobalElement (exportLIDs[i]);
size_t row_length = this->getNumEntriesInGlobalRow (GID);
row.resize (row_length);
size_t check_row_length = 0;
this->getGlobalRowCopy (GID, row (), check_row_length);
typename Array<GO>::const_iterator row_iter = row.begin();
typename Array<GO>::const_iterator row_end = row.end();
size_t j = 0;
for (; row_iter != row_end; ++row_iter, ++j) {
exports[exportsOffset+j] = *row_iter;
}
exportsOffset += row.size ();
}
}
示例3: readyBuffers
void CUDANode::readyBuffers(Teuchos::ArrayView<Teuchos::ArrayRCP<const char> > buffers, Teuchos::ArrayView<Teuchos::ArrayRCP<char> > ncBuffers)
{
#ifdef HAVE_KOKKOS_DEBUG
for (size_t i=0; i < buffers.size(); ++i) {
CHECK_COMPUTE_BUFFER(buffers[i]);
}
for (size_t i=0; i < ncBuffers.size(); ++i) {
CHECK_COMPUTE_BUFFER(ncBuffers[i]);
}
#endif
TEST_FOR_EXCEPT(true);
}
示例4: result
Teuchos::Array< int >
computeCommIndexes(int rank,
const Teuchos::ArrayView< int > & commStrides)
{
Teuchos::Array< int > result(commStrides.size());
for (int axis = 0; axis < commStrides.size(); ++axis)
{
result[axis] = rank / commStrides[axis];
rank = rank % commStrides[axis];
}
return result;
}
示例5: toString
DenseContainer<MatrixType, LocalScalarType>::
DenseContainer (const Teuchos::RCP<const row_matrix_type>& matrix,
const Teuchos::ArrayView<const local_ordinal_type>& localRows) :
Container<MatrixType> (matrix, localRows),
numRows_ (localRows.size ()),
diagBlock_ (numRows_, numRows_),
ipiv_ (numRows_, 0)
{
using Teuchos::Array;
using Teuchos::ArrayView;
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::toString;
typedef Tpetra::Map<local_ordinal_type, global_ordinal_type, node_type> map_type;
typedef typename ArrayView<const local_ordinal_type>::size_type size_type;
TEUCHOS_TEST_FOR_EXCEPTION(
! matrix->hasColMap (), std::invalid_argument, "Ifpack2::DenseContainer: "
"The constructor's input matrix must have a column Map.");
// Check whether the input set of local row indices is correct.
const map_type& rowMap = * (matrix->getRowMap ());
const size_type numRows = localRows.size ();
bool rowIndicesValid = true;
Array<local_ordinal_type> invalidLocalRowIndices;
for (size_type i = 0; i < numRows; ++i) {
if (! rowMap.isNodeLocalElement (localRows[i])) {
rowIndicesValid = false;
invalidLocalRowIndices.push_back (localRows[i]);
break;
}
}
TEUCHOS_TEST_FOR_EXCEPTION(
! rowIndicesValid, std::invalid_argument, "Ifpack2::DenseContainer: "
"On process " << rowMap.getComm ()->getRank () << " of "
<< rowMap.getComm ()->getSize () << ", in the given set of local row "
"indices localRows = " << toString (localRows) << ", the following "
"entries are not valid local row indices on the calling process: "
<< toString (invalidLocalRowIndices) << ".");
#ifdef HAVE_MPI
RCP<const Teuchos::Comm<int> > localComm =
rcp (new Teuchos::MpiComm<int> (MPI_COMM_SELF));
#else
RCP<const Teuchos::Comm<int> > localComm =
rcp (new Teuchos::SerialComm<int> ());
#endif // HAVE_MPI
// FIXME (mfh 25 Aug 2013) What if the matrix's row Map has a
// different index base than zero?
const global_ordinal_type indexBase = 0;
localMap_ = rcp (new map_type (numRows_, indexBase, localComm));
}
示例6: rcp
void CrsMatrixWrapper<ST>::ypAx(const Teuchos::ArrayView<ST>& y,
const Teuchos::ArrayView<const ST>& x) const
{
RCP<VectorType<ST> > X = rcp(new VectorType<ST>(mat.getRowMap(), x, x.size(), 1));
RCP<VectorType<ST> > Y = rcp(new VectorType<ST>(mat.getRowMap(), y, y.size(), 1));
const ST alpha = Teuchos::ScalarTraits<ST>::one();
const ST beta = Teuchos::ScalarTraits<ST>::one();
// Y = beta*Y + alpha*A*X
mat.apply(*X, *Y, Teuchos::NO_TRANS, alpha, beta);
Y->get1dCopy(y, y.size());
}
示例7: m
void DropNegativeEntriesFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Build(Level& currentLevel) const {
FactoryMonitor m(*this, "Matrix filtering (springs)", currentLevel);
RCP<Matrix> Ain = Get< RCP<Matrix> >(currentLevel, "A");
LocalOrdinal nDofsPerNode = Ain->GetFixedBlockSize();
// create new empty Operator
Teuchos::RCP<Matrix> Aout = MatrixFactory::Build(Ain->getRowMap(), Ain->getGlobalMaxNumRowEntries(), Xpetra::StaticProfile);
size_t numLocalRows = Ain->getNodeNumRows();
for(size_t row=0; row<numLocalRows; row++) {
GlobalOrdinal grid = Ain->getRowMap()->getGlobalElement(row);
int rDofID = Teuchos::as<int>(grid % nDofsPerNode);
// extract row information from input matrix
Teuchos::ArrayView<const LocalOrdinal> indices;
Teuchos::ArrayView<const Scalar> vals;
Ain->getLocalRowView(row, indices, vals);
// just copy all values in output
Teuchos::ArrayRCP<GlobalOrdinal> indout(indices.size(),Teuchos::ScalarTraits<GlobalOrdinal>::zero());
Teuchos::ArrayRCP<Scalar> valout(indices.size(),Teuchos::ScalarTraits<Scalar>::zero());
size_t nNonzeros = 0;
for(size_t i=0; i<(size_t)indices.size(); i++) {
GlobalOrdinal gcid = Ain->getColMap()->getGlobalElement(indices[i]); // global column id
int cDofID = Teuchos::as<int>(gcid % nDofsPerNode);
if(rDofID == cDofID && Teuchos::ScalarTraits<Scalar>::magnitude(vals[i]) >= Teuchos::ScalarTraits<Scalar>::magnitude(Teuchos::ScalarTraits<Scalar>::zero())) {
indout [nNonzeros] = gcid;
valout [nNonzeros] = vals[i];
nNonzeros++;
}
}
indout.resize(nNonzeros);
valout.resize(nNonzeros);
Aout->insertGlobalValues(Ain->getRowMap()->getGlobalElement(row), indout.view(0,indout.size()), valout.view(0,valout.size()));
}
Aout->fillComplete(Ain->getDomainMap(), Ain->getRangeMap());
// copy block size information
Aout->SetFixedBlockSize(nDofsPerNode);
GetOStream(Statistics0, 0) << "Nonzeros in A (input): " << Ain->getGlobalNumEntries() << ", Nonzeros after filtering A: " << Aout->getGlobalNumEntries() << std::endl;
Set(currentLevel, "A", Aout);
}
示例8: apply_op_impl
void RTOpC::apply_op_impl(
const Teuchos::ArrayView<const ConstSubVectorView<Scalar> > &sub_vecs,
const Teuchos::ArrayView<const SubVectorView<Scalar> > &targ_sub_vecs,
const Teuchos::Ptr<ReductTarget> &_reduct_obj
) const
{
using Teuchos::Workspace;
Teuchos::WorkspaceStore* wss =
Teuchos::get_default_workspace_store().get();
const int num_vecs = sub_vecs.size();
const int num_targ_vecs = targ_sub_vecs.size();
RTOp_ReductTarget reduct_obj = RTOp_REDUCT_OBJ_NULL;
if(!is_null(_reduct_obj))
reduct_obj = (*this)(*_reduct_obj);
int k;
Workspace<RTOp_SubVector> c_sub_vecs(wss,num_vecs,false);
for( k = 0; k < num_vecs; ++k ) {
const SubVector& v = sub_vecs[k];
RTOp_sub_vector(v.globalOffset(),v.subDim(),v.values(),v.stride(),&c_sub_vecs[k]);
}
Workspace<RTOp_MutableSubVector> c_targ_sub_vecs(wss,num_targ_vecs,false);
for( k = 0; k < num_targ_vecs; ++k ) {
const MutableSubVector& v = targ_sub_vecs[k];
RTOp_mutable_sub_vector(v.globalOffset(),v.subDim(),v.values(),v.stride(),&c_targ_sub_vecs[k]);
}
const int err = RTOp_apply_op(
&op_
,num_vecs, num_vecs ? &c_sub_vecs[0] : (RTOp_SubVector*)NULL
,num_targ_vecs, num_targ_vecs ? &c_targ_sub_vecs[0] : (RTOp_MutableSubVector*)NULL
,reduct_obj
);
TEUCHOS_TEST_FOR_EXCEPTION(
err==RTOp_ERR_INVALID_NUM_VECS, InvalidNumVecs
,"RTOpC::apply_op(...): Error, "
"RTOp_apply_op(...) returned RTOp_ERR_INVALID_NUM_VECS" );
TEUCHOS_TEST_FOR_EXCEPTION(
err==RTOp_ERR_INVALID_NUM_TARG_VECS, InvalidNumTargVecs
,"RTOpC::apply_op(...): Error, "
"RTOp_apply_op(...) returned RTOp_ERR_INVALID_NUM_TARG_VECS" );
TEUCHOS_TEST_FOR_EXCEPTION(
err!=0, UnknownError
,"RTOpC::apply_op(...): Error, "
"RTOp_apply_op(...) returned != 0 with unknown meaning" );
}
示例9: computeSize
size_type computeSize(const Teuchos::ArrayView< DIM_TYPE > & dimensions)
{
size_type result = 1;
for (int axis = 0; axis < dimensions.size(); ++axis)
result *= dimensions[axis];
return result;
}
示例10:
void Simple2DModelEvaluator<Scalar>::set_p(const Teuchos::ArrayView<const Scalar> &p)
{
#ifdef TEUCHOS_DEBUG
TEUCHOS_ASSERT_EQUALITY(p_.size(), p.size());
#endif
p_().assign(p);
}
示例11: apply
void diff_type_get_copy<MV,S>::
apply (const Teuchos::Ptr<const MV>& mv,
const Teuchos::ArrayView<S>& v,
const size_t& ldx,
Teuchos::Ptr<const Tpetra::Map<typename MV::local_ordinal_t, typename MV::global_ordinal_t, typename MV::node_t> > distribution_map,
EDistribution distribution )
{
typedef typename MV::scalar_t mv_scalar_t;
typedef typename Teuchos::Array<mv_scalar_t>::size_type size_type;
TEUCHOS_TEST_FOR_EXCEPTION(
mv.getRawPtr () == NULL, std::invalid_argument,
"Amesos2::diff_type_get_copy::apply: mv is null.");
TEUCHOS_TEST_FOR_EXCEPTION(
distribution_map.getRawPtr () == NULL, std::invalid_argument,
"Amesos2::diff_type_get_copy::apply: distribution_map is null.");
const size_type vals_length = v.size ();
Teuchos::Array<mv_scalar_t> vals_tmp (vals_length);
mv->get1dCopy (vals_tmp (), ldx, distribution_map, distribution);
for (size_type i = 0; i < vals_length; ++i) {
v[i] = Teuchos::as<S> (vals_tmp[i]);
}
}
示例12:
void
CrsWrapper_GraphBuilder<Scalar, LocalOrdinal, GlobalOrdinal, Node>::
insertGlobalValues (GlobalOrdinal globalRow,
const Teuchos::ArrayView<const GlobalOrdinal> &indices,
const Teuchos::ArrayView<const Scalar> &values)
{
typename std::map<GlobalOrdinal,std::set<GlobalOrdinal>*>::iterator
iter = graph_.find (globalRow);
TEUCHOS_TEST_FOR_EXCEPTION(
iter == graph_.end(), std::runtime_error,
"Tpetra::CrsWrapper_GraphBuilder::insertGlobalValues could not find row "
<< globalRow << " in the graph. Super bummer man. Hope you figure it out.");
std::set<GlobalOrdinal>& cols = * (iter->second);
for (typename Teuchos::ArrayView<const GlobalOrdinal>::size_type i = 0;
i < indices.size (); ++i) {
cols.insert (indices[i]);
}
const global_size_t row_length = static_cast<global_size_t> (cols.size ());
if (row_length > max_row_length_) {
max_row_length_ = row_length;
}
}
示例13: view_type
Kokkos::View<const T*,D>
getKokkosViewDeepCopy(const Teuchos::ArrayView<const T>& a) {
#if defined(KOKKOS_HAVE_PTHREAD)
typedef Kokkos::Threads HostDevice;
#elif defined(KOKKOS_HAVE_OPENMP)
typedef Kokkos::OpenMP HostDevice;
#else
typedef Kokkos::Serial HostDevice;
#endif
typedef Kokkos::View<T*,D> view_type;
typedef Kokkos::View<const T*,typename view_type::array_layout,HostDevice,Kokkos::MemoryUnmanaged> unmanaged_host_view_type;
if (a.size() == 0)
return view_type();
view_type v("", a.size());
unmanaged_host_view_type hv(a.getRawPtr(), a.size());
Kokkos::deep_copy(v,hv);
return v;
}
示例14: y
// Just test whether Teuchos memory management objects and Kokkos
// Array Views can coexist in the same program. This test does not
// have the Teuchos and Kokkos objects interact with each other.
TEUCHOS_UNIT_TEST( LinkTeuchosAndKokkos, NoInteraction ) {
typedef Teuchos::Array<double>::size_type size_type;
const size_type numElts = 10;
Teuchos::Array<double> x (numElts);
for (size_type k = 0; k < numElts; ++k) {
x[k] = 42.0 + static_cast<double> (k);
}
Teuchos::ArrayView<double> xView = x.view (3, 5); // view of [3, 4, 5, 6, 7]
TEST_EQUALITY_CONST( xView.size(), 5 );
for (size_type k = 0; k < xView.size (); ++k) {
TEST_EQUALITY( xView[k], x[k+3] );
}
typedef Kokkos::View<double*, Kokkos::Threads> ka_view_type;
ka_view_type y ("y", numElts);
Kokkos::parallel_for (y.dimension_0 (), FillFunctor<Kokkos::Threads> (y));
}
示例15: view_type
Kokkos::View<const T*,D>
getKokkosViewDeepCopy(const Teuchos::ArrayView<const T>& a)
{
typedef typename Kokkos::Impl::if_c<
Impl::VerifyExecutionCanAccessMemorySpace< D, Kokkos::HostSpace>::value,
typename D::execution_space, Kokkos::HostSpace>::type
HostDevice;
typedef Kokkos::View<T*, D> view_type;
typedef Kokkos::View<const T*, typename view_type::array_layout, HostDevice,
Kokkos::MemoryUnmanaged> unmanaged_host_view_type;
if (a.size () == 0) {
return view_type ();
}
view_type v ("", a.size ());
unmanaged_host_view_type hv (a.getRawPtr (), a.size ());
Kokkos::deep_copy (v, hv);
return v;
}