Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ift
NIFTy
Commits
d843e7d1
Commit
d843e7d1
authored
May 16, 2020
by
Martin Reinecke
Browse files
Merge branch 'nifty6_multi_domain_keys' into 'NIFTy_6'
Highlight that keys in a multi-domain are sorted See merge request
!465
parents
83cc5351
d9e5b5ba
Pipeline
#75055
passed with stages
in 25 minutes and 11 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nifty6/multi_domain.py
View file @
d843e7d1
...
...
@@ -22,9 +22,18 @@ from .utilities import frozendict, indent
class
MultiDomain
(
object
):
"""A tuple of domains corresponding to a direct sum.
This class is the domain of the direct sum of fields defined
on (possibly different) domains. To make an instance
of this class, call `MultiDomain.make(inp)`.
This class is the domain of the direct sum of fields defined on (possibly
different) domains. To make an instance of this class, call
`MultiDomain.make(inp)`.
Notes
-----
For consistency and to be independent of the order of insertion, the keys
within a multi-domain are sorted. Hence, renaming a domain may result in it
being placed at a different index within a multi-domain. This is especially
important if a sequence of, e.g., random numbers is distributed sequentially
over a multi-domain. In this example, ordering keys differently will change
the resulting :class:`MultiField`.
"""
_domainCache
=
{}
...
...
nifty6/multi_field.py
View file @
d843e7d1
...
...
@@ -102,6 +102,29 @@ class MultiField(Operator):
@
staticmethod
def
from_random
(
random_type
,
domain
,
dtype
=
np
.
float64
,
**
kwargs
):
"""Draws a random multi-field with the given parameters.
Parameters
----------
random_type : 'pm1', 'normal', or 'uniform'
The random distribution to use.
domain : DomainTuple
The domain of the output random Field.
dtype : type
The datatype of the output random Field.
Returns
-------
MultiField
The newly created :class:`MultiField`.
Notes
-----
The individual fields within this multi-field will be drawn in alphabetical
order of the multi-field's domain keys. As a consequence, renaming these
keys may cause the multi-field to be filled with different random numbers,
even for the same initial RNG state.
"""
domain
=
MultiDomain
.
make
(
domain
)
if
isinstance
(
dtype
,
dict
):
dtype
=
{
kk
:
np
.
dtype
(
dt
)
for
kk
,
dt
in
dtype
.
items
()}
...
...
nifty6/sugar.py
View file @
d843e7d1
...
...
@@ -274,6 +274,13 @@ def from_random(random_type, domain, dtype=np.float64, **kwargs):
-------
Field or MultiField
The newly created random field
Notes
-----
When called with a multi-domain, the individual fields will be drawn in
alphabetical order of the multi-domain's domain keys. As a consequence,
renaming these keys may cause the multi-field to be filled with different
random numbers, even for the same initial RNG state.
"""
if
isinstance
(
domain
,
(
dict
,
MultiDomain
)):
return
MultiField
.
from_random
(
random_type
,
domain
,
dtype
,
**
kwargs
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment