Skip to content
Merged
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
11 changes: 5 additions & 6 deletions brahmap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

from . import base, _extensions, core, utilities, math # noqa: E402

from .base import TypeChangeWarning, LowerTypeCastWarning, ShapeError # noqa: E402

from .core import ( # noqa: E402
SolverType,
ProcessTimeSamples,
Expand All @@ -43,10 +45,7 @@
)

from .utilities import ( # noqa: E402
TypeChangeWarning,
LowerTypeCastWarning,
modify_numpy_context,
ShapeError,
)

if find_spec("litebird_sim") is not None:
Expand Down Expand Up @@ -80,6 +79,9 @@
"MPI_RAISE_EXCEPTION",
# ./base/
"base",
"TypeChangeWarning",
"LowerTypeCastWarning",
"ShapeError",
# ./_extensions/
"_extensions",
# ./core/
Expand All @@ -103,10 +105,7 @@
"compute_GLS_maps",
# ./utilities/
"utilities",
"TypeChangeWarning",
"LowerTypeCastWarning",
"modify_numpy_context",
"ShapeError",
# ./math/
"math",
]
Expand Down
19 changes: 19 additions & 0 deletions brahmap/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Original code:
#
# Copyright (c) 2008-2013, Dominique Orban <dominique.orban@gerad.ca>
# All rights reserved.
#
Expand Down Expand Up @@ -27,6 +29,18 @@
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# Modified version:
#
# Copyright (c) 2023-present, Avinash Anand <avinash.anand@roma2.infn.it>
# and Giuseppe Puglisi
#
# This file is part of BrahMap.
#
# Licensed under the MIT License. See the <LICENSE.txt> file for details.

from .misc import TypeChangeWarning, LowerTypeCastWarning, filter_warnings, ShapeError

from .linop import (
BaseLinearOperator,
Expand Down Expand Up @@ -59,6 +73,11 @@
)

__all__ = [
# misc.py
"TypeChangeWarning",
"LowerTypeCastWarning",
"filter_warnings",
"ShapeError",
# linop.py
"BaseLinearOperator",
"LinearOperator",
Expand Down
73 changes: 66 additions & 7 deletions brahmap/base/blkop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Original code:
#
# Copyright (c) 2008-2013, Dominique Orban <dominique.orban@gerad.ca>
# All rights reserved.
#
Expand Down Expand Up @@ -27,16 +29,26 @@
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# Modified version:
#
# Copyright (c) 2023-present, Avinash Anand <avinash.anand@roma2.infn.it>
# and Giuseppe Puglisi
#
# This file is part of BrahMap.
#
# Licensed under the MIT License. See the <LICENSE.txt> file for details.

import numpy as np
import itertools
import warnings
from typing import List
from typing import List, Any
from functools import reduce, partial

from ..base import BaseLinearOperator, LinearOperator
from ..base import null_log
from ..utilities import ShapeError, TypeChangeWarning
from .misc import ShapeError, TypeChangeWarning
from ..mpi import MPI_RAISE_EXCEPTION

from brahmap import MPI_UTILS
Expand All @@ -54,9 +66,22 @@ class BlockLinearOperator(LinearOperator):
need be specified, e.g., `[[A,B,C], [D,E], [F]]`, and the blocks on the
diagonal must be square and symmetric.

Parameters
----------
blocks : List[LinearOperator]
_description_
symmetric : bool, optional
_description_, by default False
**kwargs: Any
_description_
"""

def __init__(self, blocks, symmetric=False, **kwargs):
def __init__(
self,
blocks: List[LinearOperator],
symmetric: bool = False,
**kwargs: Any,
):
# If building a symmetric operator, fill in the blanks.
# They're just references to existing objects.
try:
Expand Down Expand Up @@ -176,15 +201,29 @@ def __iter__(self):


class BlockDiagonalLinearOperator(LinearOperator):
def __init__(self, block_list, **kwargs):
"""Base class for a block-diagonal linear operator

Parameters
----------
block_list : List[LinearOperator]
_description_
**kwargs: Any
_description_
"""

def __init__(
self,
block_list: List[LinearOperator],
**kwargs: Any,
):
try:
for block in block_list:
__, __ = block.shape
except (TypeError, AttributeError):
MPI_RAISE_EXCEPTION(
condition=True,
exception=ValueError,
message="The `block_list` must be a flat list of linear" "operators",
message="The `block_list` must be a flat list of linearoperators",
)

self.__row_size = np.asarray(
Expand Down Expand Up @@ -317,9 +356,19 @@ class BlockHorizontalLinearOperator(BlockLinearOperator):
Each block must be a linear operator.
The blocks must be specified as one list, e.g., `[A, B, C]`.

Parameters
----------
blocks : List[LinearOperator]
_description_
**kwargs: Any
_description_
"""

def __init__(self, blocks, **kwargs):
def __init__(
self,
blocks: List[LinearOperator],
**kwargs: Any,
):
try:
for block in blocks:
__ = block.shape
Expand All @@ -340,9 +389,19 @@ class BlockVerticalLinearOperator(BlockLinearOperator):
Each block must be a linear operator.
The blocks must be specified as one list, e.g., `[A, B, C]`.

Parameters
----------
blocks : List[LinearOperator]
_description_
**kwargs: Any
_description_
"""

def __init__(self, blocks, **kwargs):
def __init__(
self,
blocks: List[LinearOperator],
**kwargs: Any,
):
try:
for block in blocks:
__ = block.shape
Expand Down
Loading
Loading