<commit_before>/*******************************************************
 * Copyright (c) 2016, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#pragma once
#include <af/defines.h>
#include <Array.hpp>
#include <utility.hpp>
#include <math.hpp>

namespace cpu
{
namespace kernel
{


template<typename T>
void moments(Array<float> &output, Array<T> const &input, af_moment_type moment)
{
    T const * const in       = input.get();
    af::dim4  const idims    = input.dims();
    af::dim4  const istrides = input.strides();
    af::dim4  const ostrides = output.strides();

    float *out = output.get();

    for(dim_t w = 0; w < idims[3]; w++) {
        for(dim_t z = 0; z < idims[2]; z++) {
            dim_t out_off = w * ostrides[3] + z * ostrides[2];
            for(dim_t y = 0; y < idims[1]; y++) {
                dim_t in_off = y * istrides[1] + z * istrides[2] + w * istrides[1];
                for(dim_t x = 0; x < idims[0]; x++) {
                    dim_t m_off=0;
                    float val = in[in_off + x];
                    if((moment & AF_MOMENT_M00) > 0) {
                        out[out_off + m_off] += val;
                        m_off++;
                    }
                    if((moment & AF_MOMENT_M01) > 0) {<commit_msg>BUGFIX: Fix to moments in CPU backend<commit_after>/*******************************************************
 * Copyright (c) 2016, ArrayFire
 * All rights reserved.
 *
 * This file is distributed under 3-clause BSD license.
 * The complete license agreement can be obtained at:
 * http://arrayfire.com/licenses/BSD-3-Clause
 ********************************************************/

#pragma once
#include <af/defines.h>
#include <Array.hpp>
#include <utility.hpp>
#include <math.hpp>

namespace cpu
{
namespace kernel
{


template<typename T>
void moments(Array<float> &output, Array<T> const &input, af_moment_type moment)
{
    T const * const in       = input.get();
    af::dim4  const idims    = input.dims();
    af::dim4  const istrides = input.strides();
    af::dim4  const ostrides = output.strides();

    float *out = output.get();

    for(dim_t w = 0; w < idims[3]; w++) {
        for(dim_t z = 0; z < idims[2]; z++) {
            dim_t out_off = w * ostrides[3] + z * ostrides[2];
            for(dim_t y = 0; y < idims[1]; y++) {
                dim_t in_off = y * istrides[1] + z * istrides[2] + w * istrides[3];
                for(dim_t x = 0; x < idims[0]; x++) {
                    dim_t m_off=0;
                    float val = in[in_off + x];
                    if((moment & AF_MOMENT_M00) > 0) {
                        out[out_off + m_off] += val;
                        m_off++;
                    }
                    if((moment & AF_MOMENT_M01) > 0) {
{'fraction_non_alphanumeric': 0.20400543109300748, 'fraction_numerical': 0.019687712152070606, 'mean_word_length': 2.2207650273224044, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 21, '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': '3933381', 'n_tokens_mistral': 997, 'n_tokens_neox': 947, 'n_words': 252}