Repository: ggerganov/llama.cpp
File: vendor/minja/minja.hpp (C++)

Code before:
          auto wrap = [len](int64_t i) -> int64_t {
            if (i < 0) {
              return i + len;
            }
            return i;
          };
          int64_t step = slice->step ? slice->step->evaluate(context).get<int64_t>() : 1;
          if (!step) {
            throw std::runtime_error("slice step cannot be zero");
          }
          int64_t start = slice->start ? wrap(slice->start->evaluate(context).get<int64_t>()) : (step < 0 ? len - 1 : 0);
          int64_t end = slice->end ? wrap(slice->end->evaluate(context).get<int64_t>()) : (step < 0 ? -1 : len);
          if (target_value.is_string()) {
            std::string s = target_value.get<std::string>();

            std::string result;
            if (start < end && step == 1) {
              result = s.substr(start, end - start);
            } else {
              for (int64_t i = start; step > 0 ? i < end : i > end; i += step) {
                result += s[i];
              }
            }
            return result;

          } else if (target_value.is_array()) {            
            auto result = Value::array();
            for (int64_t i = start; step > 0 ? i < end : i > end; i += step) {
              result.push_back(target_value.at(i));
            }
            return result;
          } else {
            throw std::runtime_error(target_value.is_null() ? "Cannot subscript null" : "Subscripting only supported on arrays and strings");
          }
        } else {
          auto index_value = index->evaluate(context);
          if (target_value.is_null()) {
            if (auto t = dynamic_cast<VariableExpr*>(base.get())) {
              throw std::runtime_error("'" + t->get_name() + "' is " + (context->contains(t->get_name()) ? "null" : "not defined"));
            }
            throw std::runtime_error("Trying to access property '" +  index_value.dump() + "' on null!");
          }
          return target_value.get(index_value);
        }
    }
};

class UnaryOpExpr : public Expression {
public:
    enum class Op { Plus, Minus, LogicalNot, Expansion, ExpansionDict };
    std::shared_ptr<Expression> expr;

Review comment (suggestion):
```suggestion
          } else if (target_value.is_array()) {
```

Code after:
          auto wrap = [len](int64_t i) -> int64_t {
            if (i < 0) {
              return i + len;
            }
            return i;
          };
          int64_t step = slice->step ? slice->step->evaluate(context).get<int64_t>() : 1;
          if (!step) {
            throw std::runtime_error("slice step cannot be zero");
          }
          int64_t start = slice->start ? wrap(slice->start->evaluate(context).get<int64_t>()) : (step < 0 ? len - 1 : 0);
          int64_t end = slice->end ? wrap(slice->end->evaluate(context).get<int64_t>()) : (step < 0 ? -1 : len);
          if (target_value.is_string()) {
            std::string s = target_value.get<std::string>();

            std::string result;
            if (start < end && step == 1) {
              result = s.substr(start, end - start);
            } else {
              for (int64_t i = start; step > 0 ? i < end : i > end; i += step) {
                result += s[i];
              }
            }
            return result;

          } else if (target_value.is_array()) {
            auto result = Value::array();
            for (int64_t i = start; step > 0 ? i < end : i > end; i += step) {
              result.push_back(target_value.at(i));
            }
            return result;
          } else {
            throw std::runtime_error(target_value.is_null() ? "Cannot subscript null" : "Subscripting only supported on arrays and strings");
          }
        } else {
          auto index_value = index->evaluate(context);
          if (target_value.is_null()) {
            if (auto t = dynamic_cast<VariableExpr*>(base.get())) {
              throw std::runtime_error("'" + t->get_name() + "' is " + (context->contains(t->get_name()) ? "null" : "not defined"));
            }
            throw std::runtime_error("Trying to access property '" +  index_value.dump() + "' on null!");
          }
          return target_value.get(index_value);
        }
    }
};

class UnaryOpExpr : public Expression {
public:
    enum class Op { Plus, Minus, LogicalNot, Expansion, ExpansionDict };
    std::shared_ptr<Expression> expr;