<commit_before>"use strict";

module.exports =
    function product(arr1, arr2, mode = "matrix") {
        let prod = [];
        const calc_shape = require('../lib/calc_shape'),
            form_arr = require('../lib/form_arr'),
            flatten = require('../lib/flatten'),
            matrix_mult = require('./matmul'),
            arrange = require('../lib/arrange');

        if (Array.isArray(arr1) && Array.isArray(arr2)) {
            let t1 = flatten(arr1),
                t2 = flatten(arr2),
                s1 = calc_shape(arr1),
                s2 = calc_shape(arr2);
            if (s1.length === 2 && s2.length === 2) {
                if (s1[1] === s2[0] && mode === 'matrix') {
                    return arrange([s1[0], s2[1]], matrix_mult(s1, s2, t1, t2));
                } else if (mode === 'dot') {
                    if (s1.toString() === s2.toString()) {
                        prod = product(ta1, ta2);
                        return arrange(s1, prod);
                    } else {
                        throw new Error("Uneven shape");
                    }
                }
            } else if (s1.length > 1 && s2.length === 1) {
                if (mode === 'matrix') {
                    if (s1[s1.length - 2] === s2[0]) {
                        let k = 0;
                        for (let i = 0; i < t1.length; i++) {
                            if ((i % s1[s1.length - 1]) === 0 && i !== 0) ++k;
                            prod.push(t1[i] * t2[k]);
                        }
                        return arrange(s1, prod);
                    } else {
                        throw new Error("Uneven Size");
                    }
                } else {
                    if (s1[s1.length - 1] === s2[0]) {
                        let k = 0;
                        for (let i = 0; i < t1.length; i++) {
                            if (k >= t2.length) k = 0;
                            prod.push(t1[i] * t2[k++]);
                        }
                        return arrange(s1, prod);
                    } else {
                        throw new Error("Uneven Size");
                    }
                }
            } else if (s1.length === 1 && s2.length > 1) {
                return product(arr2, arr1);
            } else if (s1.length === 1 && s2.length === 1) {
                if (t1.length === t2.length) {
                    for (let i = 0; i < t1.length; i++) {
                        prod.push(t1[i] * t2[i]);
                    }
                } else {
                    throw new Error("Uneven Size");
                }
            } else {
                if (s1.toString() === s2.toString()) {
                    prod = product(ta1, ta2);
                    return arrange(s1, prod);
                } else {
                    throw new Error("Uneven size");
                }
            }
        } else if (Array.isArray(arr1) && !Array.isArray(arr2)) {
            let t1 = form_arr(flatten(arr1));
            let s1 = calc_shape(arr1);
            for (let i = 0; i < t1.length; i++) {<commit_msg>fixed the product<commit_after>"use strict";

module.exports =
    function product(arr1, arr2, mode = "matrix") {
        let prod = [];
        const calc_shape = require('../lib/calc_shape'),
            form_arr = require('../lib/form_arr'),
            flatten = require('../lib/flatten'),
            matrix_mult = require('./matmul'),
            arrange = require('../lib/arrange');

        if (Array.isArray(arr1) && Array.isArray(arr2)) {
            let t1 = flatten(arr1),
                t2 = flatten(arr2),
                s1 = calc_shape(arr1),
                s2 = calc_shape(arr2);
            if (s1.length === 2 && s2.length === 2) {
                if (s1[1] === s2[0] && mode === 'matrix') {
                    return arrange([s1[0], s2[1]], matrix_mult(s1, s2, t1, t2));
                } else if (mode === 'dot') {
                    if (s1.toString() === s2.toString()) {
                        prod = product(t1, t2);
                        return arrange(s1, prod);
                    } else {
                        throw new Error("Uneven shape");
                    }
                }
            } else if (s1.length > 1 && s2.length === 1) {
                if (mode === 'matrix') {
                    if (s1[s1.length - 2] === s2[0]) {
                        let k = 0;
                        for (let i = 0; i < t1.length; i++) {
                            if ((i % s1[s1.length - 1]) === 0 && i !== 0) ++k;
                            prod.push(t1[i] * t2[k]);
                        }
                        return arrange(s1, prod);
                    } else {
                        throw new Error("Uneven Size");
                    }
                } else {
                    if (s1[s1.length - 1] === s2[0]) {
                        let k = 0;
                        for (let i = 0; i < t1.length; i++) {
                            if (k >= t2.length) k = 0;
                            prod.push(t1[i] * t2[k++]);
                        }
                        return arrange(s1, prod);
                    } else {
                        throw new Error("Uneven Size");
                    }
                }
            } else if (s1.length === 1 && s2.length > 1) {
                return product(arr2, arr1);
            } else if (s1.length === 1 && s2.length === 1) {
                if (t1.length === t2.length) {
                    for (let i = 0; i < t1.length; i++) {
                        prod.push(t1[i] * t2[i]);
                    }
                } else {
                    throw new Error("Uneven Size");
                }
            } else {
                if (s1.toString() === s2.toString()) {
                    prod = product(t1, t2);
                    return arrange(s1, prod);
                } else {
                    throw new Error("Uneven size");
                }
            }
        } else if (Array.isArray(arr1) && !Array.isArray(arr2)) {
            let t1 = form_arr(flatten(arr1));
            let s1 = calc_shape(arr1);
            for (let i = 0; i < t1.length; i++) {
{'fraction_non_alphanumeric': 0.14720155289550307, 'fraction_numerical': 0.030734390164995146, 'mean_word_length': 0.9364234262449107, 'pattern_counts': {'":': 0, '<': 11, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1626668', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1726, 'n_words': 408}