// Copyright (c) 2021 CINN Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #include #include #include #include #include #include namespace cinn { namespace utils { template std::vector Map(const InT &in, std::function fn) { std::vector res; std::transform( in.begin(), in.end(), std::back_inserter(res), [&](const typename InT::value_type &x) { return fn(x); }); return res; } template auto Min(T &&t) { return t; } template auto Min(T &&t, Ts &&...ts) { return std::min(t, Min(ts...)); } template auto Max(T &&t) { return t; } template auto Max(T &&t, Ts &&...ts) { return std::max(t, Max(ts...)); } template struct IsVector { template static auto infer(U *) -> std::enable_if_t, U>::value, std::true_type>; template static std::false_type infer(...); static constexpr bool value = decltype(infer>>(nullptr))::value; }; template struct IsString : std::integral_constant>::value> {}; template auto Flatten(const absl::optional> &c) -> std::enable_if_t::value || IsString::value, std::vector> { return c ? std::vector{c->get()} : std::vector{}; } template