:py:mod:`alhambra.fastreduceD`
==============================

.. py:module:: alhambra.fastreduceD


Module Contents
---------------

Classes
~~~~~~~

.. autoapisummary::

   alhambra.fastreduceD.FTile
   alhambra.fastreduceD.FTilesArray
   alhambra.fastreduceD.TileWithUse
   alhambra.fastreduceD.FGlueList
   alhambra.fastreduceD.FTileList
   alhambra.fastreduceD._FastTileSet



Functions
~~~~~~~~~

.. autoapisummary::

   alhambra.fastreduceD._fdg
   alhambra.fastreduceD._ffakedouble_n
   alhambra.fastreduceD._ffakesingle
   alhambra.fastreduceD.ptins
   alhambra.fastreduceD.gmatch
   alhambra.fastreduceD.gcomp
   alhambra.fastreduceD.findmovetiles
   alhambra.fastreduceD._2go_moveandfill
   alhambra.fastreduceD._2go_findtrialmoves
   alhambra.fastreduceD._2go_checkandmove
   alhambra.fastreduceD.is_2go_nn
   alhambra.fastreduceD.gen_2go_maps
   alhambra.fastreduceD.gen_2go_profile
   alhambra.fastreduceD.is_2go_equiv
   alhambra.fastreduceD.is_22go_equiv
   alhambra.fastreduceD.fta_to_ft
   alhambra.fastreduceD.isatamequiv
   alhambra.fastreduceD.tilemerge
   alhambra.fastreduceD._findpotentialtilemerges
   alhambra.fastreduceD._findpotentialgluemerges
   alhambra.fastreduceD._recfix
   alhambra.fastreduceD._tilereduce
   alhambra.fastreduceD._gluereduce
   alhambra.fastreduceD._single_reduce_tiles
   alhambra.fastreduceD._single_reduce_ends
   alhambra.fastreduceD.reduce_tiles
   alhambra.fastreduceD.reduce_ends



Attributes
~~~~~~~~~~

.. autoapisummary::

   alhambra.fastreduceD.TMap
   alhambra.fastreduceD.TAU
   alhambra.fastreduceD.other
   alhambra.fastreduceD.uU
   alhambra.fastreduceD.uN
   alhambra.fastreduceD.uI
   alhambra.fastreduceD.uO
   alhambra.fastreduceD.uB
   alhambra.fastreduceD.uP
   alhambra.fastreduceD.invertuse
   alhambra.fastreduceD.usedict
   alhambra.fastreduceD.Equiv
   alhambra.fastreduceD.RSEL
   alhambra.fastreduceD.FTI
   alhambra.fastreduceD.FTS
   alhambra.fastreduceD.HSEL
   alhambra.fastreduceD.VSEL
   alhambra.fastreduceD.directions


.. py:data:: TMap

   

.. py:class:: FTile


   .. py:attribute:: name
      :type: str

      

   .. py:attribute:: used
      :type: bool

      

   .. py:attribute:: glues
      :type: numpy.typing.NDArray[numpy.int64]

      

   .. py:attribute:: use
      :type: numpy.typing.NDArray[numpy.int64]

      

   .. py:attribute:: color
      :type: Any

      

   .. py:attribute:: structure
      :type: Type[alhambra.tiles.Tile]

      

   .. py:attribute:: dfake
      :type: int

      

   .. py:attribute:: sfake
      :type: int

      


.. py:class:: FTilesArray


   .. py:attribute:: color
      :type: Any

      

   .. py:attribute:: use
      :type: numpy.ndarray[Any, numpy.dtype[numpy.int64]]

      

   .. py:attribute:: glues
      :type: numpy.ndarray[Any, numpy.dtype[numpy.int64]]

      

   .. py:attribute:: name
      :type: numpy.ndarray[Any, numpy.dtype[numpy.str0]]

      

   .. py:attribute:: used
      :type: numpy.ndarray[Any, numpy.dtype[numpy.bool8]]

      

   .. py:attribute:: structure
      :type: numpy.ndarray[Any, numpy.dtype[numpy.str0]]

      

   .. py:attribute:: dfake
      :type: numpy.ndarray[Any, numpy.dtype[numpy.int64]]

      

   .. py:attribute:: sfake
      :type: numpy.ndarray[Any, numpy.dtype[numpy.int64]]

      

   .. py:method:: __len__() -> int


   .. py:method:: from_ftiles(ftiles: Iterable[FTile]) -> FTilesArray
      :classmethod:



.. py:data:: TAU
   :value: 2

   

.. py:data:: other
   :value: [2, 3, 0, 1]

   

.. py:class:: TileWithUse


   Bases: :py:obj:`Protocol`

   Base class for protocol classes.

   Protocol classes are defined as::

       class Proto(Protocol):
           def meth(self) -> int:
               ...

   Such classes are primarily used with static type checkers that recognize
   structural subtyping (static duck-typing), for example::

       class C:
           def meth(self) -> int:
               return 0

       def func(x: Proto) -> int:
           return x.meth()

       func(C())  # Passes static type check

   See PEP 544 for details. Protocol classes decorated with
   @typing.runtime_checkable act as simple-minded runtime protocols that check
   only the presence of given attributes, ignoring their type signatures.
   Protocol classes can be generic, they are defined as::

       class GenProto(Protocol[T]):
           def meth(self) -> T:
               ...

   .. py:property:: use
      :type: list[int]



.. py:data:: uU
   :value: 0

   

.. py:data:: uN
   :value: 1

   

.. py:data:: uI
   :value: 2

   

.. py:data:: uO
   :value: 3

   

.. py:data:: uB
   :value: 4

   

.. py:data:: uP
   :value: 5

   

.. py:data:: invertuse
   :value: [0, 1, 3, 2, 4, 5]

   

.. py:data:: usedict

   

.. py:data:: Equiv

   

.. py:class:: FGlueList(glues: alhambra.glues.GlueList[alhambra.glues.Glue])


   .. py:method:: blankequiv() -> Equiv


   .. py:method:: iseq(equiv: Equiv, a: int, b: int) -> bool


   .. py:method:: domerge(equiv: Equiv, a: int, b: int, preserveuse: bool = False) -> Equiv



.. py:class:: FTileList(tiles: alhambra.tiles.TileList[alhambra.tiles.Tile], gluelist: FGlueList)


   .. py:attribute:: stiles
      :type: FTilesArray

      

   .. py:attribute:: htiles
      :type: FTilesArray

      

   .. py:attribute:: vtiles
      :type: FTilesArray

      


.. py:data:: RSEL
   :value: (2, 3, 0, 1)

   

.. py:data:: FTI
   :value: (1, 0, 1, 0)

   

.. py:data:: FTS
   :value: ()

   

.. py:function:: _fdg(dir, gs1, gs2)


.. py:function:: _ffakedouble_n(tn: int, sta, gluelist: FGlueList, outputonly: bool = True, *, dir4: Literal[True], equiv=None) -> tuple[list[FTile], list[FTile], list[FTile], list[FTile]]
                 _ffakedouble_n(tn: int, sta, gluelist: FGlueList, outputonly: bool = True, *, dir4: Literal[False] = False, equiv=None) -> tuple[list[FTile], list[FTile]]


.. py:data:: HSEL
   :value: ((1, 0, 5, 6), (2, 3, 4, 0))

   

.. py:data:: VSEL
   :value: ((1, 2, 0, 6), (0, 3, 4, 5))

   

.. py:function:: _ffakesingle(ftile: FTile, gluelist: FGlueList) -> Sequence[FTile]


.. py:class:: _FastTileSet(tilesystem: alhambra.tilesets.TileSet)


   .. py:attribute:: gluelist
      :type: FGlueList

      

   .. py:attribute:: tilelist
      :type: FTileList

      

   .. py:method:: applyequiv(ts: alhambra.tilesets.TileSet, equiv) -> alhambra.tilesets.TileSet


   .. py:method:: togluemergespec(ts, equiv)



.. py:function:: ptins(fts: _FastTileSet, equiv: Equiv | None = None, tau=2) -> list[list[numpy.ndarray[Any, numpy.dtype[numpy.int64]]]]

   Calculate potential tile attachments to input neighborhoods


.. py:function:: gmatch(fts, g1, g2, equiv=None)


.. py:function:: gcomp(fts, g1, g2, equiv=None)


.. py:function:: findmovetiles(fts, tilei, direction, allin, allout)


.. py:function:: _2go_moveandfill(fts: _FastTileSet, t: int, i: int, allin=True, allout=True, pdir=None, x=0, y=0, old_d=None) -> TMap


.. py:function:: _2go_findtrialmoves(fts: _FastTileSet, tilei, direction, equiv=None)


.. py:data:: directions
   :value: [(0,), (1, 0), (0, 1), ()]

   

.. py:function:: _2go_checkandmove(fts, ct, x, y, i, tmap: TMap, exclude=tuple(), equiv=None)


.. py:function:: is_2go_nn(fts: _FastTileSet, tn: int, un: int, equiv: numpy.ndarray[Any, numpy.dtype[numpy.int64]], tau: int = 2, tmaps: dict[int, TMap] | None = None, *, retall: Literal[True], also22go: bool = False) -> tuple[bool, tuple[Any, Any] | None]
                 is_2go_nn(fts: _FastTileSet, tn: int, un: int, equiv: numpy.ndarray[Any, numpy.dtype[numpy.int64]], tau: int = 2, tmaps: dict[int, TMap] | None = None, *, retall: Literal[False] = False, also22go: bool = False) -> bool


.. py:function:: gen_2go_maps(fts: _FastTileSet) -> dict[int, TMap]


.. py:function:: gen_2go_profile(fts: _FastTileSet, equiv=None, tmaps=None, also22go: bool = False)


.. py:function:: is_2go_equiv(fts: _FastTileSet, equiv: Equiv | None = None, tmaps=None, origsens=None)


