Няшная / Говнокод #26067 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
  79. 79
  80. 80
  81. 81
  82. 82
  83. 83
  84. 84
  85. 85
  86. 86
  87. 87
  88. 88
  89. 89
  90. 90
  91. 91
  92. 92
  93. 93
  94. 94
  95. 95
  96. 96
  97. 97
  98. 98
  99. 99
  100. 100
/* ../COBYLA2/cobyla2.f -- translated by f2c (version 20100827) */
...
/* Subroutine */ int cobyla_(integer *n, integer *m, doublereal *x, 
	doublereal *rhobeg, doublereal *rhoend, integer *iprint, integer *
	maxfun, doublereal *w, integer *iact)
{
    static integer ia, idx, mpp, icon, isim, isigb, idatm, iveta, isimi, 
	    ivsig, iwork;
    extern /* Subroutine */ int cobylb_(integer *, integer *, integer *, 
	    doublereal *, doublereal *, doublereal *, integer *, integer *, 
	    doublereal *, doublereal *, doublereal *, doublereal *, 
	    doublereal *, doublereal *, doublereal *, doublereal *, 
	    doublereal *, doublereal *, integer *);
    /* Parameter adjustments */
    --iact;
    --w;
    --x;

    /* Function Body */
    mpp = *m + 2;
    icon = 1;
    isim = icon + mpp;
    isimi = isim + *n * *n + *n;
    idatm = isimi + *n * *n;
    ia = idatm + *n * mpp + mpp;
    ivsig = ia + *m * *n + *n;
    iveta = ivsig + *n;
    isigb = iveta + *n;
    idx = isigb + *n;
    iwork = idx + *n;
    cobylb_(n, m, &mpp, &x[1], rhobeg, rhoend, iprint, maxfun, &w[icon], &w[
	    isim], &w[isimi], &w[idatm], &w[ia], &w[ivsig], &w[iveta], &w[
	    isigb], &w[idx], &w[iwork], &iact[1]);
    return 0;
} /* cobyla_ */
...
/* Subroutine */ int cobylb_(integer *n, integer *m, integer *mpp, doublereal 
	*x, doublereal *rhobeg, doublereal *rhoend, integer *iprint, integer *
	maxfun, doublereal *con, doublereal *sim, doublereal *simi, 
	doublereal *datmat, doublereal *a, doublereal *vsig, doublereal *veta,
	 doublereal *sigbar, doublereal *dx, doublereal *w, integer *iact)
{
    /* Format strings */
    static char fmt_10[] = "(/3x,\002The initial value of RHO is\002,1pe13.6"
	    ",2x,\002and PARMU is set to zero.\002)";
    static char fmt_50[] = "(/3x,\002Return from subroutine COBYLA because t"
	    "he \002,\002MAXFUN limit has been reached.\002)";
    static char fmt_70[] = "(/3x,\002NFVALS =\002,i5,3x,\002F =\002,1pe13.6,"
	    "4x,\002MAXCV =\002,1pe13.6/3x,\002X =\002,1pe13.6,1p4e15.6)";
    static char fmt_80[] = "(1pe19.6,1p4e15.6)";
    static char fmt_210[] = "(/3x,\002Return from subroutine COBYLA because"
	    " \002,\002rounding errors are becoming damaging.\002)";
    static char fmt_410[] = "(/3x,\002Increase in PARMU to\002,1pe13.6)";
    static char fmt_580[] = "(/3x,\002Reduction in RHO to\002,1pe13.6,\002  "
	    "and PARMU =\002,1pe13.6)";
    static char fmt_590[] = "(/3x,\002Normal return from subroutine COBYL"
	    "A\002)";

    /* System generated locals */
    integer sim_dim1, sim_offset, simi_dim1, simi_offset, datmat_dim1, 
	    datmat_offset, a_dim1, a_offset, i__1, i__2, i__3;
    doublereal d__1, d__2;

    /* Builtin functions */
    integer s_wsfe(cilist *), do_fio(integer *, char *, ftnlen), e_wsfe(void);
    double sqrt(doublereal);

    /* Local variables */
    static doublereal f;
    static integer i__, j, k, l, mp, np, iz;
    static doublereal phi, rho, sum, beta, cmin, cmax;
    static integer ivmc;
    static doublereal weta;
    static integer ivmd;
    static doublereal temp, wsig, gamma;
    static integer iflag;
    static doublereal alpha, delta, denom, tempa, barmu;
    static integer nbest, ifull, iptem, jdrop;
    static doublereal ratio, vmold, parmu, error, vmnew;
    extern /* Subroutine */ int calcfc_(integer *, integer *, doublereal *, 
	    doublereal *, doublereal *);
    static integer ibrnch;
    static doublereal edgmax, pareta, prerec, phimin, parsig;
    static integer isdirn, nfvals, izdota;
    static doublereal cvmaxm, dxsign, prerem;
    static integer iptemp;
    static doublereal resmax, cvmaxp;
    static integer idxnew;
    static doublereal resnew, trured;
    extern /* Subroutine */ int trstlp_(integer *, integer *, doublereal *, 
	    doublereal *, doublereal *, doublereal *, integer *, integer *, 
	    doublereal *, doublereal *, doublereal *, doublereal *, 
	    doublereal *, doublereal *);

    /* Fortran I/O blocks */
    static cilist io___22 = { 0, 6, 0, fmt_10, 0 };
    static cilist io___29 = { 0, 6, 0, fmt_50, 0 };
    static cilist io___33 = { 0, 6, 0, fmt_70, 0 };
    static cilist io___34 = { 0, 6, 0, fmt_80, 0 };
    static cilist io___39 = { 0, 6, 0, fmt_210, 0 };

Найдено в зависимостях «SlangTNG». Библиотека «COBYLA», автоматически переведённая с «Фортрана».

/* This subroutine minimizes an objective function F(X) subject to M */
/* inequality constraints on X, where X is a vector of variables that has */
/* N components. The algorithm employs linear approximations to the */
/* objective and constraint functions, the approximations being formed by */
/* linear interpolation at N+1 points in the space of the variables. */

https://tng.tuxfamily.org/index.php?title=Main_Page

Запостил: XYPO3BO3 XYPO3BO3, (Updated )

Комментарии (20) RSS

    • <?php
      function cobyla_($n,$m,$x,$rhobeg,$rhoend,$iprint,$maxfun,$w,$iact)
      {
          /* Parameter adjustments */
          --$iact;
          --$w;
          --$x;
          /* Function Body */
          $mpp = $m[0] + 2;
          $icon = 1;
          $isim = $icon + $mpp;
          $isimi = $isim + $n[0] * $n[0] + $n[0];
          $idatm = $isimi + $n[0] * $n[0];
          $ia = $idatm + $n[0] * $mpp + $mpp;
          $ivsig = $ia + $m[0] * $n[0] + $n[0];
          $iveta = $ivsig + $n[0];
          $isigb = $iveta + $n[0];
          $idx = $isigb + $n[0];
          $iwork = $idx + $n[0];
          cobylb_($n, $m, $mpp, $x[1], $rhobeg, $rhoend, $iprint, $maxfun, $w[$icon], $w[
      	    $isim], $w[$isimi], $w[$idatm], $w[$ia], $w[$ivsig], $w[$iveta], $w[
      	    $isigb], $w[$idx], $w[$iwork], $iact[1]);
          return 0;
      } /* cobyla_ */
      ...
      function cobylb_($n,$m,$mpp,$x,$rhobeg,$rhoend,$iprint,$maxfun,$con,$sim,$simi,$datmat,$a,$vsig,$veta,$sigbar,$dx,$w,$iact)
      {
          /* Format strings */
          $fmt_10 = "(/3x,\002The initial value of RHO is\002,1pe13.6"
      	    ",2x,\002and PARMU is set to zero.\002)";
          $fmt_50 = "(/3x,\002Return from subroutine COBYLA because t"
      	    "he \002,\002MAXFUN limit has been reached.\002)";
          $fmt_70 = "(/3x,\002NFVALS =\002,i5,3x,\002F =\002,1pe13.6,"
      	    "4x,\002MAXCV =\002,1pe13.6/3x,\002X =\002,1pe13.6,1p4e15.6)";
          $fmt_80 = "(1pe19.6,1p4e15.6)";
          $fmt_210 = "(/3x,\002Return from subroutine COBYLA because"
      	    " \002,\002rounding errors are becoming damaging.\002)";
          $fmt_410 = "(/3x,\002Increase in PARMU to\002,1pe13.6)";
          $fmt_580 = "(/3x,\002Reduction in RHO to\002,1pe13.6,\002  "
      	    "and PARMU =\002,1pe13.6)";
          $fmt_590 = "(/3x,\002Normal return from subroutine COBYL"
      	    "A\002)";
      
          /* Fortran I/O blocks */
          $cilist io___22 = [0, 6, 0, $fmt_10, 0];
          $cilist io___29 = [0, 6, 0, $fmt_50, 0];
          $cilist io___33 = [0, 6, 0, $fmt_70, 0];
          $cilist io___34 = [0, 6, 0, $fmt_80, 0];
          $cilist io___39 = [0, 6, 0, $fmt_210, 0];
      Ответить
    • ААААА!

      https://en.wikipedia.org/wiki/COBYLA

      «Constrained optimization by linear approximation (COBYLA) is a numerical optimization method for constrained problems where the derivative of the objective function is not known, invented by Michael J. D. Powell.»

      Математический алгоритм под названием «кобыла». Эта фигню ещё добавили в питоновский пакет «scipy»:
      https://stackoverflow.com/questions/12781622/
      Ответить
      • def fmin_cobyla(func, x0, cons, args=(), consargs=None, rhobeg=1.0,
                        rhoend=1e-4, maxfun=1000, disp=None, catol=2e-4):
            """
            Minimize a function using the Constrained Optimization BY Linear
            Approximation (COBYLA) method. This method wraps a FORTRAN
            implementation of the algorithm.
        ...
        
        def _minimize_cobyla(fun, x0, args=(), constraints=(),
                             rhobeg=1.0, tol=1e-4, maxiter=1000,
                             disp=False, catol=2e-4, **unknown_options):
            """
            Minimize a scalar function of one or more variables using the
            Constrained Optimization BY Linear Approximation (COBYLA) algorithm.
        Ответить
          • Ойса, ты, ойса,
            Ты меня не бойся.
            Я тебя не трону,
            Ты не беспокойся.
            Ответить
              • бойса кодта

                У меня был одноклассник по фамилии Бойс. Он был небольшого роста, и потому его иногда буллили (или, как говорили в моем дествте -- пиздили).
                Он вырос, спился, и умер
                Ответить
  • Оригинал на «Фортране»:

    http://plato.asu.edu/ftp/other_software/COBYLA2.tar.gz

    C------------------------------------------------------------------------ 
    C
          SUBROUTINE COBYLA (N,M,X,RHOBEG,RHOEND,IPRINT,MAXFUN,W,IACT)
          IMPLICIT DOUBLE PRECISION (A-H,O-Z)
          DIMENSION X(*),W(*),IACT(*)
    C
    C     This subroutine minimizes an objective function F(X) subject to M
    C     inequality constraints on X, where X is a vector of variables that has
    C     N components. The algorithm employs linear approximations to the
    C     objective and constraint functions, the approximations being formed by
    C     linear interpolation at N+1 points in the space of the variables.
    Ответить
    • Конец исходника:

      C
        490 IF (MCON .EQ. M) GOTO 480
            IFULL=0
        500 RETURN
            END


      Как «Бейсик». А в первой половине ещё были структурированные конструкции.
      Ответить
      • Прикол:
        https://github.com/scipy/scipy/issues/19557

        В старом неструктурированном «Фортране» можно было вложенные циклы заканчивать общей меткой.

        C
              do 10 i = 1, 3
              do 10 j = 1, 3
              write(*,*) i, j
        C >>> SHARED TERMINATION <<<
           10 continue


        Разделяются метки так:

        C
              do 40 i = 1, 3
              do 50 j = 1, 3
              write(*,*) i, j
           50 continue
           40 continue
        Ответить
        • Кстати, оцените: нативное расширение «Питона», которое компилируется из сишного кода, полученного из кода на «Фортране» с помощью «f2c».
          Ответить
        • Ого, круто, это чтобы не писать:
                   }
                }
              }
            }
          }

          или не писать:

          впитоне
          Ответить
          • Да, напитоне хвосты легко закрываются, просто убираешь отступ. А в других ЯП куча писанины.
            Ответить

Добавить комментарий

Семь раз отмерь — один отрежь, guest!

    А не использовать ли нам bbcode?


    8