Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Sudhanshu Sane
VTK-m
Commits
d77342a7
Commit
d77342a7
authored
May 13, 2015
by
Kenneth Moreland
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ArrayHandleConstant
parent
59618b3a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
121 additions
and
1 deletion
+121
-1
vtkm/cont/ArrayHandleConstant.h
vtkm/cont/ArrayHandleConstant.h
+85
-0
vtkm/cont/ArrayHandleCounting.h
vtkm/cont/ArrayHandleCounting.h
+1
-1
vtkm/cont/CMakeLists.txt
vtkm/cont/CMakeLists.txt
+1
-0
vtkm/cont/testing/TestingFancyArrayHandles.h
vtkm/cont/testing/TestingFancyArrayHandles.h
+34
-0
No files found.
vtkm/cont/ArrayHandleConstant.h
0 → 100644
View file @
d77342a7
//=============================================================================
//
// 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 2015 Sandia Corporation.
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015. 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_cont_ArrayHandleConstant_h
#define vtk_m_cont_ArrayHandleConstant_h
#include <vtkm/cont/ArrayHandleImplicit.h>
namespace
vtkm
{
namespace
cont
{
namespace
detail
{
template
<
typename
ValueType
>
struct
ConstantFunctor
{
VTKM_EXEC_CONT_EXPORT
ConstantFunctor
(
const
ValueType
&
value
=
ValueType
())
:
Value
(
value
)
{
}
VTKM_EXEC_CONT_EXPORT
ValueType
operator
()(
vtkm
::
Id
vtkmNotUsed
(
index
))
const
{
return
this
->
Value
;
}
private:
ValueType
Value
;
};
}
// namespace detail
/// \brief An array handle with a constant value.
///
/// ArrayHandleConstant is an implicit array handle with a constant value. A
/// constant array handle is constructed by giving a value and an array length.
/// The resulting array is of the given size with each entry the same value
/// given in the constructor. The array is defined implicitly, so there it
/// takes (almost) no memory.
///
template
<
typename
T
>
class
ArrayHandleConstant
:
public
vtkm
::
cont
::
ArrayHandleImplicit
<
T
,
detail
::
ConstantFunctor
<
T
>
>
{
typedef
vtkm
::
cont
::
ArrayHandleImplicit
<
T
,
detail
::
ConstantFunctor
<
T
>
>
Superclass
;
public:
VTKM_CONT_EXPORT
ArrayHandleConstant
(
T
value
=
T
(),
vtkm
::
Id
numberOfValues
=
0
)
:
Superclass
(
detail
::
ConstantFunctor
<
T
>
(
value
),
numberOfValues
)
{
}
};
/// make_ArrayHandleImplicit is convenience function to generate an
/// ArrayHandleImplicit. It takes a functor and the virtual length of the
/// arry.
///
template
<
typename
T
>
vtkm
::
cont
::
ArrayHandleConstant
<
T
>
make_ArrayHandleConstant
(
T
value
,
vtkm
::
Id
numberOfValues
)
{
return
vtkm
::
cont
::
ArrayHandleConstant
<
T
>
(
value
,
numberOfValues
);
}
}
}
// vtkm::cont
#endif //vtk_m_cont_ArrayHandleConstant_h
vtkm/cont/ArrayHandleCounting.h
View file @
d77342a7
...
...
@@ -96,7 +96,7 @@ struct ArrayHandleCountingTraits
}
// namespace internal
/// ArrayHandleCounting
s
is a specialization of ArrayHandle. By default it
/// ArrayHandleCounting is a specialization of ArrayHandle. By default it
/// contains a increment value, that is increment for each step between zero
/// and the passed in length
template
<
typename
CountingValueType
>
...
...
vtkm/cont/CMakeLists.txt
View file @
d77342a7
...
...
@@ -23,6 +23,7 @@ include_directories(${Boost_INCLUDE_DIRS})
set
(
headers
ArrayHandle.h
ArrayHandleCompositeVector.h
ArrayHandleConstant.h
ArrayHandleCounting.h
ArrayHandleImplicit.h
ArrayHandlePermutation.h
...
...
vtkm/cont/testing/TestingFancyArrayHandles.h
View file @
d77342a7
...
...
@@ -22,6 +22,7 @@
#ifndef vtk_m_cont_testing_TestingFancyArrayHandles_h
#define vtk_m_cont_testing_TestingFancyArrayHandles_h
#include <vtkm/cont/ArrayHandleConstant.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandleImplicit.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
...
...
@@ -252,6 +253,33 @@ private:
}
};
struct
TestConstantAsInput
{
template
<
typename
ValueType
>
VTKM_CONT_EXPORT
void
operator
()(
const
ValueType
vtkmNotUsed
(
v
))
const
{
const
ValueType
value
=
TestValue
(
43
,
ValueType
());
vtkm
::
cont
::
ArrayHandleConstant
<
ValueType
>
constant
=
vtkm
::
cont
::
make_ArrayHandleConstant
(
value
,
ARRAY_SIZE
);
vtkm
::
cont
::
ArrayHandle
<
ValueType
>
result
;
vtkm
::
worklet
::
DispatcherMapField
<
PassThrough
,
DeviceAdapterTag
>
dispatcher
;
dispatcher
.
Invoke
(
constant
,
result
);
//verify that the control portal works
for
(
vtkm
::
Id
i
=
0
;
i
<
ARRAY_SIZE
;
++
i
)
{
const
ValueType
result_v
=
result
.
GetPortalConstControl
().
Get
(
i
);
const
ValueType
control_value
=
constant
.
GetPortalConstControl
().
Get
(
i
);
VTKM_TEST_ASSERT
(
test_equal
(
result_v
,
value
),
"Counting Handle Failed"
);
VTKM_TEST_ASSERT
(
test_equal
(
result_v
,
control_value
),
"Counting Handle Control Failed"
);
}
}
};
struct
TestCountingAsInput
{
template
<
typename
ValueType
>
...
...
@@ -556,6 +584,12 @@ struct TestPermutationAsOutput
TestingFancyArrayHandles
<
DeviceAdapterTag
>::
TestZipAsInput
(),
ZipTypesToTest
());
std
::
cout
<<
"-------------------------------------------"
<<
std
::
endl
;
std
::
cout
<<
"Testing ArrayHandleConstant as Input"
<<
std
::
endl
;
vtkm
::
testing
::
Testing
::
TryTypes
(
TestingFancyArrayHandles
<
DeviceAdapterTag
>::
TestConstantAsInput
(),
HandleTypesToTest
());
std
::
cout
<<
"-------------------------------------------"
<<
std
::
endl
;
std
::
cout
<<
"Testing ArrayHandleCounting as Input"
<<
std
::
endl
;
vtkm
::
testing
::
Testing
::
TryTypes
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment