<commit_before># This file is part of the SPLINTER library.
# Copyright (C) 2012 <NAME> (<EMAIL>).
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


from ctypes import *  # Loading libraries
from .utilities import *


# Handle to the cdll instance
__handle = None


# Try to load the library libFile
# If libFile is not specified, we try to locate and load SPLINTER
def load(libFile = None):
    global __handle
    if __handle is not None:
        out("SPLINTER is already loaded!")
        out("If you wish to unload it you must first call unload.")
    else:
        if libFile is None:
            libFile = __locateSplinter()
        if libFile is None:
            raise Exception("Unable to automatically locate SPLINTER.\nYou can load it manually by doing splinter.load(\"/path/to/SPLINTER.so\")")

        try:
            __handle = cdll.LoadLibrary(libFile)
            __init()
            out("Loaded SPLINTER from " + str(libFile) + "!")

        except Exception as e:
            out("Error:")
            out("Either you are trying to load a library with another architecture (32 bit/64 bit) than the Python you are using, ", True)
            out("or the file you are trying to load (" + libFile + ") could not be found.")
            out("For reference your Python is " + str(8*sizeof(c_void_p)) + "bit.")
            out("Here is the error message:")
            out(e)
            __handle = None


def isLoaded():
    global __handle
    return __handle is not None


# TODO:
# Is this function really necessary?
def unload():
    global __handle
    __handle = None


# Below are functions that should only be used internally
def _getHandle():
    global __handle

    if __handle is None:
        raise Exception("splinter is not loaded!")

    return __handle


# Set expected argument types and return types of all functions
def __init():
    # Define types for int* and double*
    c_int_p = POINTER(c_int)
    c_double_p = POINTER(c_double)
    handle_type = c_void_p

    _getHandle().get_error_string.restype = c_char_p
    _getHandle().get_error_string.argtypes = []

    _getHandle().datatable_load_init.restype = handle_type
    _getHandle().datatable_load_init.argtypes = [c_char_p]

    _getHandle().datatable_add_samples_row_major.restype = handle_type
    _getHandle().datatable_add_samples_row_major.argtypes = [handle_type, c_double_p, c_int, c_int]

    _getHandle().eval_row_major.restype = c_double_p
    _getHandle().eval_row_major.argtypes = [handle_type, c_double_p, c_int]

    _getHandle().eval_jacobian_row_major.restype = c_double_p
    _getHandle().eval_jacobian_row_major.argtypes = [handle_type, c_double_p, c_int]

    _getHandle().eval_hessian_row_major.restype = c_double_p
    _getHandle().eval_hessian_row_major.argtypes = [handle_type, c_double_p, c_int]

    _getHandle().polynomial_regression_init.restype = handle_type
    _getHandle().polynomial_regression_init.argtypes = [handle_type, c_int_p, c_int]

    _getHandle().pspline_load_init.restype = handle_type
    _getHandle().pspline_load_init.argtypes = [c_char_p]

    _getHandle().pspline_init.restype = handle_type
    _getHandle().pspline_init.argtypes = [handle_type, c_double]

    _getHandle().function_get_num_variables.restype = c_int<commit_msg>Removed references to pspline<commit_after># This file is part of the SPLINTER library.
# Copyright (C) 2012 <NAME> (<EMAIL>).
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.


from ctypes import *  # Loading libraries
from .utilities import *


# Handle to the cdll instance
__handle = None


# Try to load the library libFile
# If libFile is not specified, we try to locate and load SPLINTER
def load(libFile = None):
    global __handle
    if __handle is not None:
        out("SPLINTER is already loaded!")
        out("If you wish to unload it you must first call unload.")
    else:
        if libFile is None:
            libFile = __locateSplinter()
        if libFile is None:
            raise Exception("Unable to automatically locate SPLINTER.\nYou can load it manually by doing splinter.load(\"/path/to/SPLINTER.so\")")

        try:
            __handle = cdll.LoadLibrary(libFile)
            __init()
            out("Loaded SPLINTER from " + str(libFile) + "!")

        except Exception as e:
            out("Error:")
            out("Either you are trying to load a library with another architecture (32 bit/64 bit) than the Python you are using, ", True)
            out("or the file you are trying to load (" + libFile + ") could not be found.")
            out("For reference your Python is " + str(8*sizeof(c_void_p)) + "bit.")
            out("Here is the error message:")
            out(e)
            __handle = None


def isLoaded():
    global __handle
    return __handle is not None


# TODO:
# Is this function really necessary?
def unload():
    global __handle
    __handle = None


# Below are functions that should only be used internally
def _getHandle():
    global __handle

    if __handle is None:
        raise Exception("splinter is not loaded!")

    return __handle


# Set expected argument types and return types of all functions
def __init():
    # Define types for int* and double*
    c_int_p = POINTER(c_int)
    c_double_p = POINTER(c_double)
    handle_type = c_void_p

    _getHandle().get_error_string.restype = c_char_p
    _getHandle().get_error_string.argtypes = []

    _getHandle().datatable_load_init.restype = handle_type
    _getHandle().datatable_load_init.argtypes = [c_char_p]

    _getHandle().datatable_add_samples_row_major.restype = handle_type
    _getHandle().datatable_add_samples_row_major.argtypes = [handle_type, c_double_p, c_int, c_int]

    _getHandle().eval_row_major.restype = c_double_p
    _getHandle().eval_row_major.argtypes = [handle_type, c_double_p, c_int]

    _getHandle().eval_jacobian_row_major.restype = c_double_p
    _getHandle().eval_jacobian_row_major.argtypes = [handle_type, c_double_p, c_int]

    _getHandle().eval_hessian_row_major.restype = c_double_p
    _getHandle().eval_hessian_row_major.argtypes = [handle_type, c_double_p, c_int]

    _getHandle().polynomial_regression_init.restype = handle_type
    _getHandle().polynomial_regression_init.argtypes = [handle_type, c_int_p, c_int]

    _getHandle().function_get_num_variables.restype = c_int
{'fraction_non_alphanumeric': 0.08855030924724694, 'fraction_numerical': 0.003922160205159149, 'mean_word_length': 3.274661508704062, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '4411280', 'n_tokens_mistral': 2141, 'n_tokens_neox': 2052, 'n_words': 613}