+
    ÿäûj‚7  ã                   ó  a € R t0 t ^ RIt^ RIHtHtHtHtHt ^ RIt^ RI	H
t
HtHt ^ RIHt ^ RIHt . RO. RO. RO.t] ^ k . RO. RO. RO.t] ^k RR R llt]P(                  RR3R R	 lltR
R]P(                  RRR3R R lltR# )é    N)ÚCallableÚListÚOptionalÚTupleÚUnion)ÚKORNIA_CHECKÚKORNIA_CHECK_IS_TENSORÚKORNIA_CHECK_SHAPE)Únormalize_min_max)Úfilter2dc                ó  € V ^8„  d   QhR\         R\         R\         R\        R\        P                  3,          R\        \        P
                  ,          R\        \        P                  ,          R\        P                  /# )	é   Ú
replicatesÚwidthÚheightÚ	random_fn.ÚdeviceÚdtypeÚreturn)Úintr   ÚtorchÚTensorr   r   r   )Úformats   "ÚYC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\contrib\diamond_square.pyÚ__annotate__r   !   sr   € ÷ 3ñ 3Üð3äð3ô ð3ô ˜œUŸ\™\Ð)Õ*ð	3ô
 ”U—\‘\Õ"ð3ô ”E—K‘KÕ ð3ô ‡\�\ñ3ó    c                ó   € \        V^8H  ;'       g    V^8H  R4       RpV^8X  d   RpY!r!\        V^,          ^8H  ;'       d    V^8„  R4       \        P                  ! V ^W.WER7      pV! V ^^V^,           ^,          .WER7      VR
&   VR^ RR^13,          VR,          ,           VR^RR^13,          ,           VR,          ,           R,          VR&   VR^ RR^13,          VR,          ,           VR,          ,           R	,          VR&   VR^RR^13,          VR,          ,           VR,          ,           R	,          VR&   VR,          VR,          ,           VR,          ,           R	,          VR&   VR,          VR,          ,           VR,          ,           R	,          VR&   V^8”  dV   VR^ ^R^13,          VR^^R^13,          ,           VR^^R^13,          ,           VR,          ,           R,          VR^^R^13&   V'       d   VP                  ^^4      pV# )a¥  Generate the diamond square image seee.

Args:
    replicates: the num of batched replicas for the image.
    width: the expected image width.
    height: the expected image height.
    random_fn: the random function to generate the image seed.
    device: the torch device where to create the image seed.
    dtype: the torch dtype where to create the image seed.

Return:
    the generated image seed of size Bx1xHxW.

z#Height or Width must be equal to 3.FTz+Height must be odd and height bigger than 2©r   r   .Ng      @g      @).ºNNr   r   éþÿÿÿ).r   ºr   Nr   ).r   r!   ).é   ºr"   Nr   ).r   r#   ).r   r#   ).r   r   ).r   r   ).r"   r"   ).r"   r   éÿÿÿÿ).r   r$   ).r   r$   ).r"   r    ).r"   r$   ).r"   :é   Nr   )r   r   ÚzerosÚ	transpose)r   r   r   r   r   r   r'   Úress   &&&&&&  r   Ú_diamond_square_seedr)   !   s  € ô, �˜!‘×*Ð*˜v¨™{Ð,QÔRà€IØ�„{Øˆ	Øˆvô �˜!•˜q‘×/Ð/ V¨a¡ZÐ1^Ô_ô �+Š+�z 1 eÐ4¸VÔ
Q€CÙ" J°°1°vÀµzÀaÕ6GÐ#HÐQWÔe€CˆÑð ˜S ! U b¨ U˜]Õ+¨c°,Õ.?Õ?À#ÀcÈ1ÈeÈrÐRSÈeÀmÕBTÕTÐWZÐ[gÕWhÕhÐloÕo€CˆÑð ˜S ! U b¨ U˜]Õ+¨c°,Õ.?Õ?À#ÀlÕBSÕSÐWZÕZ€CˆÑØ˜S ! U b¨ U˜]Õ+¨c°,Õ.?Õ?À#ÀlÕBSÕSÐWZÕZ€CˆÑØ˜)•n s¨9¥~Õ5¸¸I½ÕFÈ#ÕM€Cˆ	�NØ˜:•¨¨Z­Õ8¸3¸z½?ÕJÈcÕQ€Cˆ
�OØ�„zà��Q˜˜"˜Q˜�Õ # c¨1¨a°°1¨f nÕ"5Õ5¸¸CÀÀAÀbÈÀF¸NÕ8KÕKÈcÐR^ÕN_Õ_ØõˆˆC��A�b˜�FˆNÑ÷ Ø�m‰m˜A˜qÓ!ˆØ€Jr   c                ó@  € V ^8„  d   QhR\         P                  R\        \        \         P                  3,          R\        R\         P                  3,          R\
        \         P                  ,          R\
        \         P                  ,          R\         P                  /# )r   ÚimgÚrandom_scaler   .Údiamond_kernelÚsquare_kernelr   )r   r   r   Úfloatr   r   )r   s   "r   r   r   W   sŠ   € ÷ Ahñ AhÜ	�‰ðAhäœœuŸ|™|Ð+Õ,ðAhô ˜œUŸ\™\Ð)Õ*ðAhô œUŸ\™\Õ*ð	Ahô
 œEŸL™LÕ)ðAhô ‡\�\ñAhr   c                ó  € \        V . RO4       Vf+   \        P                  ! \        .4      P	                  V 4      pVf+   \        P                  ! \
        .4      P	                  V 4      pV P                  w  rVrx\        P                  ! V^^V^,
          ,          ^,           ^V^,
          ,          ^,           .V P                  V P                  R7      p	W	R&   Rp
\        P                  ! V	4      pW«R&   W«R
&   W«R&   W«R&   V! V	P                  4       V P                  V P                  R7      V,          p\        P                  ! V	P                  R,          V P                  R7      P                  R	^4      ^,          p\        P                  ! V	P                  R	,          V P                  R7      P                  ^R	4      ^,          pV^8H  V^8H  ,          P	                  V P                  4      pWÞ,           ^8H  P	                  V P                  4      p\        W“4      pV	^V,
          V,          V,          ,           Wü,          ,           p	\        W”RR7      V,          pV	VV,          ,           ^V,
          V,          V,          ,           # )aÎ  Doubles the image resolution by applying a single diamond square steps.

Recursive application of this method creates plasma fractals.

Attention! The function is differentiable and gradients are computed as well.

If this function is run in the usual sense, it is more efficient if it is run in a no_grad()

Args:
    img: a 4D torch.Tensor where dimensions are Batch, Channel, Width, Height.
        Width and Height must both be 2^N+1 and
        Batch and Channels should in the usual case be 1.
    random_scale: a float  number in [0,1] controlling the randomness created pixels get. I the usual case, it is
        halved at every application of this function.
    random_fn: the random function to generate the image seed.
    diamond_kernel: the 3x3 kernel to perform the diamond step.
    square_kernel: the 3x3 kernel to perform the square step.

Return:
    A torch.Tensor on the same device as img with the same channels as img and width, height of 2^(N+1)+1.

r   )r   Úconstant)Úborder_type)ÚBÚCÚHÚW)ºNNNr7   r   r   gUUUUUUõ?)r7   r7   r7   r   r$   )r7   r7   r7   r$   )r7   r7   r   r7   )r7   r7   r$   r7   r    )r
   r   r   Údefault_diamond_kernelÚtoÚdefault_square_kernelÚshaper&   r   r   Ú	ones_likeÚsizeÚarangeÚviewr   )r+   r,   r   r-   r.   Úbatch_szÚ_r   r   Únew_imgÚfactorÚpad_compencateÚ
