Skip to content

Commit

Permalink
Fixed CubicIntegerLattice super() init bug, renamed integer box sizes…
Browse files Browse the repository at this point in the history
… variable from "sidelens" to "counts_along_dims" to avoid confusion
  • Loading branch information
timbernat committed Apr 26, 2024
1 parent 2dd08ab commit ac6e9e2
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions polymerist/maths/lattices/integral.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,29 @@ def nearest_int_coord_along_normal(point : np.ndarray[Shape[N], Numeric], normal

class CubicIntegerLattice(Coordinates):
'''For representing an n-dimensional integer lattice, consisting of all n-tuples of integers with values constrained by side lengths in each dimension'''
def __init__(self, sidelens : np.ndarray[Shape[N], int]) -> None: # TODO: implement more flexible input support (i.e. star-unpacking, listlikes, etc.)
assert(sidelens.ndim == 1)
super().__init__(generate_int_lattice(*self.sidelens))
def __init__(self, counts_along_dims : np.ndarray[Shape[N], int]) -> None: # TODO: implement more flexible input support (i.e. star-unpacking, listlikes, etc.)
assert(counts_along_dims.ndim == 1)
super().__init__(generate_int_lattice(*counts_along_dims))
self.counts_along_dims = counts_along_dims

def sidelens_as_str(self, multip_char : str='x') -> str:
def counts_along_dims_as_str(self, multip_char : str='x') -> str:
'''Stringify the lattice sidelengths'''
return multip_char.join(str(i) for i in self.sidelens)
return multip_char.join(str(i) for i in self.counts_along_dims)

def __repr__(self) -> str:
return f'{self.__class__.__name__}({self.n_dims}-dimensional, {self.sidelens_as_str()})'
return f'{self.__class__.__name__}({self.n_dims}-dimensional, {self.counts_along_dims_as_str()})'

# LATTICE DIMENSIONS
@property
def capacity(self) -> int: # referred to as "M" in typehints
'''The maximum number of points that the lattice could contains'''
return np.prod(self.sidelens)
return np.prod(self.counts_along_dims)

@property
def lex_ordered_weights(self) -> np.ndarray[Shape[N], int]:
'''Vector of the number of points corresponding
Can be viewed as a linear transformation between indices and point coordinates when coords are placed in lexicographic order'''
return np.concatenate(([1], np.cumprod(self.sidelens)[:-1]))
return np.concatenate(([1], np.cumprod(self.counts_along_dims)[:-1]))

# SUBLATTICE DECOMPOSITION
@property
Expand Down

0 comments on commit ac6e9e2

Please sign in to comment.