From 1e396765e290e08e93ce04ef21fbe312a65c2f8e Mon Sep 17 00:00:00 2001
From: Martin Reinecke <martin@mpa-garching.mpg.de>
Date: Mon, 21 Jan 2019 13:40:36 +0100
Subject: [PATCH] allow explicit specification of codomains

---
 nifty5/library/correlated_fields.py | 8 ++++++--
 nifty5/operators/qht_operator.py    | 9 ++++++---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/nifty5/library/correlated_fields.py b/nifty5/library/correlated_fields.py
index 4ceaf902e..15f4e7cdd 100644
--- a/nifty5/library/correlated_fields.py
+++ b/nifty5/library/correlated_fields.py
@@ -24,7 +24,7 @@ from ..operators.harmonic_operators import HarmonicTransformOperator
 from ..operators.simple_linear_operators import ducktape
 
 
-def CorrelatedField(target, amplitude_operator, name='xi'):
+def CorrelatedField(target, amplitude_operator, name='xi', codomain=None):
     """Constructs an operator which turns a white Gaussian excitation field
     into a correlated field.
 
@@ -42,6 +42,8 @@ def CorrelatedField(target, amplitude_operator, name='xi'):
     amplitude_operator: Operator
     name : string
         :class:`MultiField` key for the xi-field.
+    codomain : Domain
+        The codomain for target[0]. If not supplied, it is inferred.
 
     Returns
     -------
@@ -50,7 +52,9 @@ def CorrelatedField(target, amplitude_operator, name='xi'):
     tgt = DomainTuple.make(target)
     if len(tgt) > 1:
         raise ValueError
-    h_space = tgt[0].get_default_codomain()
+    if codomain is None:
+        codomain = tgt[0].get_default_codomain()
+    h_space = codomain
     ht = HarmonicTransformOperator(h_space, tgt[0])
     p_space = amplitude_operator.target[0]
     power_distributor = PowerDistributor(h_space, p_space)
diff --git a/nifty5/operators/qht_operator.py b/nifty5/operators/qht_operator.py
index ec858d623..ac8f5b52c 100644
--- a/nifty5/operators/qht_operator.py
+++ b/nifty5/operators/qht_operator.py
@@ -37,9 +37,11 @@ class QHTOperator(LinearOperator):
     space : int
         The index of the domain on which the operator acts.
         target[space] must be a non-harmonic LogRGSpace.
+    codomain : Domain
+        The codomain for target[space]. If not supplied, it is inferred.
     """
 
-    def __init__(self, target, space=0):
+    def __init__(self, target, space=0, codomain=None):
         self._target = DomainTuple.make(target)
         self._space = infer_space(self._target, space)
 
@@ -51,8 +53,9 @@ class QHTOperator(LinearOperator):
             raise TypeError("target[space] must be a nonharmonic space")
 
         self._domain = [dom for dom in self._target]
-        self._domain[self._space] = \
-            self._target[self._space].get_default_codomain()
+        if codomain is None:
+            codomain = self._target[self._space].get_default_codomain()
+        self._domain[self._space] = codomain
         self._domain = DomainTuple.make(self._domain)
         self._capability = self.TIMES | self.ADJOINT_TIMES
 
-- 
GitLab