Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions abelian/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,17 +754,6 @@ def _fft_wrapper(self, func_to_wrap = 'fftn', func_type = ''):
"""
Common wrapper for FFT and IFFT routines.

The numpy DFT is defined as:
:math:`A_{kl} = \sum_{m=0}^{M-1} \sum_{n=0}^{N-1}
a_{mn}\exp\left\{-2\pi i \left({mk\over M}+{nl\over N}\right)\right\}
\qquad k = 0, \ldots, M-1;\quad l = 0, \ldots, N-1.`

And the inverse DFT is defined as:
:math:`a_{mn} = \frac{1}{MN} \sum_{k=0}^{M-1} \sum_{l=0}^{N-1}
A_{kl}\exp\left\{2\pi i \left({mk\over M}+{nl\over N}\right)\right\}
\qquad m = 0, \ldots, M-1;\quad n = 0, \ldots, N-1.`


Parameters
----------
func_to_wrap : str
Expand Down Expand Up @@ -897,4 +886,4 @@ def sigma(x):

if __name__ == "__main__":
import doctest
doctest.testmod(verbose = False)
doctest.testmod(verbose = False)
12 changes: 6 additions & 6 deletions abelian/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def __init__(self, orders, discrete = None):
orders and whether or not they are discrete. An order of 0 means
infinite order. The possible groups are:

* :math:`\mathbb{Z}_n` : order = `n`, discrete = `True`
* :math:`\mathbb{Z}` : order = `0`, discrete = `True`
* :math:`Z_n` : order = `n`, discrete = `True`
* :math:`Z` : order = `0`, discrete = `True`
* :math:`T` : order = `1`, discrete = `False`
* :math:`\mathbb{R}` : order = `0`, discrete = `False`
* :math:`R` : order = `0`, discrete = `False`

Every locally compact abelian group is isomorphic to a direct sum
or one or several of the groups above.
Expand Down Expand Up @@ -813,7 +813,7 @@ def sum(self, other):

def to_latex(self):
"""
Return the LCA as a :math:`\LaTeX` string.
Return the LCA as a :math:`LaTeX` string.

Returns
-------
Expand All @@ -824,12 +824,12 @@ def to_latex(self):
---------
>>> G = LCA([5, 0], [True, False])
>>> G.to_latex()
'\\\mathbb{Z}_{5} \\\oplus \\\mathbb{R}'
'Z_{5} oplus R'
"""
def repr_single(p, d):
if p == 0:
if d:
return r'\mathbb{Z}'
return r'Z'
return r'\mathbb{R}'
if d:
return r'\mathbb{Z}_{' + str(p) + '}'
Expand Down
24 changes: 11 additions & 13 deletions abelian/linalg/free_to_free.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,11 @@ def free_kernel(A):
"""
Computes the free-to-free kernel monomorphism of A.

Let :math:`A: \mathbb{Z}^n -> \mathbb{Z}^m` be a homomorphism from
Let :math:`A: Z^n -> Z^m` be a homomorphism from
a free (infinite order) finitely generated Abelian group (FGA) to another
free FGA. Associated with this homomorphism is the kernel monomorphism.
The kernel monomorphism has the property that
:math:`A \circ \operatorname{ker}(A) = \mathbf{0}`, where :math:`\mathbf{0}`
denotes the zero morphism.
:math:`A * ker(A) = 0`, where `0` denotes the zero morphism.

Parameters
----------
Expand Down Expand Up @@ -270,12 +269,11 @@ def free_cokernel(A):
"""
Computes the free-to-free cokernel epimorphism of A.

Let :math:`A: \mathbb{Z}^n -> \mathbb{Z}^m` be a homomorphism from
Let :math:`A: Z^n -> Z^m` be a homomorphism from
a free (infinite order) finitely generated Abelian group (FGA) to another
free FGA. Associated with this homomorphism is the cokernel epimorphism.
The cokernel epimorphism has the property that
:math:`\operatorname{coker}(A) \circ A = \mathbf{0}`, where
:math:`\mathbf{0}` denotes the zero morphism.
:math:`coker(A) * A = 0`, where :math:`0` denotes the zero morphism.

Parameters
----------
Expand Down Expand Up @@ -310,12 +308,12 @@ def free_image(A):
"""
Computes the free-to-free image monomorphism of A.

