<commit_before>=item arrayfun(func, A)

Apply a function 'func' to each element of an array 'A'.

=cut

.namespace ["_Matrixy";"builtins"]

.sub 'arrayfun'
    .param int nargout
    .param int nargin
    .param pmc f
    .param pmc A
    .param pmc O :slurpy
    .const "Sub" helper = "!_arrayfun_helper"

    $S0 = typeof f
    if $S0 == 'Sub' goto have_sub
    $S1 = f
    f = '!lookup_function'($S1)

  have_sub:
    $S0 = typeof A
    if $S0 == 'NumMatrix2D' goto its_a_matrix
    $I0 = elements O
    $I0 = $I0 + 1
    $P0 = f(1, $I0, A, O :flat)
    .return($P0)

  its_a_matrix:
    .lex "function", f
    A.'iterate_function_inplace'(helper, O :flat)
    .return(A)
.end

.sub '!_arrayfun_helper' :outer('arrayfun')
    .param pmc matrix
    .param num value
    .param int x
    .param int y
    $P0 = find_lex "function"
    .tailcall $P0(value)
.end<commit_msg>some fixes to arrayfun. It operates correctly for one matrix but does not operate correctly for multiple matrices<commit_after>=item arrayfun(func, A)

Apply a function 'func' to each element of an array 'A'.

=cut

.namespace ["_Matrixy";"builtins"]

.sub 'arrayfun'
    .param int nargout
    .param int nargin
    .param pmc f
    .param pmc A
    .param pmc O :slurpy
    .const "Sub" helper = "!_arrayfun_helper"
    $S0 = typeof f
    if $S0 == 'Sub' goto have_sub
    $S1 = f
    f = '!lookup_function'($S1)
    if null f goto no_sub_available

  have_sub:
    $S0 = typeof A
    if $S0 == 'NumMatrix2D' goto its_a_matrix
    $I0 = elements O
    $I0 = $I0 + 1
    $P0 = f(1, $I0, A, O :flat)
    .return($P0)

  its_a_matrix:
    $P0 = A.'iterate_function_external'(helper, f, O :flat)
    .return($P0)
  no_sub_available:
    .return(A)
.end

.sub '!_arrayfun_helper'
    .param pmc matrix
    .param num value
    .param int x
    .param int y
    .param pmc subroutine
    .param pmc args :slurpy
    $I0 = args
    .tailcall subroutine(1, $I0, value, args :flat)
.end
{'fraction_non_alphanumeric': 0.12346311475409837, 'fraction_numerical': 0.018954918032786885, 'mean_word_length': 2.5900735294117645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '326307', 'n_tokens_mistral': 769, 'n_tokens_neox': 758, 'n_words': 237}