<commit_before>/*
  Teem: Tools to process and visualize scientific data and images
  Copyright (C) 2006, 2005  <NAME>
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public License
  (LGPL) as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  The terms of redistributing and/or modifying this software also
  include exceptions to the LGPL that facilitate static linking.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


#include "ten.h"
#include "privateTen.h"

tenPathParm *
tenPathParmNew(void) {
  tenPathParm *tpp;

  tpp = AIR_CAST(tenPathParm *, malloc(sizeof(tenPathParm)));
  if (tpp) {
    tpp->verbose = AIR_FALSE;
    tpp->convStep = 0.2;
    tpp->minNorm = 0.0;
    tpp->convEps = 0.0000001;
    tpp->wghtSumEps = 0.0000001;
    tpp->enableRecurse = AIR_TRUE;
    tpp->maxIter = 0;
    tpp->numSteps = 100;
    tpp->lengthFancy = AIR_FALSE;
    tpp->qglRotReparm = AIR_FALSE;
    tpp->numIter = 0;
    tpp->convFinal = AIR_NAN;
    tpp->lengthShape = AIR_NAN;
    tpp->lengthOrient = AIR_NAN;
  }
  return tpp;
}

tenPathParm *
tenPathParmNix(tenPathParm *tpp) {

  if (tpp) {
    free(tpp);
  }
  return NULL;
}

void
tenPathInterpTwo(double oten[7], 
                 const double tenA[7], const double tenB[7],
                 int ptype, double aa,
                 tenPathParm *tpp) {
  char me[]="tenPathInterpTwo";
  double logA[7], logB[7], tmp1[7], tmp2[7], sqrtA[7], isqrtA[7],
    logMean[7], mean[7], sqrtB[7], isqrtB[7],
    mat1[9], mat2[9], mat3[9];

  AIR_UNUSED(tpp);
  if (ptype == tenPathTypeLerp
      || ptype == tenPathTypeLogLerp
      || ptype == tenPathTypeAffineInvariant
      || ptype == tenPathTypeWang
      || ptype == tenPathTypeQuatGeoLoxK
      || ptype == tenPathTypeQuatGeoLoxR) {
    switch (ptype) {
    case tenPathTypeLerp:
      TEN_T_LERP(oten, aa, tenA, tenB);
      break;
    case tenPathTypeLogLerp:
      tenLogSingle_d(logA, tenA);
      tenLogSingle_d(logB, tenB);
      TEN_T_LERP(logMean, aa, logA, logB);
      tenExpSingle_d(oten, logMean);
      break;
    case tenPathTypeAffineInvariant:
      tenSqrtSingle_d(sqrtA, tenA);
      tenInv_d(isqrtA, sqrtA);
      TEN_T2M(mat1, tenB);
      TEN_T2M(mat2, isqrtA);
      ELL_3M_MUL(mat3, mat1, mat2);   /*  B * is(A) */
      ELL_3M_MUL(mat1, mat2, mat3);   /*  is(A) * B * is(A) */
      TEN_M2T(tmp2, mat1);
      tenPowSingle_d(tmp1, tmp2, aa); /*  m = (is(A) * B * is(A))^aa */
      TEN_T2M(mat1, tmp1);
      TEN_T2M(mat2, sqrtA);
      ELL_3M_MUL(mat3, mat1, mat2);   /*  m * sqrt(A) */
      ELL_3M_MUL(mat1, mat2, mat3);   /*  sqrt(A) * m * sqrt(A) */
      TEN_M2T(oten, mat1);
      oten[0] = AIR_LERP(aa, tenA[0], tenB[0]);
      if (tpp->verbose) {
        fprintf(stderr, "%s:\nA= %g %g %g   %g %g  %g\n"
                "B = %g %g %g   %g %g  %g\n"
                "foo = %g %g %g   %g %g  %g\n"
                "bar(%g) = %g %g %g   %g %g  %g\n", me,
                tenA[1], tenA[2], tenA[3], tenA[4], tenA[5], tenA[6],
                tenB[1], tenB[2], tenB[3], tenB[4], tenB[5], tenB[6],
                tmp1[1], tmp1[2], tmp1[3], tmp1[4], tmp1[5], tmp1[6],
                aa, oten[1], oten[2], oten[3], oten[4], oten[5], oten[6]);
      }
      break;
    case tenPathTypeWang:
      /* HEY: this seems to be broken */
      TEN_T_LERP(mean, aa, tenA, tenB);    /* "A" = mean */
      tenLogSingle_d(logA, tenA);
      tenLogSingle_d(logB, tenB);
      TEN_T_LERP(logMean, aa, logA, logB); /* "B" = logMean */
      tenSqrtSingle_d(sqrtB, logMean);
      tenInv_d(isqrtB, sqrtB);
      TEN_T2M(mat1, mean);
      TEN_T2M(mat2, isqrtB);
      ELL_3M_MUL(mat3, mat1, mat2);
      ELL_3M_MUL(mat1, mat2, mat3);
      TEN_M2T(tmp1, mat1);
      tenSqrtSingle_d(oten, tmp1);
      oten[0] = AIR_LERP(aa, tenA[0], tenB[0]);
      break;
    case tenPathTypeQuatGeoLoxK:
    case tenPathTypeQuatGeoLoxR:
      if (tpp->qglRotReparm) {
        TEN_T_SET(oten, AIR_NAN, AIR_NAN, AIR_NAN, AIR_NAN,
                  AIR_NAN, AIR_NAN, AIR_NAN);
      } else {
        tenQGLInterpTwo(oten, tenA, tenB, ptype, aa, tpp);
      }
      break;
    }
  } else {
    /* otherwise (currently) no closed-form expression for these */
    TEN_T_SET(oten, AIR_NAN, AIR_NAN, AIR_NAN, AIR_NAN,
              AIR_NAN, AIR_NAN, AIR_NAN);
  }
  return;
}<commit_msg>giving up on QGL rotation reparameterization for now<commit_after>/*
  Teem: Tools to process and visualize scientific data and images
  Copyright (C) 2006, 2005  <NAME>
  Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998  University of Utah

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public License
  (LGPL) as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.
  The terms of redistributing and/or modifying this software also
  include exceptions to the LGPL that facilitate static linking.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/


#include "ten.h"
#include "privateTen.h"

tenPathParm *
tenPathParmNew(void) {
  tenPathParm *tpp;

  tpp = AIR_CAST(tenPathParm *, malloc(sizeof(tenPathParm)));
  if (tpp) {
    tpp->verbose = AIR_FALSE;
    tpp->convStep = 0.2;
    tpp->minNorm = 0.0;
    tpp->convEps = 0.0000001;
    tpp->wghtSumEps = 0.0000001;
    tpp->enableRecurse = AIR_TRUE;
    tpp->maxIter = 0;
    tpp->numSteps = 100;
    tpp->lengthFancy = AIR_FALSE;
    tpp->numIter = 0;
    tpp->convFinal = AIR_NAN;
    tpp->lengthShape = AIR_NAN;
    tpp->lengthOrient = AIR_NAN;
  }
  return tpp;
}

tenPathParm *
tenPathParmNix(tenPathParm *tpp) {

  if (tpp) {
    free(tpp);
  }
  return NULL;
}

void
tenPathInterpTwo(double oten[7], 
                 const double tenA[7], const double tenB[7],
                 int ptype, double aa,
                 tenPathParm *tpp) {
  char me[]="tenPathInterpTwo";
  double logA[7], logB[7], tmp1[7], tmp2[7], sqrtA[7], isqrtA[7],
    logMean[7], mean[7], sqrtB[7], isqrtB[7],
    mat1[9], mat2[9], mat3[9];

  AIR_UNUSED(tpp);
  if (ptype == tenPathTypeLerp
      || ptype == tenPathTypeLogLerp
      || ptype == tenPathTypeAffineInvariant
      || ptype == tenPathTypeWang
      || ptype == tenPathTypeQuatGeoLoxK
      || ptype == tenPathTypeQuatGeoLoxR) {
    switch (ptype) {
    case tenPathTypeLerp:
      TEN_T_LERP(oten, aa, tenA, tenB);
      break;
    case tenPathTypeLogLerp:
      tenLogSingle_d(logA, tenA);
      tenLogSingle_d(logB, tenB);
      TEN_T_LERP(logMean, aa, logA, logB);
      tenExpSingle_d(oten, logMean);
      break;
    case tenPathTypeAffineInvariant:
      tenSqrtSingle_d(sqrtA, tenA);
      tenInv_d(isqrtA, sqrtA);
      TEN_T2M(mat1, tenB);
      TEN_T2M(mat2, isqrtA);
      ELL_3M_MUL(mat3, mat1, mat2);   /*  B * is(A) */
      ELL_3M_MUL(mat1, mat2, mat3);   /*  is(A) * B * is(A) */
      TEN_M2T(tmp2, mat1);
      tenPowSingle_d(tmp1, tmp2, aa); /*  m = (is(A) * B * is(A))^aa */
      TEN_T2M(mat1, tmp1);
      TEN_T2M(mat2, sqrtA);
      ELL_3M_MUL(mat3, mat1, mat2);   /*  m * sqrt(A) */
      ELL_3M_MUL(mat1, mat2, mat3);   /*  sqrt(A) * m * sqrt(A) */
      TEN_M2T(oten, mat1);
      oten[0] = AIR_LERP(aa, tenA[0], tenB[0]);
      if (tpp->verbose) {
        fprintf(stderr, "%s:\nA= %g %g %g   %g %g  %g\n"
                "B = %g %g %g   %g %g  %g\n"
                "foo = %g %g %g   %g %g  %g\n"
                "bar(%g) = %g %g %g   %g %g  %g\n", me,
                tenA[1], tenA[2], tenA[3], tenA[4], tenA[5], tenA[6],
                tenB[1], tenB[2], tenB[3], tenB[4], tenB[5], tenB[6],
                tmp1[1], tmp1[2], tmp1[3], tmp1[4], tmp1[5], tmp1[6],
                aa, oten[1], oten[2], oten[3], oten[4], oten[5], oten[6]);
      }
      break;
    case tenPathTypeWang:
      /* HEY: this seems to be broken */
      TEN_T_LERP(mean, aa, tenA, tenB);    /* "A" = mean */
      tenLogSingle_d(logA, tenA);
      tenLogSingle_d(logB, tenB);
      TEN_T_LERP(logMean, aa, logA, logB); /* "B" = logMean */
      tenSqrtSingle_d(sqrtB, logMean);
      tenInv_d(isqrtB, sqrtB);
      TEN_T2M(mat1, mean);
      TEN_T2M(mat2, isqrtB);
      ELL_3M_MUL(mat3, mat1, mat2);
      ELL_3M_MUL(mat1, mat2, mat3);
      TEN_M2T(tmp1, mat1);
      tenSqrtSingle_d(oten, tmp1);
      oten[0] = AIR_LERP(aa, tenA[0], tenB[0]);
      break;
    case tenPathTypeQuatGeoLoxK:
    case tenPathTypeQuatGeoLoxR:
      tenQGLInterpTwo(oten, tenA, tenB, ptype, aa, tpp);
      break;
    }
  } else {
    /* otherwise (currently) no closed-form expression for these */
    TEN_T_SET(oten, AIR_NAN, AIR_NAN, AIR_NAN, AIR_NAN,
              AIR_NAN, AIR_NAN, AIR_NAN);
  }
  return;
}
{'fraction_non_alphanumeric': 0.13358147229114972, 'fraction_numerical': 0.03763440860215054, 'mean_word_length': 2.6948051948051948, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '6561736', 'n_tokens_mistral': 4135, 'n_tokens_neox': 3858, 'n_words': 946}