mirror of
https://github.com/ceres-solver/ceres-solver.git
synced 2026-08-29 16:40:38 +08:00
0a53aa9054
1. Add abseil-cpp as a submodule. We are tracking the latest LTS release, which is lts_2024_01_16. 2. Replace glog/gflags with absl::log and absl::flags. 3. Remove miniglog 4. Also take a whack at making the bazel build work with abseil-cpp and gtest. There are a number of TODOs in this CL that still need to be resolved. Change-Id: I39355ed7d61375be4ebcbc8596d9cc70acc1c678
93 lines
3.8 KiB
C++
93 lines
3.8 KiB
C++
//
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
// this list of conditions and the following disclaimer.
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
// and/or other materials provided with the distribution.
|
|
// * Neither the name of Google Inc. nor the names of its contributors may be
|
|
// used to endorse or promote products derived from this software without
|
|
// specific prior written permission.
|
|
//
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
//
|
|
// Author: jodebo_beck@gmx.de (Johannes Beck)
|
|
|
|
#include "ceres/internal/parameter_dims.h"
|
|
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
namespace ceres {
|
|
namespace internal {
|
|
|
|
// Static parameter dims unit test
|
|
static_assert(
|
|
std::is_same<StaticParameterDims<4, 2, 1>::Parameters,
|
|
std::integer_sequence<int, 4, 2, 1>>::value == true,
|
|
"Unit test of type 'parameters' for static parameter dims failed.");
|
|
|
|
static_assert(StaticParameterDims<4, 2, 1>::kIsValid == true,
|
|
"Unit test of is valid for static parameter dims failed.");
|
|
static_assert(StaticParameterDims<4, 2, 1>::kIsDynamic == false,
|
|
"Unit test of is dynamic for static parameter dims failed.");
|
|
static_assert(StaticParameterDims<4, 2, 1>::kNumParameterBlocks == 3,
|
|
"Unit test of number of parameter blocks for static parameter "
|
|
"dims failed.");
|
|
static_assert(
|
|
StaticParameterDims<4, 2, 1>::kNumParameters == 7,
|
|
"Unit test of number of parameters for static parameter dims failed.");
|
|
|
|
// Dynamic parameter dims unit test
|
|
static_assert(DynamicParameterDims::kIsValid == true,
|
|
"Unit test of is valid for dynamic parameter dims failed.");
|
|
static_assert(DynamicParameterDims::kIsDynamic == true,
|
|
"Unit test of is dynamic for dynamic parameter dims failed.");
|
|
static_assert(DynamicParameterDims::kNumParameterBlocks == 0,
|
|
"Unit test of number if parameter blocks for dynamic parameter "
|
|
"dims failed.");
|
|
static_assert(
|
|
DynamicParameterDims::kNumParameters == 0,
|
|
"Unit test of number of parameters for dynamic parameter dims failed.");
|
|
|
|
TEST(ParameterDims, GetDims) {
|
|
constexpr int N0 = 3;
|
|
constexpr int N1 = 4;
|
|
constexpr int N2 = 2;
|
|
|
|
StaticParameterDims<N0, N1, N2> params;
|
|
EXPECT_EQ(N0, params.GetDim(0));
|
|
EXPECT_EQ(N1, params.GetDim(1));
|
|
EXPECT_EQ(N2, params.GetDim(2));
|
|
}
|
|
|
|
TEST(ParameterDims, GetUnpackedParameters) {
|
|
constexpr int N0 = 3;
|
|
constexpr int N1 = 4;
|
|
constexpr int N2 = 2;
|
|
|
|
using ParameterDims = StaticParameterDims<N0, N1, N2>;
|
|
|
|
std::array<double, ParameterDims::kNumParameters> packed_parameters{};
|
|
std::array<double*, 3> unpacked_parameters =
|
|
ParameterDims::GetUnpackedParameters(packed_parameters.data());
|
|
|
|
EXPECT_EQ(packed_parameters.data(), unpacked_parameters[0]);
|
|
EXPECT_EQ(packed_parameters.data() + N0, unpacked_parameters[1]);
|
|
EXPECT_EQ(packed_parameters.data() + N0 + N1, unpacked_parameters[2]);
|
|
}
|
|
|
|
} // namespace internal
|
|
} // namespace ceres
|