<commit_before>require 'fiddle'
require 'rbconfig'
require 'numo/linalg/linalg'

module Numo
  module Linalg
    module Autoloader

      @@libs = nil

      module_function

      def libs
        @@libs
      end

      # Load backend libraries for Numo::Linalg automatically.
      #
      # @return [String] name of loaded backend library (mkl/openblas/lapack)
      def load_library
        mkl_dirs = ['/opt/intel/lib', '/opt/intel/lib64', '/opt/intel/mkl/lib', '/opt/intel/mkl/lib64']
        openblas_dirs = ['/opt/OpenBLAS/lib', '/opt/OpenBLAS/lib64', '/opt/openblas/lib', '/opt/openblas/lib64',
                         '/usr/local/opt/openblas/lib']
        atlas_dirs = ['/opt/atlas/lib', '/opt/atlas/lib64',
                      '/usr/lib/atlas', '/usr/lib64/atlas', '/usr/local/opt/atlas/lib']
        lapacke_dirs = ['/opt/lapack/lib', '/opt/lapack/lib64', '/opt/local/lib/lapack',
                        '/usr/local/opt/lapack/lib']
        opt_dirs =  ['/opt/local/lib', '/opt/local/lib64', '/opt/lib', '/opt/lib64']
        base_dirs = ['/usr/local/lib', '/usr/local/lib64', '/usr/lib', '/usr/lib64']
        base_dirs.unshift(*ENV['LD_LIBRARY_PATH'].split(':')) unless ENV['LD_LIBRARY_PATH'].nil?

        mkl_libs = find_mkl_libs([*base_dirs, *opt_dirs, *mkl_dirs])
        openblas_libs = find_openblas_libs([*base_dirs, *opt_dirs, *openblas_dirs])
        atlas_libs = find_atlas_libs([*base_dirs, *opt_dirs, *atlas_dirs, *lapacke_dirs])
        lapack_libs = find_lapack_libs([*base_dirs, *opt_dirs, *lapacke_dirs])

        @@libs = nil
        if !mkl_libs.value?(nil)
          open_mkl_libs(mkl_libs)
          @@libs = mkl_libs.values
          'mkl'
        elsif !openblas_libs.value?(nil)
          open_openblas_libs(openblas_libs)
          @@libs = openblas_libs.values.uniq
          'openblas'
        elsif !atlas_libs.value?(nil)
          open_atlas_libs(atlas_libs)
          @@libs = atlas_libs.values.uniq
          'atlas'
        elsif !lapack_libs.value?(nil)
          open_lapack_libs(lapack_libs)
          @@libs = lapack_libs.values.uniq
          'lapack'
        else
          raise 'cannot find MKL/OpenBLAS/ATLAS/BLAS-LAPACK library'
        end<commit_msg>Add multiarch library directory of Debian family to autoloader<commit_after>require 'fiddle'
require 'rbconfig'
require 'numo/linalg/linalg'

module Numo
  module Linalg
    module Autoloader

      @@libs = nil

      module_function

      def libs
        @@libs
      end

      # Load backend libraries for Numo::Linalg automatically.
      #
      # @return [String] name of loaded backend library (mkl/openblas/lapack)
      def load_library
        mkl_dirs = ['/opt/intel/lib', '/opt/intel/lib64', '/opt/intel/mkl/lib', '/opt/intel/mkl/lib64']
        openblas_dirs = ['/opt/OpenBLAS/lib', '/opt/OpenBLAS/lib64', '/opt/openblas/lib', '/opt/openblas/lib64',
                         '/usr/local/opt/openblas/lib']
        atlas_dirs = ['/opt/atlas/lib', '/opt/atlas/lib64',
                      '/usr/lib/atlas', '/usr/lib64/atlas', '/usr/local/opt/atlas/lib']
        lapacke_dirs = ['/opt/lapack/lib', '/opt/lapack/lib64', '/opt/local/lib/lapack',
                        '/usr/local/opt/lapack/lib']
        opt_dirs =  ['/opt/local/lib', '/opt/local/lib64', '/opt/lib', '/opt/lib64']
        base_dirs = ['/usr/local/lib', '/usr/local/lib64', '/usr/lib', '/usr/lib64',
                     "/usr/lib/#{RbConfig::CONFIG['host_cpu']}-#{RbConfig::CONFIG['host_os']}"]
        base_dirs.unshift(*ENV['LD_LIBRARY_PATH'].split(':')) unless ENV['LD_LIBRARY_PATH'].nil?

        mkl_libs = find_mkl_libs([*base_dirs, *opt_dirs, *mkl_dirs])
        openblas_libs = find_openblas_libs([*base_dirs, *opt_dirs, *openblas_dirs])
        atlas_libs = find_atlas_libs([*base_dirs, *opt_dirs, *atlas_dirs, *lapacke_dirs])
        lapack_libs = find_lapack_libs([*base_dirs, *opt_dirs, *lapacke_dirs])

        @@libs = nil
        if !mkl_libs.value?(nil)
          open_mkl_libs(mkl_libs)
          @@libs = mkl_libs.values
          'mkl'
        elsif !openblas_libs.value?(nil)
          open_openblas_libs(openblas_libs)
          @@libs = openblas_libs.values.uniq
          'openblas'
        elsif !atlas_libs.value?(nil)
          open_atlas_libs(atlas_libs)
          @@libs = atlas_libs.values.uniq
          'atlas'
        elsif !lapack_libs.value?(nil)
          open_lapack_libs(lapack_libs)
          @@libs = lapack_libs.values.uniq
          'lapack'
        else
          raise 'cannot find MKL/OpenBLAS/ATLAS/BLAS-LAPACK library'
        end
{'fraction_non_alphanumeric': 0.14891755958889133, 'fraction_numerical': 0.009621692543188278, 'mean_word_length': 2.3806356245380638, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '493660', 'n_tokens_mistral': 1805, 'n_tokens_neox': 1679, 'n_words': 250}