
    ЏkhN                     P    d Z ddlZddlmZmZmZmZ ddlm	Z	m
Z
 d Zd Zd Zd	 Zy)
a  
This is a module evaluating the objective/constraint function with Nan/Inf handling.

Translated from Zaikun Zhang's modern-Fortran reference implementation in PRIMA.

Dedicated to late Professor M. J. D. Powell FRS (1936--2015).

Python translation by Nickolai Belakovski.
    N   )FUNCMAX	CONSTRMAXREALMAX	DEBUGGING)matprodprimasumc                 v    d| t        j                  |       <   t        j                  | t         t              } | S )zq
    This function moderates a decision variable. It replaces NaN by 0 and Inf/-Inf by
    REALMAX/-REALMAX.
    r   )npisnanclipr   )xs    ^/var/www/teggl/fontify/venv/lib/python3.12/site-packages/scipy/_lib/pyprima/common/evaluate.py	moderatexr      s.    
 AbhhqkN
G8W%AH    c                     t        j                  |       rt        n| } t        j                  | t         t              } | S )z
    This function moderates the function value of a MINIMIZATION problem. It replaces
    NaN and any value above FUNCMAX by FUNCMAX.
    )r   r   r   r   r   )fs    r   	moderatefr      s0    
 88A;AA
G8W%A Hr   c                 ~    t        j                  | dt               t        j                  | t         t              } | S )z
    This function moderates the constraint value, the constraint demanding this value
    to be NONNEGATIVE. It replaces any value below -CONSTRMAX by -CONSTRMAX, and any
    NaN or value above CONSTRMAX by CONSTRMAX.
    F)copynan)r   
nan_to_numr   r   )cs    r   	moderatecr   '   s-     MM!%Y/
I:y)AHr   c                    |t        |      nd}t        r t        t        j                  |            rJ t        j
                  ||z         }|t        ||j                        |z
  |d| t        t        j                  |            r$t        |      }t        j                  |      |z  }n3 | t        |            \  }||d t        |      }t        ||d       ||d t        rbt        j                  |      st        j                  |      rJ t        t        j                  |      t        j                  |      z        rJ ||fS )z
    This function evaluates CALCFC at X, returning the objective function value and the
    constraint value. Nan/Inf are handled by a moderated extreme barrier.
    Nr   )lenr   anyr   r   zerosr   Tr	   onesr   r   r   isposinf)calcfcr   m_nlconamatbvecm_lconconstrr   s           r   evaluater(   2   s     *SYF  rxx{### XXfw&'F!!TVV,t3w
288A; QK!A%#IaL16&'?
 aL#F67O4vw  HHQK2;;q>22rxx'"++f*==>>>f9r   )__doc__numpyr   constsr   r   r   r   linalgr   r	   r   r   r   r(    r   r   <module>r.      s,     : : %
	1r   