<commit_before># -*- coding: utf-8 -*-

import collections
import itertools as it

from mpi4py import MPI
import numpy as np

import pyfr.backends.base as base


class OpenMPMatrixBase(base.MatrixBase):
    def onalloc(self, basedata, offset):
        self.basedata = basedata.ctypes.data

        self.data = basedata[offset:offset + self.nrow*self.pitch]
        self.data = self.data.view(self.dtype).reshape(self.datashape)

        self.offset = offset

        # Process any initial value
        if self._initval is not None:
            self.set(self._initval)

        # Remove
        del self._initval

    def get(self):
        # Trim any padding in the final dimension
        return self.data[...,:self.ioshape[-1]]

    def set(self, ary):
        if ary.shape != self.ioshape:
            raise ValueError('Invalid matrix shape')

        # Assign
        self.data[...,:ary.shape[-1]] = ary

    @property
    def _as_parameter_(self):
        # Obtain a pointer to our ndarray
        return self.data.ctypes.data


class OpenMPMatrix(OpenMPMatrixBase, base.Matrix):
    def __init__(self, backend, ioshape, initval, extent, tags):
        super(OpenMPMatrix, self).__init__(backend, backend.fpdtype, ioshape,
                                           initval, extent, tags)


class OpenMPMatrixRSlice(base.MatrixRSlice):
    def __init__(self, backend, mat, p, q):
        super(OpenMPMatrixRSlice, self).__init__(backend, mat, p, q)

        # Since slices do not retain any information about the
        # high-order structure of an array it is fine to compact mat
        # down to two dimensions and simply slice this
        self.data = backend.compact_arr(mat.data)[p:q]

    @property
    def _as_parameter_(self):
        return self.data.ctypes.data


class OpenMPMatrixBank(base.MatrixBank):
    pass
<commit_msg>Reduce the overhead of the OpenMP backend.<commit_after># -*- coding: utf-8 -*-

import collections
import itertools as it

from mpi4py import MPI
import numpy as np

import pyfr.backends.base as base


class OpenMPMatrixBase(base.MatrixBase):
    def onalloc(self, basedata, offset):
        self.basedata = basedata.ctypes.data

        self.data = basedata[offset:offset + self.nrow*self.pitch]
        self.data = self.data.view(self.dtype).reshape(self.datashape)

        self.offset = offset

        # Pointer to our ndarray (used by ctypes)
        self._as_parameter_ = self.data.ctypes.data

        # Process any initial value
        if self._initval is not None:
            self.set(self._initval)

        # Remove
        del self._initval

    def get(self):
        # Trim any padding in the final dimension
        return self.data[...,:self.ioshape[-1]]

    def set(self, ary):
        if ary.shape != self.ioshape:
            raise ValueError('Invalid matrix shape')

        # Assign
        self.data[...,:ary.shape[-1]] = ary


class OpenMPMatrix(OpenMPMatrixBase, base.Matrix):
    def __init__(self, backend, ioshape, initval, extent, tags):
        super(OpenMPMatrix, self).__init__(backend, backend.fpdtype, ioshape,
                                           initval, extent, tags)


class OpenMPMatrixRSlice(base.MatrixRSlice):
    def __init__(self, backend, mat, p, q):
        super(OpenMPMatrixRSlice, self).__init__(backend, mat, p, q)

        # Since slices do not retain any information about the
        # high-order structure of an array it is fine to compact mat
        # down to two dimensions and simply slice this
        self.data = backend.compact_arr(mat.data)[p:q]

        # Pointer to our ndarray (used by ctypes)
        self._as_parameter_ = self.data.ctypes.data


class OpenMPMatrixBank(base.MatrixBank):
    pass

{'fraction_non_alphanumeric': 0.09631423190745225, 'fraction_numerical': 0.0021522733387140166, 'mean_word_length': 2.4910798122065727, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2949190', 'n_tokens_mistral': 1118, 'n_tokens_neox': 1102, 'n_words': 312}