.. py:function:: is_22go_equiv(fts, equiv=None, ins2go=None, orig22go=None)


.. py:function:: fta_to_ft(stiles, un, sel=None)


.. py:function:: isatamequiv(fts, equiv, initptins=None)


.. py:function:: tilemerge(fts, equiv, t1, t2, preserveuse=False)


.. py:function:: _findpotentialtilemerges(fts, equiv)


.. py:function:: _findpotentialgluemerges(fts, equiv)


.. py:function:: _recfix(fts, equiv, tp, initptins, check2go=False, tmaps=None, orig2go=None, orig22go=None, check22go=False, checkld=False, chain=None, preserveuse=False)


.. py:function:: _tilereduce(fts, equiv=None, check2go=False, initptins=None, check22go=False, checkld=False, preserveuse=False)


.. py:function:: _gluereduce(fts: _FastTileSet, equiv: Equiv | None = None, check2go: bool = False, check22go: bool = False, checkld: bool = False, initptins=None, preserveuse: bool = False)


.. py:function:: _single_reduce_tiles(p)


.. py:function:: _single_reduce_ends(p)


.. py:function:: reduce_tiles(tileset, preserve=('s22', 'ld'), tries=10, threads=1, returntype='equiv', best=1, key=None, initequiv=None)

   Apply tile reduction algorithm, preserving some set of properties, and using a multiprocessing pool.

   :param tileset: The system to reduce.
   :type tileset: TileSet
   :param preserve: The properties to preserve.  Currently supported are 's1' for first order
                    sensitivity, 's2' for second order sensitivity, 's22' for two-by-two sensitivity,
                    'ld' for small lattice defects, and 'gs' for glue sense (to avoid spurious
                    hierarchical attachment).  Default is currently ('s22', 'ld').
   :type preserve: a tuple or list of strings, optional
   :param tries: The number of times to run the algorithm.
   :type tries: int, optional
   :param threads: The number of threads to use (using multiprocessing).
   :type threads: int, optional
   :param returntype: The type of object to return.  If 'equiv', returns an array of glue equivalences
                      (or list, if best != 1) that can be applied to the tileset with apply_equiv, or used
                      for further reduction.  If 'TileSet', return a TileSet with the equiv already applied
                      (or a list, if best != 1).
   :type returntype: 'TileSet' or 'equiv' (default 'equiv')
   :param best: The number of systems to return.  If 1, the result will be returned
                directly; if k > 1, a list will be returned of the best k results (per cmp);
                if k = None, a list of *all* results will be returned, sorted by cmp. (default 1)
   :type best: int or None, optional
   :param key: A comparison function for equivs, to sort the results. FIXME: documentation needed.
               Default (if None) here is to sort by number of glues in the system, regardless of number
               of tiles.
   :type key: function (ts, equiv1, equiv2) -> some number/comparable
   :param initequiv: If provided, the equivalence array to start from.  If None, start from the tileset without
                     any merged glues.
   :type initequiv: equiv

   :returns: **reduced** -- The reduced system/systems
   :rtype: single TileSet


.. py:function:: reduce_ends(tileset, preserve=('s22', 'ld'), tries=10, threads=1, returntype='equiv', best=1, key=None, initequiv=None)

   Apply end reduction algorithm, preserving some set of properties, and using a multiprocessing pool.

   :param tileset: The system to reduce.
   :type tileset: TileSet
   :param preserve: The properties to preserve.  Currently supported are 's1' for first order
                    sensitivity, 's2' for second order sensitivity, 's22' for two-by-two sensitivity,
                    'ld' for small lattice defects, and 'gs' for glue sense (to avoid spurious
                    hierarchical attachment).  Default is currently ('s22', 'ld').
   :type preserve: a tuple or list of strings, optional
   :param tries: The number of times to run the algorithm.
   :type tries: int, optional
   :param threads: The number of threads to use (using multiprocessing).
   :type threads: int, optional
   :param returntype: The type of object to return.  If 'equiv', returns an array of glue equivalences
                      (or list, if best != 1) that can be applied to the tileset with apply_equiv, or used
                      for further reduction.  If 'TileSet', return a TileSet with the equiv already applied
                      (or a list, if best != 1).
   :type returntype: 'TileSet' or 'equiv' (default 'equiv')
   :param best: The number of systems to return.  If 1, the result will be returned
                directly; if k > 1, a list will be returned of the best k results (per cmp);
                if k = None, a list of *all* results will be returned, sorted by cmp. (default 1)
   :type best: int or None, optional
   :param key: A comparison function for equivs, to sort the results. FIXME: documentation needed.
               Default (if None) here is to sort by number of glues in the system, regardless of number
               of tiles.
   :type key: function (ts, equiv1, equiv2) -> some number/comparable
   :param initequiv: If provided, the equivalence array to start from.  If None, start from the tileset without
                     any merged glues.
   :type initequiv: equiv

   :returns: **reduced** -- The reduced system/systems
   :rtype: single TileSet


