<commit_before>/*
    tabsum.c:

    Copyright (C) 2009 <NAME>

    This file is part of Csound.

    The Csound Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Csound is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/

#include "csdl.h"

typedef struct {
    OPDS    h;
    MYFLT   *kans;
    MYFLT   *itab;
    MYFLT   *kmin, *kmax;
  /* Local */
    FUNC    *ftp;
} TABSUM;


static int tabsuminit(CSOUND *csound, TABSUM *p)
{
    if (UNLIKELY((p->ftp = csound->FTFind(csound, p->itab)) == NULL)) {
      return csound->InitError(csound, Str("tabsum: No table"));
    }
    return OK;
}



static int tabsum(CSOUND *csound, TABSUM *p)
{
    int i, min, max;
    MYFLT ans = FL(0.0);
    FUNC  *ftp = p->ftp;
    MYFLT *t;

    if (ftp==NULL)
      return csound->PerfError(csound, Str("tabsum: Not initialised"));
    t = (MYFLT*)p->ftp;
    min = MYFLT2LRND(*p->kmin);
    max = MYFLT2LRND(*p->kmax);
    if (min > max) {
      int k = min; min = max; max = k;
    }

    for (i=min; i<=max; i++) ans += t[i];
    *p->kans = ans;
    return OK;
}

#define S(x)    sizeof(x)

static OENTRY localops[] = {
{ "tabsum",     S(TABSUM),     3,     "k",    "ikk",(SUBR)tabsuminit, (SUBR)tabsum },
};

LINKAGE


<commit_msg>tabsum improved<commit_after>/*
    tabsum.c:

    Copyright (C) 2009 <NAME>

    This file is part of Csound.

    The Csound Library is free software; you can redistribute it
    and/or modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    Csound is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with Csound; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA
*/

#include "csdl.h"

typedef struct {
    OPDS    h;
    MYFLT   *kans;
    MYFLT   *itab;
    MYFLT   *kmin, *kmax;
  /* Local */
    FUNC    *ftp;
} TABSUM;


static int tabsuminit(CSOUND *csound, TABSUM *p)
{
    if (UNLIKELY((p->ftp = csound->FTFind(csound, p->itab)) == NULL)) {
      return csound->InitError(csound, Str("tabsum: No table"));
    }
    return OK;
}



static int tabsum(CSOUND *csound, TABSUM *p)
{
    int i, min, max;
    MYFLT ans = FL(0.0);
    FUNC  *ftp = p->ftp;
    MYFLT *t;

    if (ftp==NULL)
      return csound->PerfError(csound, Str("tabsum: Not initialised"));
    t = (MYFLT*)p->ftp;
    min = MYFLT2LRND(*p->kmin);
    max = MYFLT2LRND(*p->kmax);
    if (UNLIKELY(min == 0 && max == 0)) max = ftp->flen;
    else if (UNLIKELY(min > max)) {
      int k = min; min = max; max = k;
    }

    for (i=min; i<=max; i++) ans += t[i];
    *p->kans = ans;
    return OK;
}

#define S(x)    sizeof(x)

static OENTRY localops[] = {
{ "tabsum",     S(TABSUM),     3,     "k",    "iOO",(SUBR)tabsuminit, (SUBR)tabsum },
};

LINKAGE



{'fraction_non_alphanumeric': 0.11980830670926518, 'fraction_numerical': 0.013844515441959531, 'mean_word_length': 2.7087857847976307, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 28, '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': '5783566', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1295, 'n_words': 461}