<commit_before>
class Matriz

  attr_reader :rows, :cols

  def initialize(rows, cols)
    @rows, @cols = rows , cols
  end
       
  def Matriz.vector(rows, cols, ele)
    raise TypeError, 'No se han introducido suficientes valores' unless (ele.length==rows*cols) 
      if (((ele.count{|e| e == e.elemento_nulo}*100)/(rows*cols)) >= 60) # Matriz dispersa
        Matriz_dispersa.new(rows,cols,ele)
      else # Matriz densa
        Matriz_densa.new(rows,cols,ele)
      end
  end
  
  def Matriz.nula(rows=1, cols=1)
    aux=Array.new(rows*cols, 0)
    Matriz_dispersa.new(rows, cols, aux)
  end
       
  def to_s  
    cadena = "["
    for i in (0..(@rows-1))
      cadena += "["
      for j in (0..(@cols-1))
        cadena += "#{self[i,j]}"
        if (j < (@cols-1)) 
          cadena += "," 
        end
      end
      cadena += "]"
      if (i < (@rows-1)) 
        cadena += "," 
      end
    end
    cadena += "]"
  end

  def +(other) 
    raise TypeError, 'Las matrices no son del mismo tamanyo' unless (@rows==other.rows && @cols==other.cols)
      result=Array.new
      for i in 0...@rows
        for j in 0...@cols
          result << (self[i,j] + other[i,j])
        end 
      end
      Matriz.vector(@rows, @cols, result)
  end
  
  def -(other) 
    raise TypeError, 'Las matrices no son del mismo tamanyo' unless (@rows==other.rows && @cols==other.cols)
      result=Array.new
      for i in 0...@rows
        for j in 0...@cols
          result << (self[i,j] - other[i,j])
        end 
      end
      Matriz.vector(@rows, @cols, result)
  end
  
  def *(other)
    if(other.is_a? Numeric)
      result=Array.new
      for i in 0...@rows
        for j in 0...@cols
          result << (self[i,j]*other)
        end
      end
      return Matriz.vector(@rows,@cols,result)
      
    elsif(other.is_a? Matriz)
      raise TypeError, 'Las matrices dadas no se pueden multiplicar entre si' unless (@cols == other.rows)
      result=Array.new
      for i in 0...@rows
        for j in 0...other.cols
          result << 0
          for k in 0...@cols
            result[(result.length)-1]= (result.last + (self[i,k] * other[k,j]))
          end
        end
      end
    end
    Matriz.vector(@rows,other.cols,result)
  end

  def max
    aux=self[0,0]
    for i in 0...@rows
      for j in 0...@cols
        r = aux.coerce(self[i,j])
        if (r[0] > r[1])
          aux = r[0]
        else
          aux = r[1]
        end
      end
    end
    aux
  end
  <commit_msg>Suma, resta y producto de matrices con método 'times'<commit_after>
class Matriz

  attr_reader :rows, :cols

  def initialize(rows, cols)
    @rows, @cols = rows , cols
  end
       
  def Matriz.vector(rows, cols, ele)
    raise TypeError, 'No se han introducido suficientes valores' unless (ele.length==rows*cols) 
      if (((ele.count{|e| e == e.elemento_nulo}*100)/(rows*cols)) >= 60) # Matriz dispersa
        Matriz_dispersa.new(rows,cols,ele)
      else # Matriz densa
        Matriz_densa.new(rows,cols,ele)
      end
  end
  
  def Matriz.nula(rows=1, cols=1)
    aux=Array.new(rows*cols, 0)
    Matriz_dispersa.new(rows, cols, aux)
  end
       
  def to_s  
    cadena = "["
    for i in (0..(@rows-1))
      cadena += "["
      for j in (0..(@cols-1))
        cadena += "#{self[i,j]}"
        if (j < (@cols-1)) 
          cadena += "," 
        end
      end
      cadena += "]"
      if (i < (@rows-1)) 
        cadena += "," 
      end
    end
    cadena += "]"
  end

  def +(other) 
    raise TypeError, 'Las matrices no son del mismo tamanyo' unless (@rows==other.rows && @cols==other.cols)
      result=Array.new
      @rows.times do |i|
        @cols.times do |j|
          result << (self[i,j] + other[i,j])
        end
      end
      Matriz.vector(@rows, @cols, result)
  end
  
  def -(other) 
    raise TypeError, 'Las matrices no son del mismo tamanyo' unless (@rows==other.rows && @cols==other.cols)
      result=Array.new
      @rows.times do |i|
        @cols.times do |j|
          result << (self[i,j] - other[i,j])
        end
      end
      Matriz.vector(@rows, @cols, result)
  end
  
  def *(other)
    if(other.is_a? Numeric)
      result=Array.new
      @rows.times do |i|
        @cols.times do |j|
          result << (self[i,j]*other)
        end
      end
      return Matriz.vector(@rows,@cols,result)
      
    elsif(other.is_a? Matriz)
      raise TypeError, 'Las matrices dadas no se pueden multiplicar entre si' unless (@cols == other.rows)
      result=Array.new
      @rows.times do |i|
        other.cols.times do |j|
          result << 0
          @cols.times do |k|
            result[(result.length)-1]= (result.last + (self[i,k] * other[k,j]))
          end
        end
      end
    end
    Matriz.vector(@rows,other.cols,result)
  end

  def max
    aux=self[0,0]
    for i in 0...@rows
      for j in 0...@cols
        r = aux.coerce(self[i,j])
        if (r[0] > r[1])
          aux = r[0]
        else
          aux = r[1]
        end
      end
    end
    aux
  end
  
{'fraction_non_alphanumeric': 0.14345403899721448, 'fraction_numerical': 0.011341026661360923, 'mean_word_length': 1.814669652855543, 'pattern_counts': {'":': 0, '<': 23, '<?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': '5794280', 'n_tokens_mistral': 1866, 'n_tokens_neox': 1796, 'n_words': 459}