<commit_before># -*- coding: utf-8 -*-
#
# test_result_comparison.py
#
# purpose:  Compare a dataset from python vs matlab (run on octave).
# author:   <NAME>
# e-mail:   <EMAIL>
# web:      http://ocefpaf.github.io/
# created:  05-Aug-2013
# modified: Wed 21 Aug 2013 05:43:57 PM BRT
#
# obs:
#


from __future__ import division

import os
import unittest

import numpy as np

rootpath = os.path.dirname(__file__)
try:
    from oct2py import octave
    path = os.path.join(rootpath, 'seawater_v3_3')
    _ = octave.addpath(octave.genpath(path))
except ImportError:
    pass

import seawater as sw
from seawater.constants import c3515


def compare_results(name, function, args, values):
    args = [values.get(arg) for arg in args]
    res = function(*args)  # Python call.
    # FIXME: Test only the first output when multiple outputs are present.
    if isinstance(res, tuple):
        nout = len(res)
        res = res[0]
    else:
        nout = 1
    val = octave.call('sw_%s' % name, *args, nout=nout)  # Octave call.
    if nout > 1:
        val = val[0]
    val, res = val.squeeze(), res.squeeze()
    np.testing.assert_allclose(val, res)

<commit_msg>Ensure oct2py import.<commit_after># -*- coding: utf-8 -*-
#
# test_result_comparison.py
#
# purpose:  Compare a dataset from python vs matlab (run on octave).
# author:   <NAME>
# e-mail:   <EMAIL>
# web:      http://ocefpaf.github.io/
# created:  05-Aug-2013
# modified: Wed 21 Aug 2013 05:43:57 PM BRT
#
# obs:
#


from __future__ import division

import os
import unittest

import numpy as np

rootpath = os.path.dirname(__file__)
from oct2py import octave
path = os.path.join(rootpath, 'seawater_v3_3')
_ = octave.addpath(octave.genpath(path))

import seawater as sw
from seawater.constants import c3515


def compare_results(name, function, args, values):
    args = [values.get(arg) for arg in args]
    res = function(*args)  # Python call.
    # FIXME: Test only the first output when multiple outputs are present.
    if isinstance(res, tuple):
        nout = len(res)
        res = res[0]
    else:
        nout = 1
    val = octave.call('sw_%s' % name, *args, nout=nout)  # Octave call.
    if nout > 1:
        val = val[0]
    val, res = val.squeeze(), res.squeeze()
    np.testing.assert_allclose(val, res)


{'fraction_non_alphanumeric': 0.1212784588441331, 'fraction_numerical': 0.026707530647985988, 'mean_word_length': 3.080357142857143, 'pattern_counts': {'":': 0, '<': 7, '<?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': '354229', 'n_tokens_mistral': 858, 'n_tokens_neox': 813, 'n_words': 238}