<commit_before>#!/usr/bin/env ruby
require 'eldritch'

def print_matrix(matrix)
  matrix.each do |line|
    formatted = line.map { |i| '% 10.5f' % i }
    puts "[ #{formatted.join(', ')} ]"
  end
end

matrix = [
  [-1, -1, -1, -1, -1, -1],
  [-1,  1,  2,  3,  4, -1],
  [-1,  1,  2,  3,  4, -1],
  [-1,  1,  2,  3,  4, -1],
  [-1,  1,  2,  3,  4, -1],
  [-1, -1, -1, -1, -1, -1]
]

epsilon = 0.001

print_matrix matrix
puts

matrix_height = matrix.length - 2
matrix_width = matrix[0].length - 2

max_diff = epsilon + 1
iterations = 1
while max_diff > epsilon do
  matrix_temp = Marshal.load(Marshal.dump(matrix))

  together do
    (1..matrix_height).each do |row_id|
      async do
        (1..matrix_width).each do |col_id|
          matrix_temp[row_id][col_id] = [1, -1].product([1, -1])
            .map { |i| matrix[row_id+i[1]][col_id+i[0]] }
            .reduce(:+).to_f / 4
        end
      end
    end
  end

  max_diff = (1..matrix_height).to_a
    .product((1..matrix_width).to_a)
    .map { |i| (matrix_temp[i[0]][i[1]] - matrix[i[0]][i[1]]).abs }
    .max
  matrix = matrix_temp

  puts 'Iteration '
  print_matrix matrix
  puts iterations
  iterations+=1
  puts max_diff
  puts ''
end<commit_msg>improved iteration and epsilon printing<commit_after>#!/usr/bin/env ruby
require 'eldritch'

def print_matrix(matrix)
  matrix.each do |line|
    formatted = line.map { |i| '% 10.5f' % i }
    puts "[ #{formatted.join(', ')} ]"
  end
end

matrix = [
  [-1, -1, -1, -1, -1, -1],
  [-1,  1,  2,  3,  4, -1],
  [-1,  1,  2,  3,  4, -1],
  [-1,  1,  2,  3,  4, -1],
  [-1,  1,  2,  3,  4, -1],
  [-1, -1, -1, -1, -1, -1]
]

epsilon = 0.001

print_matrix matrix
puts

matrix_height = matrix.length - 2
matrix_width = matrix[0].length - 2

max_diff = epsilon + 1
iterations = 1
while max_diff > epsilon do
  matrix_temp = Marshal.load(Marshal.dump(matrix))

  together do
    (1..matrix_height).each do |row_id|
      async do
        (1..matrix_width).each do |col_id|
          matrix_temp[row_id][col_id] = [1, -1].product([1, -1])
            .map { |i| matrix[row_id+i[1]][col_id+i[0]] }
            .reduce(:+).to_f / 4
        end
      end
    end
  end

  max_diff = (1..matrix_height).to_a
    .product((1..matrix_width).to_a)
    .map { |i| (matrix_temp[i[0]][i[1]] - matrix[i[0]][i[1]]).abs }
    .max
  matrix = matrix_temp

  print_matrix matrix
  puts "iteration = #{iterations}; diff = #{max_diff}"
  puts
  iterations+=1
end
{'fraction_non_alphanumeric': 0.1901062959934587, 'fraction_numerical': 0.05233033524121014, 'mean_word_length': 2.3705234159779613, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1258668', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1056, 'n_words': 244}