B @`?@sdddlmZmZeddddZdddZdd Zd d Zd d ZdddZ dddZ dddZ dS))numpyattempt_importz*pyomo.contrib.pynumero.sparse.block_vectorT)Z defer_checkNcCsJtjj}t|tjr |||dSt|tjr@|}|||dStdS)N)ord) npZlinalgnorm isinstancendarray block_vector BlockVectorflattenNotImplementedError)xrfZflat_xrD/tmp/pip-unpacked-wheel-bi3529v6/pyomo/contrib/pynumero/intrinsic.pyrs    rcCs"|}|}tj||||dS)N)rtolatol)r rallclose)x1Zx2rrZx1_flatZx2_flatrrrrsrcCstdd|DS)NcSsg|] }|qSr)r ).0arrr #szconcatenate..)r concatenate)Zarraysrrrr"src Gs|d}t|dkrtdt|dkr:tdt|t|}t|tjr||dkr|jrftdt|j }x2t |j D]$}| |g}| |t |dq~W|fS|d}|d}t|tjrt|tjr|jrtd|jrtd|jrtd|j |j kstd|j |j ks0tdt|j }x@t |j D]2}| || || |g}| |t |qHW|St|tjrnt|tjrn|jrtd|jrtd|j |j kstd|j|jkstd|j|jkstdt|j }d}xXt |j D]J}|j|} | ||||| | |g}| |t ||| 7}qW|St|tjrZt|tjrZ|jrtd|jrtd|j |j kstd|j|jkstd|j|jkstdt|j }d}xXt |j D]J}|j|} | || ||||| g}| |t ||| 7}qW|St|r"t|tjr"|jrtd|jrtd|j |j kstd|j|jkstdt|j }d}xLt |j D]>}|j|} | ||| |g}| |t ||| 7}qW|St|tjrt|r|jrLtd|jr\td|j |j ksrtd|j|jkstdt|j }d}xLt |j D]>}|j|} | || ||g}| |t ||| 7}qW|St|tjrt|tjr|jrtd|j|jks,td|j|jksBtdt|j }d}x^t |j D]P}|j|} | ||||| |||| g}| |t ||| 7}q^W|St|tjr^t|r^|jrtd|j|jkstdt|j }d}xRt |j D]D}|j|} | ||||| |g}| |t ||| 7}qW|St|rt|tjr|jrtd|j|jkstdt|j }d}xRt |j D]D}|j|} | |||||| g}| |t ||| 7}qW|St|rtt|rt|jr.tdt|j }x4t |j D]&}| |||g}| |t |qFW|Stnd|dkrtj |S|d}|d}t|tjr|}t|tjr|}|||g}tj |SdS) Nrz1either both or neither of x and y should be givenz,where() takes at most 3 arguments ({} given)zIOperation not allowed with None blocks. Specify all blocks in BlockVectorzHOperation on BlockVectors need the same number of blocks on each operand)len ValueError TypeErrorformatrr r has_noneAssertionErrornblocksrange get_block set_blockwhererrsizeZ _brow_lengthsZisscalarr r ) args conditionZn_argsresi_argsr yaccumZ nelementsrrrr&&s        "  "      (        r&Fc Cs0t|tjrt|tjr|jr&td|jr4td|j|jksHtdt|j}x6t|jD](}||t| || |||dq`W|St|tjrt|t j r|jrtdt|j}x0t|jD]"}||t| ||||dqW|St|t j r&t|t j r&t j||||dSt dS)NzIOperation not allowed with None blocks. Specify all blocks in BlockVectorzHOperation on BlockVectors need the same number of blocks on each operand) assume_uniqueinvert) rr r r r!r"r#r%isinr$rrr )elementZ test_elementsr/r0r*r+rrrr1s4  r1c Cs|r tt|tr*t|dkr*|d}n&t|tjsBt|tjrH|}ntdt|trpt|dkrp|d}n&t|tjst|tjr|}ntdt|tjr(t|tjr(|j |j kst d|j rt d|j rt dt|j }x4t |j D]&}| |t|||||dqW|St|tjrt|tjr|j rTt dt|j }x2t |j D]$}| |tj||||dqlW|St|tjrt|tjr|j rt dt|j }x2t |j D]$}| |tj||||dqW|Stj|||dSdS)Nrrz>ar1 type not recognized. Needs to be np.ndarray or BlockVectorz>ar2 type not recognized. Needs to be np.ndarray or BlockVectorzNumber of blocks does not matchzIOperation not allowed with None blocks. Specify all blocks in BlockVector)r/)r rtuplerrrr r RuntimeErrorr"r!r r#r% intersect1dr$)ar1ar2r/Zreturn_indicesr r-r*r+rrrr5sB   & $ $r5c Cst|tr t|dkr |d}n&t|tjs8t|tjr>|}ntdt|trft|dkrf|d}n&t|tjs~t|tjr|}ntdt|tjrt|tjr|j|jkst d|j rt d|j rt dt|j}x4t |jD]&}| |t |||||dqW|St|tjrt|tjr|j rJt dt|j}x2t |jD]$}| |tj ||||dqbW|St|tjrt|tjr|j rt dt|j}x2t |jD]$}| |tj ||||dqW|Stj |||dSdS)Nrrz>ar1 type not recognized. Needs to be np.ndarray or BlockVectorz>ar2 type not recognized. Needs to be np.ndarray or BlockVectorzNumber of blocks does not matchzIOperation not allowed with None blocks. Specify all blocks in BlockVector)r/)rr3rrrr r r4r"r!r r#r% setdiff1dr$)r6r7r/r r-r*r+rrrr8s>   & $ $r8)N)FF)FF)F) Zpyomo.common.dependenciesrrrr rrrr&r1r5r8rrrr s   $ 0