<commit_before># Copyright 2014-2017 The ODL contributors
#
# This file is part of ODL.
#
# 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 https://mozilla.org/MPL/2.0/.

"""ODL integration with pyshearlab."""


import odl
import numpy as np
import pyshearlab


__all__ = ('PyShearlabOperator',)


class PyShearlabOperator(odl.Operator):
    def __init__(self, space, scales):
        self.shearletSystem = pyshearlab.SLgetShearletSystem2D(0, space.shape[0], space.shape[1], scales)
        range = space ** self.shearletSystem['nShearlets']
        odl.Operator.__init__(self, space, range, True)
        
    def _call(self, x):
        result = pyshearlab.SLsheardec2D(x, self.shearletSystem)
        return np.moveaxis(result, -1, 0)
    
    @property
    def adjoint(self):
        op = self
        
        class PyShearlabOperatorAdjoint(odl.Operator):
            def _call(self, x):
                x = np.moveaxis(x, 0, -1)
                return pyshearlab.SLshearadjoint2D(x, op.shearletSystem)
            
            @property
            def adjoint(self):
                return op
            
        return PyShearlabOperatorAdjoint(self.range, self.domain, True)
    
    @property
    def inverse(self):
        op = self
        
        class PyShearlabOperatorInverse(odl.Operator):
            def _call(self, x):
                x = np.moveaxis(x, 0, -1)
                return pyshearlab.SLshearrec2D(x, op.shearletSystem)
            
            @property
            def adjoint(self):
                return op
            
        return PyShearlabOperatorInverse(self.range, self.domain, True)<commit_msg>ENH: Fix thread safety of pyshearlets<commit_after># Copyright 2014-2017 The ODL contributors
#
# This file is part of ODL.
#
# 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 https://mozilla.org/MPL/2.0/.

"""ODL integration with pyshearlab."""


import odl
import numpy as np
import pyshearlab
from threading import Lock


__all__ = ('PyShearlabOperator',)


class PyShearlabOperator(odl.Operator):
    def __init__(self, space, scales):
        self.shearletSystem = pyshearlab.SLgetShearletSystem2D(0, space.shape[0], space.shape[1], scales)
        range = space ** self.shearletSystem['nShearlets']
        self.mutex = Lock()
        odl.Operator.__init__(self, space, range, True)

    def _call(self, x):
        with self.mutex:
            result = pyshearlab.SLsheardec2D(x, self.shearletSystem)
            return np.moveaxis(result, -1, 0)

    @property
    def adjoint(self):
        op = self

        class PyShearlabOperatorAdjoint(odl.Operator):
            def _call(self, x):
                with op.mutex:
                    x = np.moveaxis(x, 0, -1)
                    return pyshearlab.SLshearadjoint2D(x, op.shearletSystem)

            @property
            def adjoint(self):
                return op

        return PyShearlabOperatorAdjoint(self.range, self.domain, True)

    @property
    def inverse(self):
        op = self

        class PyShearlabOperatorInverse(odl.Operator):
            def _call(self, x):
                with op.mutex:
                    x = np.moveaxis(x, 0, -1)
                    return pyshearlab.SLshearrec2D(x, op.shearletSystem)

            @property
            def inverse(self):
                return op

        return PyShearlabOperatorInverse(self.range, self.domain, True)
{'fraction_non_alphanumeric': 0.0927863436123348, 'fraction_numerical': 0.013766519823788546, 'mean_word_length': 2.1454545454545455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2995768', 'n_tokens_mistral': 1175, 'n_tokens_neox': 1109, 'n_words': 296}