From eaf87e45191e583fcb0d0890ba8b2383d973cf71 Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 30 Jul 2019 14:43:52 -0600 Subject: [PATCH] Remove special ArrayHandleMultiplexer template case There was a special case for ArrayHandleMultiplexer where if you gave it just one type it would treat that as a value type rather than an array to support and instead provide a default list of types. However, GCC 4.8 is having trouble compiling the code to create the default list, the semantics are confusing, and the more I think about it the less likely I think we will need this functionality. So, just getting rid of that. --- benchmarking/BenchmarkFieldAlgorithms.cxx | 21 +- docs/changelog/array-handle-multiplexer.md | 41 ---- vtkm/cont/ArrayHandleMultiplexer.h | 224 +++--------------- .../testing/TestingArrayHandleMultiplexer.h | 58 +---- 4 files changed, 50 insertions(+), 294 deletions(-) diff --git a/benchmarking/BenchmarkFieldAlgorithms.cxx b/benchmarking/BenchmarkFieldAlgorithms.cxx index eb94d497f..8a7bc4480 100644 --- a/benchmarking/BenchmarkFieldAlgorithms.cxx +++ b/benchmarking/BenchmarkFieldAlgorithms.cxx @@ -306,12 +306,25 @@ template using ArrayHandlePassThrough = vtkm::cont::ArrayHandleTransform; +template +struct JunkArrayHandle : vtkm::cont::ArrayHandle +{ +}; + template using BMArrayHandleMultiplexer = - vtkm::ListTagApply, - ArrayHandlePassThrough>, - vtkm::cont::ArrayHandleMultiplexer>; + vtkm::cont::ArrayHandleMultiplexer, + JunkArrayHandle, + JunkArrayHandle, + JunkArrayHandle, + JunkArrayHandle, + JunkArrayHandle, + JunkArrayHandle, + JunkArrayHandle, + JunkArrayHandle, + JunkArrayHandle, + ArrayHandlePassThrough>; template BMArrayHandleMultiplexer make_ArrayHandleMultiplexer0(const ArrayHandleType& array) diff --git a/docs/changelog/array-handle-multiplexer.md b/docs/changelog/array-handle-multiplexer.md index 2d93fed32..cfb333905 100644 --- a/docs/changelog/array-handle-multiplexer.md +++ b/docs/changelog/array-handle-multiplexer.md @@ -96,47 +96,6 @@ indices = indicesInMemory; All the code that uses `indices` will continue to work. -If `ArrayHandleMultiplexer` is created with only a single template -parameter, then the parameter is interpreted differently. Instead of being -interpreted as a type of array, it is interpreted as the `ValueType` of the -array. In this case, a default set of arrays will set for you. The basic -storage type array will always be part of this list. - -``` cpp -vtkm::cont::ArrayHandleMultiplexer multiplexerArray; - -vtkm::cont::ArrayHandle basicArray; -// Fill basicArray... - -multiplexerArray = basicArray; -``` - -The default list of arrays includes `ArrayHandleCast` from pretty much any -basic type of the same vector length. This allows you to get an -`ArrayHandleMultiplexer` of some known type and then use it for other -types. For example, you can use an integer-based array in a place where you -expect a floating point field. - -``` cpp -vtkm::cont::ArrayHandleMultiplexer multiplexerArray; - -vtkm::cont::ArrayHandle integerField; -// Fill integerField... - -multiplexerArray = vtkm::cont::make_ArrayHandleCast(integerField); -``` - -We (as developers) also have the option of putting in special storage types -for particular value types. For example, the default list of arrays for a -`Vec` include `ArrayHandleUniformPointCoordinates` (whereas -this array cannot be placed in other default lists). - -``` cpp -vtkm::cont::ArrayHandleMultiplexer> multiplexerArray; - -multiplexerArray = vtkm::cont::ArrayHandleUniformPointCoordinates(vtkm::Id3(50)); -``` - ## Variant To implement `ArrayHandleMultiplexer`, the class `vtkm::internal::Variant` diff --git a/vtkm/cont/ArrayHandleMultiplexer.h b/vtkm/cont/ArrayHandleMultiplexer.h index df4085427..81ba3c34b 100644 --- a/vtkm/cont/ArrayHandleMultiplexer.h +++ b/vtkm/cont/ArrayHandleMultiplexer.h @@ -375,13 +375,18 @@ private: namespace detail { -template +template struct ArrayHandleMultiplexerTraits { - // If there is a compile error in this group of lines, then the list tag given to - // ArrayHandleMultiplexer must contain an invalid ArrayHandle. That could mean that - // it is not an ArrayHandle type or it could mean that the value type does not match - // the appropriate value type. + using ArrayHandleType0 = + brigand::at, std::integral_constant>; + VTKM_IS_ARRAY_HANDLE(ArrayHandleType0); + using ValueType = typename ArrayHandleType0::ValueType; + + // If there is a compile error in this group of lines, then one of the array types given to + // ArrayHandleMultiplexer must contain an invalid ArrayHandle. That could mean that it is not an + // ArrayHandle type or it could mean that the value type does not match the appropriate value + // type. template struct CheckArrayHandleTransform { @@ -409,154 +414,6 @@ struct ArrayHandleMultiplexerTraits }; } -/// \brief Base implementation of \c ArrayHandleMultiplexer. -/// -/// This behavies the same as \c ArrayHandleMultiplexer, but the template parameters are -/// more explicit. The first template parameter must be the \c ValueType of the array. -/// The remaining template parameters are the array handles to support. -/// -template -class ArrayHandleMultiplexerBase - : public vtkm::cont::ArrayHandle< - ValueType_, - typename detail::ArrayHandleMultiplexerTraits::StorageTag> -{ - using Traits = detail::ArrayHandleMultiplexerTraits; - -public: - VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleMultiplexerBase, - (ArrayHandleMultiplexerBase), - (vtkm::cont::ArrayHandle)); - -private: - using StorageType = vtkm::cont::internal::Storage; - -public: - template - VTKM_CONT ArrayHandleMultiplexerBase( - const vtkm::cont::ArrayHandle& src) - : Superclass(StorageType(src)) - { - } - - template - VTKM_CONT ArrayHandleMultiplexerBase(vtkm::cont::ArrayHandle&& rhs) - : Superclass(StorageType(std::move(rhs))) - { - } -}; - -namespace internal -{ - -namespace detail -{ - -template -struct MakeArrayListFromStorage -{ - template - using Transform = vtkm::cont::ArrayHandle; -}; - -template -struct SupportedArrays - : vtkm::ListTagTransform::template Transform> -{ -}; - -template -struct MakeCastArrayListImpl -{ - using TypeStoragePairs = vtkm::ListCrossProduct; - - template - struct PairToCastArrayImpl; - template - struct PairToCastArrayImpl> - { - using Type = vtkm::cont::ArrayHandleCast>; - }; - template - using PairToCastArray = typename PairToCastArrayImpl::Type; - - using Type = vtkm::ListTagTransform; -}; - -template -struct MakeCastArrayList -{ - using Type = typename MakeCastArrayListImpl::Type; -}; - -template -struct MakeCastArrayList> -{ - template - using ScalarToVec = vtkm::Vec; - using SourceTypes = vtkm::ListTagTransform; - - using Type = typename MakeCastArrayListImpl, SourceTypes>::Type; -}; - -template -struct ArrayHandleMultiplexerDefaultArraysBase - : vtkm::ListTagJoin, typename MakeCastArrayList::Type> -{ -}; - -} // namespace detail - -template -struct ArrayHandleMultiplexerDefaultArrays : detail::ArrayHandleMultiplexerDefaultArraysBase -{ -}; - -template <> -struct ArrayHandleMultiplexerDefaultArrays> - : vtkm::ListTagJoin< - detail::ArrayHandleMultiplexerDefaultArraysBase>, - vtkm::ListTagBase< -#if 1 - vtkm::cont::ArrayHandleCartesianProduct, - vtkm::cont::ArrayHandle, - vtkm::cont::ArrayHandle>, -#endif - vtkm::cont::ArrayHandleUniformPointCoordinates>> -{ -}; - -} // namespace internal - -namespace detail -{ - -template -struct ArrayHandleMultiplexerChooseBaseImpl -{ - VTKM_IS_LIST_TAG(ListTagArrays); - - template - struct BrigandListArraysToArrayHandleMultiplexerBase; - - template - struct BrigandListArraysToArrayHandleMultiplexerBase> - { - using Type = vtkm::cont::ArrayHandleMultiplexerBase; - }; - - using Type = typename BrigandListArraysToArrayHandleMultiplexerBase< - vtkm::internal::ListTagAsBrigandList>::Type; -}; - -template -using ArrayHandleMultiplexerChooseBase = typename ArrayHandleMultiplexerChooseBaseImpl< - ValueType, - internal::ArrayHandleMultiplexerDefaultArrays>::Type; - -} // namespace detail - /// \brief An ArrayHandle that can behave like several other handles. /// /// An \c ArrayHandleMultiplexer simply redirects its calls to another \c ArrayHandle. However @@ -568,58 +425,41 @@ using ArrayHandleMultiplexerChooseBase = typename ArrayHandleMultiplexerChooseBa /// see which type of array is currently stored in it. It then redirects to the \c ArrayHandle /// of the appropriate type. /// +/// The \c ArrayHandleMultiplexer template parameters are all the ArrayHandle types it +/// should support. +/// /// If only one template parameter is given, it is assumed to be the \c ValueType of the /// array. A default list of supported arrays is supported (see /// \c vtkm::cont::internal::ArrayHandleMultiplexerDefaultArrays.) If multiple template /// parameters are given, they are all considered possible \c ArrayHandle types. /// -template -class ArrayHandleMultiplexer; - -template -class ArrayHandleMultiplexer - : public detail::ArrayHandleMultiplexerChooseBase +template +class ArrayHandleMultiplexer + : public vtkm::cont::ArrayHandle< + typename detail::ArrayHandleMultiplexerTraits::ValueType, + typename detail::ArrayHandleMultiplexerTraits::StorageTag> { + using Traits = detail::ArrayHandleMultiplexerTraits; + public: - VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleMultiplexer, - (ArrayHandleMultiplexer), - (detail::ArrayHandleMultiplexerChooseBase)); + VTKM_ARRAY_HANDLE_SUBCLASS( + ArrayHandleMultiplexer, + (ArrayHandleMultiplexer), + (vtkm::cont::ArrayHandle)); - template - VTKM_CONT ArrayHandleMultiplexer(const vtkm::cont::ArrayHandle& src) - : Superclass(src) - { - } +private: + using StorageType = vtkm::cont::internal::Storage; - template - VTKM_CONT ArrayHandleMultiplexer(vtkm::cont::ArrayHandle&& rhs) - : Superclass(std::move(rhs)) - { - } -}; - -template -class ArrayHandleMultiplexer - : public vtkm::cont::ArrayHandleMultiplexerBase -{ public: - VTKM_ARRAY_HANDLE_SUBCLASS(ArrayHandleMultiplexer, - (ArrayHandleMultiplexer), - (vtkm::cont::ArrayHandleMultiplexerBase)); - - template - VTKM_CONT ArrayHandleMultiplexer(const vtkm::cont::ArrayHandle& src) - : Superclass(src) + template + VTKM_CONT ArrayHandleMultiplexer(const vtkm::cont::ArrayHandle& src) + : Superclass(StorageType(src)) { } - template - VTKM_CONT ArrayHandleMultiplexer(vtkm::cont::ArrayHandle&& rhs) - : Superclass(std::move(rhs)) + template + VTKM_CONT ArrayHandleMultiplexer(vtkm::cont::ArrayHandle&& rhs) + : Superclass(StorageType(std::move(rhs))) { } }; diff --git a/vtkm/cont/testing/TestingArrayHandleMultiplexer.h b/vtkm/cont/testing/TestingArrayHandleMultiplexer.h index 0be07d673..b8402b097 100644 --- a/vtkm/cont/testing/TestingArrayHandleMultiplexer.h +++ b/vtkm/cont/testing/TestingArrayHandleMultiplexer.h @@ -86,63 +86,7 @@ class TestingArrayHandleMultiplexer CheckArray(multiplexer, array3); } - static void DefaultScalar() - { - std::cout << std::endl << "--- Default list for scalars" << std::endl; - - using ValueType = vtkm::FloatDefault; - - vtkm::cont::ArrayHandleMultiplexer multiplexer; - - std::cout << "Basic array type." << std::endl; - vtkm::cont::ArrayHandle baseArray; - baseArray.Allocate(ARRAY_SIZE); - SetPortal(baseArray.GetPortalControl()); - multiplexer = baseArray; - CheckArray(multiplexer, baseArray); - - std::cout << "Cast array type." << std::endl; - vtkm::cont::ArrayHandle castArray; - castArray.Allocate(ARRAY_SIZE); - SetPortal(castArray.GetPortalControl()); - multiplexer = vtkm::cont::make_ArrayHandleCast(castArray); - CheckArray(multiplexer, castArray); - } - - static void DefaultVec3() - { - std::cout << std::endl << "--- Default list for Vec3" << std::endl; - - using ValueType = vtkm::Vec; - - vtkm::cont::ArrayHandleMultiplexer multiplexer; - - std::cout << "Basic array type." << std::endl; - vtkm::cont::ArrayHandle baseArray; - baseArray.Allocate(ARRAY_SIZE); - SetPortal(baseArray.GetPortalControl()); - multiplexer = baseArray; - CheckArray(multiplexer, baseArray); - - std::cout << "Cast array type." << std::endl; - vtkm::cont::ArrayHandle> castArray; - castArray.Allocate(ARRAY_SIZE); - SetPortal(castArray.GetPortalControl()); - multiplexer = vtkm::cont::make_ArrayHandleCast(castArray); - CheckArray(multiplexer, castArray); - - std::cout << "Uniform point coordinates" << std::endl; - vtkm::cont::ArrayHandleUniformPointCoordinates uniformCoords(vtkm::Id3(3)); - multiplexer = uniformCoords; - CheckArray(multiplexer, uniformCoords); - } - - static void TestAll() - { - BasicSwitch(); - DefaultScalar(); - DefaultVec3(); - } + static void TestAll() { BasicSwitch(); } public: static int Run(int argc, char* argv[])