Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
nskeip committed Apr 29, 2022
2 parents b22e5d7 + 4d07703 commit 37f3089
Show file tree
Hide file tree
Showing 37 changed files with 955 additions and 350 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ dmypy.json

# Cython debug symbols
cython_debug/

*.ipynb
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ Running tests
The whole project is covered with unit-tests, except for gui.
Use `tests/run_all_tests.py` to run them all.

Or you can use `pytest` and run `python -m pytest` or just `py.test` from `src/`.


Using as a library
------------------

To install the program as a python package, run `pip install` after
cloning the repository:
```shell
pip install /path/to/calculations
```
23 changes: 23 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from setuptools import setup

setup(
name='calculations',
version='2.0.0',
packages=[
'spectrum',
'spectrum.gui',
'spectrum.gui.graph',
'spectrum.graph',
'spectrum.tools',
'spectrum.modules',
'spectrum.calculations',
'spectrum.calculations.spectra'
],
package_dir={'': 'src'},
url='https://github.com/nskeip/calculations',
license='Apache 2',
author='Daniel Lytkin',
maintainer='Nikita Hismatov',
maintainer_email='me@ns-keip.ru',
description=''
)
1 change: 1 addition & 0 deletions src/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# created to force py.test to make src/ the root dir
22 changes: 12 additions & 10 deletions src/spectrum/calculations/graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
__author__ = 'Daniel Lytkin'


class PrimeGraph(Graph):
class __metaclass__(type):
"""Provide a metaclass in order to override class-level str method"""
def __str__(self):
return 'Prime Graph'
class PrimeGraphMeta(type):
"""Provide a metaclass in order to override class-level str method"""
def __str__(self):
return 'Prime Graph'


class PrimeGraph(Graph, metaclass=PrimeGraphMeta):
def __init__(self, group):
Graph.__init__(self)
apex = group.apex()
Expand All @@ -38,12 +39,13 @@ def __init__(self, group):
self.add_edges(itertools.combinations(factors, 2))


class FastGraph(Graph):
class __metaclass__(type):
"""Provide a metaclass in order to override class-level str method"""
def __str__(self):
return 'Fast Graph'
class FastGraphMeta(type):
"""Provide a metaclass in order to override class-level str method"""
def __str__(self):
return 'Fast Graph'


class FastGraph(Graph, metaclass=FastGraphMeta):
def __init__(self, group):
Graph.__init__(self)
apex = group.apex()
Expand Down
26 changes: 19 additions & 7 deletions src/spectrum/calculations/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
limitations under the License.
"""
from partition import Partitions
from functools import reduce

from spectrum.calculations import orders, spectra, numeric
from spectrum.calculations.numeric import Constraints, Integer
from spectrum.tools.tools import doc_inherit, ObjectCache

from .partition import Partitions

__author__ = 'Daniel Lytkin'

Expand All @@ -28,7 +29,7 @@
#LATEX_OPERATORNAME = True


class Field(object):
class Field:
"""Finite field.
Can be created as Field(order) or Field(base, pow) where base**pow is the
order of the field. `order' must be a prime power, otherwise the wrong
Expand Down Expand Up @@ -70,7 +71,7 @@ def __str__(self):
return "F({}^{})".format(self._base, self._pow)


class Group(object):
class Group:
"""Abstract class for finite groups.
"""

Expand Down Expand Up @@ -151,7 +152,7 @@ def degree(self):
def apex(self):
if self._apex is None:
n = self._degree
partitions = filter(lambda x: (len(x) + n) % 2 == 0, Partitions(n))
partitions = [x for x in Partitions(n) if (len(x) + n) % 2 == 0]
self._apex = numeric.sort_and_filter(
[reduce(numeric.lcm, partition) for partition in partitions])
return self._apex
Expand All @@ -160,7 +161,7 @@ def apex(self):
def order(self):
if self._order is None:
# n!/2
self._order = numeric.prod(xrange(3, self._degree + 1))
self._order = numeric.prod(range(3, self._degree + 1))
return Integer(self._order)

def __str__(self):
Expand Down Expand Up @@ -278,6 +279,13 @@ class ExceptionalGroup(Group):
"F4": 'F_4', "2F4": '{}^2F_4', "G2": 'G_2', "2G2": '{}^2G_2',
"2B2": '{}^2B_2', "3D4": '{}^3D_4'}

# constraints for field order
_field_constraints = {
'2F4': Constraints(min=2, primality=numeric.ODD_POWER_OF_2),
'2B2': Constraints(min=2, primality=numeric.ODD_POWER_OF_2),
'2G2': Constraints(min=2, primality=numeric.ODD_POWER_OF_3),
}

def __init__(self, name, *field):
super(ExceptionalGroup, self).__init__()
self._name = name
Expand Down Expand Up @@ -315,4 +323,8 @@ def order(self):
func = orders.exceptional_orders.get(self._name,
lambda *arg: Integer())
self._order = func(self._field)
return self._order
return self._order

@classmethod
def field_constraints(cls, name):
return cls._field_constraints.get(name, Constraints(min=2, primality=numeric.PRIME_POWER))
Loading

0 comments on commit 37f3089

Please sign in to comment.