12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #include "ceres/block_structure.h"
- #include <vector>
- #include "glog/logging.h"
- namespace ceres::internal {
- bool CellLessThan(const Cell& lhs, const Cell& rhs) {
- if (lhs.block_id == rhs.block_id) {
- return (lhs.position < rhs.position);
- }
- return (lhs.block_id < rhs.block_id);
- }
- std::vector<Block> Tail(const std::vector<Block>& blocks, int n) {
- CHECK_LE(n, blocks.size());
- std::vector<Block> tail;
- const int num_blocks = blocks.size();
- const int start = num_blocks - n;
- int position = 0;
- tail.reserve(n);
- for (int i = start; i < num_blocks; ++i) {
- tail.emplace_back(blocks[i].size, position);
- position += blocks[i].size;
- }
- return tail;
- }
- int SumSquaredSizes(const std::vector<Block>& blocks) {
- int sum = 0;
- for (const auto& b : blocks) {
- sum += b.size * b.size;
- }
- return sum;
- }
- }
|