From 13e54858634e01da07ef813c228bb7f015bdfcf4 Mon Sep 17 00:00:00 2001 From: chn Date: Tue, 13 Aug 2024 23:44:54 +0800 Subject: [PATCH] packages.biu: add Eigen serialization --- flake.nix | 10 --- packages/biu/include/biu.hpp | 3 +- packages/biu/include/biu/eigen.hpp | 88 +++++++++++++--------- packages/biu/include/biu/eigen.tpp | 111 +++++++++++++++++++++++----- packages/ufo/include/ufo/fold.hpp | 1 + packages/ufo/include/ufo/solver.hpp | 13 +--- 6 files changed, 152 insertions(+), 74 deletions(-) diff --git a/flake.nix b/flake.nix index 23a9154d..83137c00 100644 --- a/flake.nix +++ b/flake.nix @@ -83,16 +83,6 @@ system = "x86_64-linux"; config.allowUnfree = true; overlays = [ inputs.self.overlays.default ]; - crossOverlays = [(final: prev: - { - boost = prev.boost.override { zstd = null; }; - magic-enum = prev.magic-enum.overrideAttrs (prev: { cmakeFlags = prev.cmakeFlags ++ - [ "-DMAGIC_ENUM_OPT_BUILD_EXAMPLES=OFF" "-DMAGIC_ENUM_OPT_BUILD_TESTS=OFF" ]; }); - range-v3 = prev.range-v3.overrideAttrs (prev: { cmakeFlags = prev.cmakeFlags ++ - [ "-DRANGE_V3_DOCS=OFF" "-DRANGE_V3_TESTS=OFF" "-DRANGE_V3_EXAMPLES=OFF" ]; }); - abseil-cpp = prev.abseil-cpp.overrideAttrs (prev: { buildInputs = prev.buildInputs ++ - [ final.windows.pthreads ]; }); - })]; }); default = inputs.nixpkgs.legacyPackages.x86_64-linux.writeText "systems" (builtins.concatStringsSep "\n" (builtins.map diff --git a/packages/biu/include/biu.hpp b/packages/biu/include/biu.hpp index d0801e3f..ac4a5fa3 100644 --- a/packages/biu/include/biu.hpp +++ b/packages/biu/include/biu.hpp @@ -5,7 +5,8 @@ # include # include # include +# include // # include // # include -// # include + diff --git a/packages/biu/include/biu/eigen.hpp b/packages/biu/include/biu/eigen.hpp index a648bce7..a5959914 100644 --- a/packages/biu/include/biu/eigen.hpp +++ b/packages/biu/include/biu/eigen.hpp @@ -6,49 +6,69 @@ namespace biu { - namespace detail_::eigen + namespace eigen { - // user-specified size of destination container: dynamic, unspecified(use default), or fixed - constexpr std::size_t dynamicSize = std::dynamic_extent, unspecifiedSize = std::dynamic_extent - 1; - static_assert(std::dynamic_extent == std::numeric_limits::max()); + namespace detail_ + { + // user-specified size of destination container: dynamic, unspecified(use default), or fixed + constexpr std::size_t dynamicSize = std::dynamic_extent, unspecifiedSize = std::dynamic_extent - 1; + static_assert(std::dynamic_extent == std::numeric_limits::max()); - // supported types of standard containers - template struct SpecializationOfArrayHelper : std::false_type {}; - template - struct SpecializationOfArrayHelper, Scalar> : std::true_type {}; - template - struct SpecializationOfArrayHelper, void> : std::true_type {}; - template concept SpecializationOfArray = - SpecializationOfArrayHelper::value; - template concept StandardContainer = - SpecializationOf || SpecializationOfArray; + // supported types of standard containers + template struct SpecializationOfArrayHelper : std::false_type {}; + template + struct SpecializationOfArrayHelper, Scalar> : std::true_type {}; + template + struct SpecializationOfArrayHelper, void> : std::true_type {}; + template concept SpecializationOfArray = + SpecializationOfArrayHelper::value; + template concept StandardContainer = + SpecializationOf || SpecializationOfArray; + + // deduce the size of the destination Eigen container + // if no size is specified, convert std::vector to dynamic-size Eigen::Vector, + // std::array to fixed-size Eigen::Vector; + // if size is std::dynamic_extent, always convert to dynamic-size Eigen::Vector + // if size is specified as a number, convert to fixed-size Eigen::Vector if specified size equals the size of the + // input, otherwise throw an error + // return deduced size if the size is deducible in compile time, otherwise return Empty + template auto deduce_eigen_size(); + + // helper operator| to specify the size of the destination container + template struct ToEigenHelper {}; + } - // helper operator| to specify the size of the destination container // usage: some_value | toEigen - template struct ToEigenHelper {}; - template - inline constexpr ToEigenHelper toEigen; - // convert 1D standard container to Eigen::Vector - // if no size is specified, convert std::vector to dynamic-size Eigen::Vector, - // std::array to fixed-size Eigen::Vector; - // if size is std::dynamic_extent, always convert to dynamic-size Eigen::Vector - // if size is specified as a number, convert to fixed-size Eigen::Vector if specified size equals the size of the - // input, otherwise throw an error - template