random_imgÚrowsÚcolsÚdiamond_centersÚsquare_centersÚdiamond_regionsÚsquare_regionss   &&&&&              r   Ú_one_diamond_one_squarerL   W   s  € ô: �sÒ0Ô1ð ÒÜŸšÔ'=Ð&>Ó?×BÑBÀ3ÓGˆØÒÜŸšÔ&;Ð%<Ó=×@Ñ@ÀÓEˆà!$§¡Ñ€H�Ü!ŸKšKØ	�1�a˜6 A�:Õ&¨Õ*¨A°¸µ­O¸aÕ,?Ð@ÈÏÉÐ[^×[dÑ[dô€Gð "ˆNÑà€FÜ—_’_ WÓ-€NØ!'�:ÑØ"(�;ÑØ!'�:ÑØ"(�;Ñá(¨¯©«ÀÇ
Á
ÐRU×R[ÑR[Ô\Ð_kÕk€Jô �<Š<˜Ÿ™ bÕ)°#·*±*Ô=×BÑBÀ2ÀqÓIÈAÕM€DÜ�<Š<˜Ÿ™ bÕ)°#·*±*Ô=×BÑBÀ1ÀbÓIÈAÕM€DØ ™	 d¨a¡iÕ0×4Ñ4°S·Y±YÓ?€OØ•{ qÑ(×,Ñ,¨S¯Y©YÓ7€Nô ˜wÓ7€OØ˜˜\Õ)¨_Õ<¸ÕNÕNÐQ`ÕQmÕm€Gô ˜gÀ*ÔMÐP^Õ^€NØ�^ jÕ0Õ0°A¸Õ4DÈÕ3VÐYgÕ3gÕgÐgr   g      à?g      ð?c                óè  € V ^8„  d   QhR\         \        \        \        \        3,          R\        \        \        P
                  3,          R\        \        \        P
                  3,          R\        R\        P
                  3,          R\        \         \        \        3,          ,          R\        \        P                  ,          R\        \        P                  ,          R	\        P
                  /# )
r   Úoutput_sizeÚ	roughnessr,   r   .Únormalize_ranger   r   r   )
r   r   r   r/   r   r   r   r   r   r   )r   s   "r   r   r   ›   s¾   € ÷ vñ vÜ”sœC¤¤cÐ)Õ*ðvä”UœEŸL™LÐ(Õ)ðvô œœuŸ|™|Ð+Õ,ðvô ˜œUŸ\™\Ð)Õ*ð	vô
 œe¤E¬5 LÕ1Õ2ðvô ”U—\‘\Õ"ðvô ”E—K‘KÕ ðvô ‡\�\ñvr   c           	     ó*  € \        \        V 4      ^8H  R4       \        V\        P                  4      '       gU   \        P                  ! V....4      P                  WV4      pVP                  V ^ ,          V ^,          ,          ^^^.4      pMe\        V4       VP                  WVR7      P                  R^^^4      pVP                  V ^ ,          V ^,          ^^.4      pVP                  . RO4      p\        V\        P                  4      '       gU   \        P                  ! V....4      P                  WV4      pVP                  V ^ ,          V ^,          ,          ^^^.4      pMZVP                  WVR7      P                  R^^^4      pVP                  V ^ ,          V ^,          ^^.4      pVP                  . RO4      pV RR w  rx^p	V RR  F  p
Wš,          p	K  	  ^\        P                  ! \        P                  ! \        V^4      ^,
          4      4      ,          ^,           p^\        P                  ! \        P                  ! \        V^4      ^,
          4      4      ,          ^,           p\        \        \        P                  ! V^,
          4      ^,
          \        P                  ! V^,
          4      ^,
          4      4      pV^,
          ^V,          ,          ^,           pV^,
          ^V,          ,          ^,           p\!        WžWóWV4      pVP                  \        P"                  ! VP$                  VP$                  4      4      pTp\'        V4       F  pVV,          p\)        VVV4      pK  	  VP                  \        P"                  ! VP$                  VP$                  4      4      pVRRV1RV13,          pVP                  V 4      pVe@   \+        V^ ,          4      \+        V^,          4      pp\-        VP/                  4       VV4      pV# )a¤  Generate plasma-fractal noise maps by the diamond-square algorithm.

``noise = diamond_square((B, C, H, W))`` returns a ``(B, C, H, W)`` map of spatially correlated noise, an
independent fractal in each ``(b, c)`` plane. ``roughness`` and ``random_scale`` set how much of each finer level is
random rather than interpolated, and ``normalize_range`` rescales each plane to a given range. It ports
`tormentor <https://github.com/anguelos/tormentor>`_'s variant of the
`diamond-square algorithm <https://en.wikipedia.org/wiki/Diamond-square_algorithm>`_.

Convention:
    - The map is grown on a :math:`2^n + 1` grid and cropped to ``output_size`` at its top-left corner. The seed
      is a :math:`3 \times K` grid, transposed to :math:`K \times 3` for a map taller than wide, whose cell
      corners, the even nodes of its first and last rows (columns when transposed), are ``random_fn`` draws, and
      whose other nodes are the means of their neighbours. Each level sets a new node to
      :math:`(1 - s_k)\,\overline{n} + s_k\,u`, the mean :math:`\overline{n}` of its neighbours mixed with a
      ``random_fn`` draw :math:`u` by the weight :math:`s_k = \mathrm{random\_scale} \cdot \mathrm{roughness}^k`
      at level :math:`k \geq 1`. ``random_scale`` and ``roughness`` act only through :math:`s_k`, a mixing
      weight, not an amplitude. A border node of the square step averages its three neighbours; the diamond
      step's nodes are all interior, so its ``reflect`` padding never reaches them.
    - ``random_fn`` is called as ``random_fn(shape, device=device, dtype=dtype)`` and is the only source of
      randomness, so ``functools.partial(torch.rand, generator=g)`` leaves the global generator alone. With
      ``torch.rand`` the map stays in :math:`[0, 1]` without normalization while ``random_scale`` and ``roughness``
      are in :math:`[0, 1]`, and it is flat in mean (0.5 at every pixel) for every ``random_scale``, though its
      variance varies across the map.
    - ``roughness`` and ``random_scale`` are a float, a 0-d tensor or a ``(B,)`` tensor with one value per
      sample, and follow ``device`` and ``dtype``; with ``dtype=None`` a tensor keeps its dtype and a float takes
      the default dtype. When ``random_fn`` returns the dtype it is asked for, the map has the dtype that
      ``dtype`` (the default dtype for ``None``), ``roughness`` and ``random_scale`` promote to, at every map
      size. A ``random_fn`` that returns another dtype also promotes the levels' arithmetic to its dtype, but not
      a map with a side of 3 px or less, which is the seed alone and stores the draws in the requested dtype.
    - Without ``normalize_range`` the result can be a non-contiguous view, which ``.view(B, -1)`` cannot
      flatten; use ``.reshape``, or call ``.contiguous()`` first.
    - ``normalize_range=(min, max)`` rescales each :math:`(b, c)` plane to that range with
      :func:`~kornia.enhance.normalize_min_max`, whose ``eps`` keeps the maximum just below ``max``.

Args:
    output_size: the ``(B, C, H, W)`` size of the map to generate.
    roughness: the factor that scales the mixing weight at each recursion step.
    random_scale: scales the per-level mixing weight
        :math:`s_k = \mathrm{random\_scale} \cdot \mathrm{roughness}^k`, :math:`k \geq 1`.
    random_fn: the callable function to use to sample a random tensor.
    normalize_range: if given, the ``(min, max)`` range each plane is min-max normalized to.
    device: the torch device to place the output map.
    dtype: the torch dtype to place the output map.

Returns:
    The fractal map, ``(B, C, H, W)``.

Raises:
    BaseError: if ``output_size`` does not have four entries.

See Also:
    - :class:`~kornia.augmentation.RandomPlasmaShadow`: darkens image regions with these maps.
    - :class:`~kornia.augmentation.RandomPlasmaBrightness`: shifts image brightness by these maps.
    - :class:`~kornia.augmentation.RandomPlasmaContrast`: scales image contrast by these maps.

zoutput_size must be (B,C,H,W)r   N.r$   )r$   r"   r"   r"   r    )r   ÚlenÚ
isinstancer   r   r9   Úexpandr	   r?   ÚreshapeÚmathÚceilÚlog2Úmaxr   Úminr)   Úpromote_typesr   ÚrangerL   r/   r   Ú
contiguous)rN   rO   r,   r   rP   r   r   r   r   Únum_samplesÚxÚp2_widthÚ	p2_heightÚrecursion_depthÚ
seed_widthÚseed_heightÚseedr+   ÚscalerA   Úmin_valÚmax_vals   &&&&&&&               r   Údiamond_squareri   ›   s[  € ôB ”�[Ó! QÑ&Ð(GÔHÜ�l¤E§L¡L×1Ò1Ü—|’|¨ ~Ð&6Ð%7Ð$8Ó9×<Ñ<¸VÓKˆØ#×*Ñ*¨K¸­N¸[È½^Õ,KÈQÐPQÐSTÐ+UÓV‰ä˜|Ô,Ø#—‘¨f�ÓB×GÑGÈÈAÈqÐRSÓTˆØ#×*Ñ*¨K¸­N¸KÈ½NÈAÈqÐ+QÓRˆØ#×+Ñ+ªMÓ:ˆä�i¤§¡×.Ò.Ü—L’L Y K = /Ð!2Ó3×6Ñ6°vÓEˆ	Ø×$Ñ$ k°!¥n°{À1µ~Õ&EÀqÈ!ÈQÐ%OÓP‰	à—L‘L¨�LÓ<×AÑAÀ"ÀaÈÈAÓNˆ	Ø×$Ñ$ k°!¥n°kÀ!µnÀaÈÐ%KÓLˆ	Ø×%Ñ%¢mÓ4ˆ	à  Ð$�M€EØ€KØ˜˜"ÓˆØÕŠñ ð œŸš¤4§9¢9¬S°¸«]¸QÕ->Ó#?Ó@Õ@À1ÕD€HØœ$Ÿ)š)¤D§I¢I¬c°&¸!«n¸qÕ.@Ó$AÓBÕBÀQÕF€IÜœs¤4§9¢9¨X¸­\Ó#:¸QÕ#>ÄÇ	Â	È)ÐVWÍ-Ó@XÐ[\Õ@\Ó]Ó^€OØ !•|¨¨?Õ(:Õ:¸QÕ>€JØ! A�¨!¨_Õ*<Õ<¸qÕ@€KÜ ¸ÐQWÓ_€Dð
 Ÿ™¤× 3Ò 3°D·J±JÀ×@RÑ@RÓ SÓT€Cð €EÜ�?Ö#ˆØ˜	Õ!ˆÜ% c¨5°)Ó<Šñ $ð �&‰&”×$Ò$ S§Y¡Y°	·±Ó@Ó
A€Cð ˆc�6�E�6˜7˜F˜7Ð"Õ
#€CØ
�(‰(�;Ó
€Cð Ò"Ü  °Õ!3Ó4´e¸OÈAÕ<NÓ6O�ˆÜ §¡Ó 0°'¸7ÓCˆØ€Jr   c                óÀ   € V ^8„  d   Qh/ ^ \         9   d    \        \        \        ,          ,          ;R&   ^\         9   d    \        \        \        ,          ,          ;R&   # )r   r8   r:   )Ú__conditional_annotations__r   r/   )r   s   "r   r   r      s>   € ‡�÷ dÒ cœœT¤%�[Õ)Ñ cñ ÷ cÒ b”tœD¤�KÕ(Ñ bò r   )ç      Ð?ç        rl   )rm   rm   rm   )rm   rl   rm   )NN)rk   rV   Útypingr   r   r   r   r   r   Úkornia.core.checkr   r	   r
   Úkornia.enhancer   Úkornia.filtersr   r8   r:   r)   ÚrandrL   ri   r   )rk   s   @r   Ú<module>rs      sˆ   øð÷& €ß 9Õ 9ã ç VÑ VÝ ,Ý #ò .?ÂÒQbÐ,cÐ Ó cÚ,<Ò>OÒQaÐ+bÐ Ó b÷3ðr .3¯Z©ZØ-1Ø,0÷AhðL -0Ø/2Ø-2¯Z©ZØ59Ø%)Ø#'÷vñ vr   