<commit_before>#include "xchainer/shape.h"

#include <functional>
#include <numeric>

#include "xchainer/strides.h"

namespace xchainer {

namespace internal {

bool IsContiguous(const Shape& shape, const Strides& strides, int64_t element_bytes) {
    Expects(shape.size() == strides.size());
    auto shape_it = shape.rbegin();
    for (auto strides_it = strides.rbegin(); strides_it != strides.rend(); ++shape_it, ++strides_it) {
        if (*strides_it != element_bytes) {
            return false;
        }
        element_bytes *= *shape_it;
    }
    return true;
}
<commit_msg>Fix IsContiguous for cases total_size is 0 or 1<commit_after>#include "xchainer/shape.h"

#include <functional>
#include <numeric>

#include "xchainer/strides.h"

namespace xchainer {

namespace internal {

bool IsContiguous(const Shape& shape, const Strides& strides, int64_t element_bytes) {
    Expects(shape.size() == strides.size());
    int64_t total_size = shape.GetTotalSize();
    if (total_size == 0 || total_size == 1) {
        return true;
    }
    auto shape_it = shape.rbegin();
    for (auto strides_it = strides.rbegin(); strides_it != strides.rend(); ++shape_it, ++strides_it) {
        if (*strides_it != element_bytes) {
            return false;
        }
        element_bytes *= *shape_it;
    }
    return true;
}

{'fraction_non_alphanumeric': 0.1299093655589124, 'fraction_numerical': 0.0075528700906344415, 'mean_word_length': 3.4166666666666665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6493713', 'n_tokens_mistral': 458, 'n_tokens_neox': 434, 'n_words': 104}