<commit_before>package org.vitrivr.adampro.query.distance

import org.vitrivr.adampro.datatypes.feature.Feature._
import org.vitrivr.adampro.query.distance.Distance.Distance
import org.vitrivr.adampro.utils.Logging

/**
  * ADAMpro
  *
  * <NAME>
  * June 2016
  */
trait ElementwiseSummedDistanceFunction extends DistanceFunction with Logging with Serializable {
  override def apply(v1_q: FeatureVector, v2: FeatureVector, weights: Option[FeatureVector]): Distance = {
    var cumSum = 0.0

    //computing sum
    if (weights.isEmpty) {
      //un-weighted
      if (v1_q.isInstanceOf[SparseFeatureVector] && v2.isInstanceOf[SparseFeatureVector]) {
        //sparse vectors
        log.trace("compute distance without weights, sparse vectors")

        val sv1_q = v1_q.asInstanceOf[SparseFeatureVector]
        val sv2 = v2.asInstanceOf[SparseFeatureVector]
        var offset = 0

        while (offset < math.max(sv1_q.activeSize, sv2.activeSize)) {
          if (offset < sv1_q.activeSize && offset < sv2.activeSize) {
            cumSum += element(sv1_q.valueAt(offset), sv2.valueAt(offset))
          } else if (offset < sv1_q.activeSize) {
            cumSum += element(sv1_q.valueAt(offset), 0.0)
          } else if (offset < sv2.activeSize) {
            cumSum += element(0.0, sv2.valueAt(offset))
          }
          offset += 1
        }
      } else {
        //dense vectors
        log.trace("compute distance without weights, dense vectors")

        var offset = 0
        while (offset < math.min(v1_q.length, v2.length)) {
          cumSum += element(v1_q(offset), v2(offset))
          offset += 1
        }
      }
    } else {
      //weighted
      log.trace("compute distance with weights")

      if (weights.get.isInstanceOf[SparseFeatureVector]) {
        //sparse weights
        log.trace("compute distance with sparse weights")

        val sweights = weights.get.asInstanceOf[SparseFeatureVector]

        var offset = 0
        while (offset < sweights.activeSize) {
          if (offset < v1_q.length && offset < v2.length) {
            cumSum += element(v1_q(offset), v2(offset), sweights.valueAt(offset))
          }
          offset += 1
        }
      } else if (v1_q.isInstanceOf[SparseFeatureVector] && v2.isInstanceOf[SparseFeatureVector]) {
        //dense weights, sparse vectors
        log.trace("compute distance with dense weights and sparse vectors")

        val sv1_q = v1_q.asInstanceOf[SparseFeatureVector]
        val sv2 = v2.asInstanceOf[SparseFeatureVector]

        var offset = 0
        while (offset < math.max(sv1_q.activeSize, sv2.activeSize)) {
          if (offset < sv1_q.activeSize && offset < sv2.activeSize) {
            cumSum += element(sv1_q.valueAt(offset), sv2.valueAt(offset), weights.get(offset))
          } else if (offset < sv1_q.activeSize) {
            cumSum += element(sv1_q.valueAt(offset), 0.0, weights.get(offset))
          } else if (offset < sv2.activeSize) {
            cumSum += element(0.0, sv2.valueAt(offset), weights.get(offset))
          }
          offset += 1
        }
      } else {
        //dense weights, dense vectors
        log.trace("compute distance with dense weights and dense vectors")

        var offset = 0
        while (offset < v1_q.length && offset < v1_q.length && offset < v2.length) {
          cumSum += element(v1_q(offset), v2(offset), weights.get(offset))
          offset += 1
        }
      }<commit_msg>removing logs in distance computation<commit_after>package org.vitrivr.adampro.query.distance

import org.vitrivr.adampro.datatypes.feature.Feature._
import org.vitrivr.adampro.query.distance.Distance.Distance
import org.vitrivr.adampro.utils.Logging

/**
  * ADAMpro
  *
  * <NAME>
  * June 2016
  */
trait ElementwiseSummedDistanceFunction extends DistanceFunction with Logging with Serializable {
  override def apply(v1_q: FeatureVector, v2: FeatureVector, weights: Option[FeatureVector]): Distance = {
    var cumSum = 0.0

    //computing sum
    if (weights.isEmpty) {
      //un-weighted
      if (v1_q.isInstanceOf[SparseFeatureVector] && v2.isInstanceOf[SparseFeatureVector]) {
        //sparse vectors
        val sv1_q = v1_q.asInstanceOf[SparseFeatureVector]
        val sv2 = v2.asInstanceOf[SparseFeatureVector]
        var offset = 0

        while (offset < math.max(sv1_q.activeSize, sv2.activeSize)) {
          if (offset < sv1_q.activeSize && offset < sv2.activeSize) {
            cumSum += element(sv1_q.valueAt(offset), sv2.valueAt(offset))
          } else if (offset < sv1_q.activeSize) {
            cumSum += element(sv1_q.valueAt(offset), 0.0)
          } else if (offset < sv2.activeSize) {
            cumSum += element(0.0, sv2.valueAt(offset))
          }
          offset += 1
        }
      } else {
        //dense vectors
        var offset = 0
        while (offset < math.min(v1_q.length, v2.length)) {
          cumSum += element(v1_q(offset), v2(offset))
          offset += 1
        }
      }
    } else {
      //weighted
      if (weights.get.isInstanceOf[SparseFeatureVector]) {
        //sparse weights

        val sweights = weights.get.asInstanceOf[SparseFeatureVector]

        var offset = 0
        while (offset < sweights.activeSize) {
          if (offset < v1_q.length && offset < v2.length) {
            cumSum += element(v1_q(offset), v2(offset), sweights.valueAt(offset))
          }
          offset += 1
        }
      } else if (v1_q.isInstanceOf[SparseFeatureVector] && v2.isInstanceOf[SparseFeatureVector]) {
        //dense weights, sparse vectors
        val sv1_q = v1_q.asInstanceOf[SparseFeatureVector]
        val sv2 = v2.asInstanceOf[SparseFeatureVector]

        var offset = 0
        while (offset < math.max(sv1_q.activeSize, sv2.activeSize)) {
          if (offset < sv1_q.activeSize && offset < sv2.activeSize) {
            cumSum += element(sv1_q.valueAt(offset), sv2.valueAt(offset), weights.get(offset))
          } else if (offset < sv1_q.activeSize) {
            cumSum += element(sv1_q.valueAt(offset), 0.0, weights.get(offset))
          } else if (offset < sv2.activeSize) {
            cumSum += element(0.0, sv2.valueAt(offset), weights.get(offset))
          }
          offset += 1
        }
      } else {
        //dense weights, dense vectors
        var offset = 0
        while (offset < v1_q.length && offset < v1_q.length && offset < v2.length) {
          cumSum += element(v1_q(offset), v2(offset), weights.get(offset))
          offset += 1
        }
      }
{'fraction_non_alphanumeric': 0.11497079618813404, 'fraction_numerical': 0.02182600676298801, 'mean_word_length': 2.3593185338151783, 'pattern_counts': {'":': 0, '<': 39, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6652135', 'n_tokens_mistral': 2101, 'n_tokens_neox': 2017, 'n_words': 419}