<commit_before>//=======================================================================
// Copyright (c) 2014-2020 <NAME>
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
//  http://opensource.org/licenses/MIT)
//=======================================================================

#pragma once

namespace etl::impl::standard {

/*!
 * \brief Standard implementation of a matrix-matrix multiplication
 * \param a The left input matrix
 * \param b The right input matrix
 * \param c The output matrix
 */
template <typename A, typename B, typename C>
static void mm_mul(A&& a, B&& b, C&& c) {
    static constexpr bool row_major = decay_traits<A>::storage_order == order::RowMajor;

    c = 0;

    if constexpr (row_major) {
        for (size_t i = 0; i < rows(a); i++) {
            for (size_t k = 0; k < columns(a); k++) {
                for (size_t j = 0; j < columns(b); j++) {
                    c(i, j) += a(i, k) * b(k, j);
                }
            }
        }
    } else {
        for (size_t j = 0; j < columns(b); j++) {
            for (size_t k = 0; k < columns(a); k++) {
                for (size_t i = 0; i < rows(a); i++) {
                    c(i, j) += a(i, k) * b(k, j);
                }
            }
        }
    }
}

/*!
 * \brief Performs the computation c = c + a * b
 * \param c The output
 * \param a The lhs of the multiplication
 * \param b The rhs of the multiplication
 */
inline void add_mul(float& c, float a, float b) {
    c += a * b;
}

/*!
 * \brief Performs the computation c = c + a * b
 * \param c The output
 * \param a The lhs of the multiplication
 * \param b The rhs of the multiplication
 */
inline void add_mul(double& c, double a, double b) {
    c += a * b;
}

/*!
 * \brief Performs the computation c = c + a * b
 * \param c The output<commit_msg>Add alpha GEMM support to std impl<commit_after>//=======================================================================
// Copyright (c) 2014-2020 <NAME>
// Distributed under the terms of the MIT License.
// (See accompanying file LICENSE or copy at
//  http://opensource.org/licenses/MIT)
//=======================================================================

#pragma once

namespace etl::impl::standard {

/*!
 * \brief Standard implementation of a matrix-matrix multiplication
 * \param a The left input matrix
 * \param b The right input matrix
 * \param c The output matrix
 */
template <typename A, typename B, typename C, typename T>
static void mm_mul(A&& a, B&& b, C&& c, T alpha) {
    static constexpr bool row_major = decay_traits<A>::storage_order == order::RowMajor;

    c = 0;

    if constexpr (row_major) {
        for (size_t i = 0; i < rows(a); i++) {
            for (size_t k = 0; k < columns(a); k++) {
                for (size_t j = 0; j < columns(b); j++) {
                    c(i, j) += alpha * a(i, k) * b(k, j);
                }
            }
        }
    } else {
        for (size_t j = 0; j < columns(b); j++) {
            for (size_t k = 0; k < columns(a); k++) {
                for (size_t i = 0; i < rows(a); i++) {
                    c(i, j) += alpha * a(i, k) * b(k, j);
                }
            }
        }
    }
}

/*!
 * \brief Performs the computation c = c + a * b
 * \param c The output
 * \param a The lhs of the multiplication
 * \param b The rhs of the multiplication
 */
inline void add_mul(float& c, float a, float b) {
    c += a * b;
}

/*!
 * \brief Performs the computation c = c + a * b
 * \param c The output
 * \param a The lhs of the multiplication
 * \param b The rhs of the multiplication
 */
inline void add_mul(double& c, double a, double b) {
    c += a * b;
}

/*!
 * \brief Performs the computation c = c + a * b
 * \param c The output
{'fraction_non_alphanumeric': 0.20625662778366913, 'fraction_numerical': 0.007953340402969246, 'mean_word_length': 2.23862660944206, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 9, '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': '1658257', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1140, 'n_words': 443}