mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Add vtkm/UnaryPredicates header.
Currently includes the following predicates: - IsDefaultConstructor - NotDefaultConstructor - LogicalNot
This commit is contained in:
parent
780f3fea29
commit
d3fd571ef2
@ -34,6 +34,7 @@ set(headers
|
||||
TypeTraits.h
|
||||
VectorAnalysis.h
|
||||
VecTraits.h
|
||||
UnaryPredicates.h
|
||||
)
|
||||
|
||||
vtkm_pyexpander_generated_file(Math.h)
|
||||
|
12
vtkm/Types.h
12
vtkm/Types.h
@ -1099,18 +1099,6 @@ VTK_M_SCALAR_DOT(vtkm::UInt64)
|
||||
VTK_M_SCALAR_DOT(vtkm::Float32)
|
||||
VTK_M_SCALAR_DOT(vtkm::Float64)
|
||||
|
||||
|
||||
/// Predicate that takes a single argument \c x, and returns
|
||||
/// True if it isn't the identity of the Type \p T.
|
||||
template<typename T>
|
||||
struct not_default_constructor
|
||||
{
|
||||
VTKM_EXEC_CONT_EXPORT bool operator()(const T &x) const
|
||||
{
|
||||
return (x != T());
|
||||
}
|
||||
};
|
||||
|
||||
} // End of namespace vtkm
|
||||
|
||||
// Declared outside of vtkm namespace so that the operator works with all code.
|
||||
|
65
vtkm/UnaryPredicates.h
Normal file
65
vtkm/UnaryPredicates.h
Normal file
@ -0,0 +1,65 @@
|
||||
//============================================================================
|
||||
// Copyright (c) Kitware, Inc.
|
||||
// All rights reserved.
|
||||
// See LICENSE.txt for details.
|
||||
// This software is distributed WITHOUT ANY WARRANTY; without even
|
||||
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
// PURPOSE. See the above copyright notice for more information.
|
||||
//
|
||||
// Copyright 2014 Sandia Corporation.
|
||||
// Copyright 2014 UT-Battelle, LLC.
|
||||
// Copyright 2014 Los Alamos National Security.
|
||||
//
|
||||
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
|
||||
// the U.S. Government retains certain rights in this software.
|
||||
//
|
||||
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
#ifndef vtk_m_UnaryPredicates_h
|
||||
#define vtk_m_UnaryPredicates_h
|
||||
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/internal/ExportMacros.h>
|
||||
|
||||
namespace vtkm {
|
||||
|
||||
/// Predicate that takes a single argument \c x, and returns
|
||||
/// True if it is the identity of the Type \p T.
|
||||
struct IsZeroInitialized
|
||||
{
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT bool operator()(const T &x) const
|
||||
{
|
||||
return (x == vtkm::TypeTraits<T>::ZeroInitialization() );
|
||||
}
|
||||
};
|
||||
|
||||
/// Predicate that takes a single argument \c x, and returns
|
||||
/// True if it isn't the identity of the Type \p T.
|
||||
struct NotZeroInitialized
|
||||
{
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT bool operator()(const T &x) const
|
||||
{
|
||||
return (x != vtkm::TypeTraits<T>::ZeroInitialization() );
|
||||
}
|
||||
};
|
||||
|
||||
/// Predicate that takes a single argument \c x, and returns
|
||||
/// True if and only if \c x is \c false.
|
||||
/// Note: Requires Type \p T to be convertible to \c bool or implement the
|
||||
/// ! operator.
|
||||
struct LogicalNot
|
||||
{
|
||||
template<typename T>
|
||||
VTKM_EXEC_CONT_EXPORT bool operator()(const T& x) const
|
||||
{
|
||||
return !x;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace vtkm
|
||||
|
||||
#endif //vtk_m_UnaryPredicates_h
|
@ -21,11 +21,12 @@
|
||||
#ifndef vtk_m_cont_cuda_internal_DeviceAdapterThrust_h
|
||||
#define vtk_m_cont_cuda_internal_DeviceAdapterThrust_h
|
||||
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ErrorExecution.h>
|
||||
#include <vtkm/cont/Timer.h>
|
||||
#include <vtkm/Types.h>
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/UnaryPredicates.h>
|
||||
|
||||
#include <vtkm/cont/cuda/internal/MakeThrustIterator.h>
|
||||
|
||||
@ -977,7 +978,7 @@ public:
|
||||
::thrust::make_counting_iterator<vtkm::Id>(size),
|
||||
stencil.PrepareForInput(DeviceAdapterTag()),
|
||||
output.PrepareForOutput(size, DeviceAdapterTag()),
|
||||
::vtkm::not_default_constructor<T>());
|
||||
::vtkm::NotZeroInitialized());
|
||||
output.Shrink(newSize);
|
||||
}
|
||||
|
||||
@ -995,7 +996,7 @@ public:
|
||||
vtkm::Id newSize = CopyIfPortal(input.PrepareForInput(DeviceAdapterTag()),
|
||||
stencil.PrepareForInput(DeviceAdapterTag()),
|
||||
output.PrepareForOutput(size, DeviceAdapterTag()),
|
||||
::vtkm::not_default_constructor<T>()); //yes on the stencil
|
||||
::vtkm::NotZeroInitialized()); //yes on the stencil
|
||||
output.Shrink(newSize);
|
||||
}
|
||||
|
||||
|
@ -20,13 +20,14 @@
|
||||
#ifndef vtk_m_cont_internal_DeviceAdapterAlgorithmGeneral_h
|
||||
#define vtk_m_cont_internal_DeviceAdapterAlgorithmGeneral_h
|
||||
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/cont/ArrayHandle.h>
|
||||
#include <vtkm/cont/ArrayHandleCounting.h>
|
||||
#include <vtkm/cont/ArrayHandleImplicit.h>
|
||||
#include <vtkm/cont/ArrayHandleZip.h>
|
||||
#include <vtkm/cont/ArrayPortalToIterators.h>
|
||||
#include <vtkm/cont/StorageBasic.h>
|
||||
#include <vtkm/TypeTraits.h>
|
||||
#include <vtkm/UnaryPredicates.h>
|
||||
|
||||
#include <vtkm/exec/FunctorBase.h>
|
||||
|
||||
@ -1182,7 +1183,7 @@ template<typename T, typename U, class CIn, class CStencil, class COut>
|
||||
const vtkm::cont::ArrayHandle<U,CStencil>& stencil,
|
||||
vtkm::cont::ArrayHandle<T,COut>& output)
|
||||
{
|
||||
::vtkm::not_default_constructor<U> unary_predicate;
|
||||
::vtkm::NotZeroInitialized unary_predicate;
|
||||
DerivedAlgorithm::StreamCompact(input, stencil, output, unary_predicate);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user