Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Pietro Max Marsella committed Jan 11, 2025
1 parent a17c76e commit a56201c
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions lib/utils/include/utils/containers/zip.h
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#ifndef _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_CONTAINERS_ZIP_H
#define _FLEXFLOW_LIB_UTILS_INCLUDE_UTILS_CONTAINERS_ZIP_H

#include "fmt/format.h"
#include "utils/exception.h"
#include <tuple>
#include <utility>
#include <vector>
#include "utils/exception.h"
#include "fmt/format.h"

namespace FlexFlow {

template <typename L, typename R>
std::vector<std::pair<L, R>> zip(std::vector<L> const &l,
std::vector<R> const &r,
bool strict = false) {
std::vector<std::pair<L, R>>
zip(std::vector<L> const &l, std::vector<R> const &r, bool strict = false) {
if (strict && l.size() != r.size()) {
throw mk_runtime_error(fmt::format(
"When strict = true, vector sizes must match. Got vectors of length {} and {}",
l.size(), r.size()));
throw mk_runtime_error(fmt::format("When strict = true, vector sizes must "
"match. Got vectors of length {} and {}",
l.size(),
r.size()));
}

std::vector<std::pair<L, R>> result;
Expand All @@ -28,15 +28,18 @@ std::vector<std::pair<L, R>> zip(std::vector<L> const &l,

template <typename A, typename B, typename C>
std::vector<std::tuple<A, B, C>> zip(std::vector<A> const &a,
std::vector<B> const &b,
std::vector<C> const &c,
bool strict = false) {
std::vector<B> const &b,
std::vector<C> const &c,
bool strict = false) {
if (strict && (a.size() != b.size() || b.size() != c.size())) {
throw std::runtime_error(fmt::format(
"When strict = true, vectors sizes must match. Got vectors of length {}, {} and {}",
a.size(), b.size(), c.size()));
throw std::runtime_error(
fmt::format("When strict = true, vectors sizes must match. Got vectors "
"of length {}, {} and {}",
a.size(),
b.size(),
c.size()));
}

std::vector<std::tuple<A, B, C>> result;
for (int i = 0; i < std::min({a.size(), b.size(), c.size()}); i++) {
result.push_back(std::make_tuple(a.at(i), b.at(i), c.at(i)));
Expand Down

0 comments on commit a56201c

Please sign in to comment.