Let :math:`A: \mathbb{Z}^n -> \mathbb{Z}^m` be a homomorphism from
Let :math:`A: Z^^ -> Z^m` be a homomorphism from
a free (infinite order) finitely generated Abelian group (FGA) to another
free FGA. Associated with this homomorphism is the image monomorphism.
The image monomorphism has the property that :math:`A` factors through
the composition of the coimage and image morphisms, i.e.
:math:`\operatorname{im}(A) \circ \operatorname{coim}(A) = A`.
:math:`im(A) * coim(A) = A`.

Parameters
----------
Expand Down Expand Up @@ -348,12 +346,12 @@ def free_coimage(A):
"""
Computes the free-to-free coimage epimorphism of A.

Let :math:`A: \mathbb{Z}^n -> \mathbb{Z}^m` be a homomorphism from
Let :math:`A: Z^n -> Z^m` be a homomorphism from
a free (infinite order) finitely generated Abelian group (FGA) to another
free FGA. Associated with this homomorphism is the coimage epimorphism.
The coimage epimorphism has the property that :math:`A` factors through
the composition of the coimage and image morphisms, i.e.
:math:`\operatorname{im}(A) \circ \operatorname{coim}(A) = A`.
:math:`im(A) * coim(A) = A`.

Parameters
----------
Expand Down Expand Up @@ -387,11 +385,11 @@ def free_quotient(A):
"""
Compute the quotient group Z^m / im(A).

Let :math:`A: \mathbb{Z}^n -> \mathbb{Z}^m` be a homomorphism from
Let :math:`A: Z^n -> Z^m` be a homomorphism from
a free (infinite order) finitely generated Abelian group (FGA) to another
free FGA. Associated with this homomorphism is the cokernel epimorphism,
which maps from :math:`A: \mathbb{Z}^n` to
:math:`A: \mathbb{Z}^m / \operatorname{im}(A)`.
which maps from :math:`A: Z^n` to
:math:`A: Z^m / im(A)`.

Parameters
----------
Expand Down
4 changes: 2 additions & 2 deletions abelian/morphisms.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def _is_homFGA(self):

def to_latex(self):
"""
Return the homomorphism as a :math:`\LaTeX` string.
Return the homomorphism as a :math:`LaTeX` string.

Returns
-------
Expand All @@ -887,7 +887,7 @@ def to_latex(self):
--------
>>> phi = HomLCA([1])
>>> phi.to_latex()
'\\\\begin{pmatrix}1\\\\end{pmatrix}:\\\\mathbb{Z} \\\\to \\\\mathbb{Z}'
'pmatrix1->pmatrix:Z -> Z'
"""
latex_code = latex(self.A)
latex_code = latex_code.replace(r'\left[\begin{matrix}',
Expand Down
41 changes: 37 additions & 4 deletions abelian/utils.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import itertools
import functools
import itertools
import random
import types

import numpy as np
from sympy import Integer, Float, Rational


def mod(a, b):
Expand Down Expand Up @@ -183,9 +186,39 @@ def copy_func(f):
return g


argmin = functools.partial(arg, min_or_max = min)
argmax = functools.partial(arg, min_or_max = max)
argmin = functools.partial(arg, min_or_max=min)
argmax = functools.partial(arg, min_or_max=max)


def close(a, b):
numeric_types = (float, int, complex, Integer, Float, Rational)
if isinstance(a, numeric_types) and isinstance(a, numeric_types):
return abs(a - b) < 10e-10
return sum(abs(i - j) for (i, j) in zip(a, b))


def random_zero_heavy(low, high):
"""
Draw a random number, with approx 50% probability of zero.
"""
return random.choice(list(range(low, high)) + [0] * (high - low))


def frob_norm(A, B):
"""
Frobenius norm.
"""
return sum(abs(i - j) for (i, j) in zip(A, B))


def random_from_list(number, list_to_take_from):
"""
Draw several random values from the same list.
"""
return [random.choice(list_to_take_from) for i in range(number)]


if __name__ == "__main__":
import doctest
doctest.testmod(verbose = True)

doctest.testmod(verbose=True)
Empty file added tests/__init__.py
Empty file.
Loading