Viskores  1.0
ArrayHandleIndex.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_ArrayHandleIndex_h
19 #define viskores_cont_ArrayHandleIndex_h
20 
21 #include <viskores/Range.h>
23 
24 namespace viskores
25 {
26 
27 namespace internal
28 {
29 
30 struct VISKORES_ALWAYS_EXPORT IndexFunctor
31 {
32  VISKORES_EXEC_CONT viskores::Id operator()(viskores::Id index) const { return index; }
33 };
34 
35 } // namespace internal
36 
37 namespace cont
38 {
39 
40 struct VISKORES_ALWAYS_EXPORT StorageTagIndex
41 {
42 };
43 
44 namespace internal
45 {
46 
47 using StorageTagIndexSuperclass =
49 
50 template <>
52  : Storage<viskores::Id, StorageTagIndexSuperclass>
53 {
54 };
55 
56 } // namespace internal
57 
64 class ArrayHandleIndex : public viskores::cont::ArrayHandle<viskores::Id, StorageTagIndex>
65 {
66 public:
69 
73  : Superclass(
74  internal::FunctorToArrayHandleImplicitBuffers(viskores::internal::IndexFunctor{}, length))
75  {
76  }
77 };
78 
82 {
83  return viskores::cont::ArrayHandleIndex(length);
84 }
85 
86 namespace internal
87 {
88 
89 template <typename S>
90 struct ArrayRangeComputeImpl;
91 
92 template <>
93 struct VISKORES_CONT_EXPORT ArrayRangeComputeImpl<viskores::cont::StorageTagIndex>
94 {
98  bool computeFiniteRange,
99  viskores::cont::DeviceAdapterId device) const;
100 };
101 
102 template <typename S>
103 struct ArrayRangeComputeMagnitudeImpl;
104 
105 template <>
106 struct VISKORES_CONT_EXPORT ArrayRangeComputeMagnitudeImpl<viskores::cont::StorageTagIndex>
107 {
108  VISKORES_CONT viskores::Range operator()(
111  bool computeFiniteRange,
112  viskores::cont::DeviceAdapterId device) const
113  {
114  auto rangeAH = ArrayRangeComputeImpl<viskores::cont::StorageTagIndex>{}(
115  input, maskArray, computeFiniteRange, device);
116  return rangeAH.ReadPortal().Get(0);
117  }
118 };
119 
120 } // namespace internal
121 
122 }
123 } // namespace viskores::cont
124 
125 //=============================================================================
126 // Specializations of serialization related classes
128 
129 namespace viskores
130 {
131 namespace cont
132 {
133 
134 template <>
135 struct SerializableTypeString<viskores::cont::ArrayHandleIndex>
136 {
137  static VISKORES_CONT std::string Get() { return "AH_Index"; }
138 };
139 
140 template <>
141 struct SerializableTypeString<
142  viskores::cont::ArrayHandle<viskores::Id, viskores::cont::StorageTagIndex>>
143  : SerializableTypeString<viskores::cont::ArrayHandleIndex>
144 {
145 };
146 }
147 } // viskores::cont
148 
149 namespace mangled_diy_namespace
150 {
151 
152 template <>
153 struct Serialization<viskores::cont::ArrayHandleIndex>
154 {
155 private:
157 
158 public:
159  static VISKORES_CONT void save(BinaryBuffer& bb, const BaseType& obj)
160  {
161  viskoresdiy::save(bb, obj.GetNumberOfValues());
162  }
163 
164  static VISKORES_CONT void load(BinaryBuffer& bb, BaseType& obj)
165  {
166  viskores::Id length = 0;
167  viskoresdiy::load(bb, length);
168 
169  obj = viskores::cont::ArrayHandleIndex(length);
170  }
171 };
172 
173 template <>
174 struct Serialization<viskores::cont::ArrayHandle<viskores::Id, viskores::cont::StorageTagIndex>>
175  : Serialization<viskores::cont::ArrayHandleIndex>
176 {
177 };
178 } // diy
180 
181 #endif //viskores_cont_ArrayHandleIndex_h
viskores::exec::arg::load
T load(const U &u, viskores::Id v)
Definition: FetchTagArrayDirectIn.h:44
viskores::cont::ArrayHandleIndex::Superclass
viskores::cont::detail::GetTypeInParentheses< void(viskores::cont::ArrayHandle< viskores::Id, StorageTagIndex >) >::type Superclass
Definition: ArrayHandleIndex.h:68
viskores::cont::ArrayHandleIndex::ArrayHandleIndex
ArrayHandleIndex(viskores::Id length)
Construct an index array containing values from 0 to length - 1.
Definition: ArrayHandleIndex.h:72
viskores::cont::make_ArrayHandleIndex
viskores::cont::ArrayHandleIndex make_ArrayHandleIndex(viskores::Id length)
A convenience function for creating an ArrayHandleIndex.
Definition: ArrayHandleIndex.h:81
VISKORES_ARRAY_HANDLE_SUBCLASS_NT
#define VISKORES_ARRAY_HANDLE_SUBCLASS_NT(classname, superclass)
Macro to make default methods in ArrayHandle subclasses.
Definition: ArrayHandle.h:279
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
VISKORES_EXEC_CONT
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
mangled_diy_namespace
Definition: Particle.h:373
viskores::cont::ArrayHandleImplicit::StorageTag
typename Superclass::StorageTag StorageTag
Definition: ArrayHandleImplicit.h:196
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
Range.h
viskores::cont::StorageTagIndex
Definition: ArrayHandleIndex.h:40
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
viskores::Range
Represent a continuous scalar range of values.
Definition: Range.h:39
viskores::Get
auto Get(const viskores::Tuple< Ts... > &tuple)
Retrieve the object from a viskores::Tuple at the given index.
Definition: Tuple.h:89
ArrayHandleImplicit.h
viskores::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:64