Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
NIFTy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ift
NIFTy
Commits
7494f51c
Commit
7494f51c
authored
6 years ago
by
Martin Reinecke
Browse files
Options
Downloads
Patches
Plain Diff
more docs
parent
215f2d90
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
nifty5/sugar.py
+75
-0
75 additions, 0 deletions
nifty5/sugar.py
with
75 additions
and
0 deletions
nifty5/sugar.py
+
75
−
0
View file @
7494f51c
...
...
@@ -214,30 +214,105 @@ def create_harmonic_smoothing_operator(domain, space, sigma):
def
full
(
domain
,
val
):
"""
Convenience function creating Fields/MultiFields with uniform values.
Parameters
----------
domain : Domainoid
the intended domain of the output field
val : scalar value
the uniform value to be placed into all entries of the result
Returns
-------
Field / MultiField : the newly created uniform field
"""
if
isinstance
(
domain
,
(
dict
,
MultiDomain
)):
return
MultiField
.
full
(
domain
,
val
)
return
Field
.
full
(
domain
,
val
)
def
from_random
(
random_type
,
domain
,
dtype
=
np
.
float64
,
**
kwargs
):
"""
Convenience function creating Fields/MultiFields with random values.
Parameters
----------
random_type :
'
pm1
'
,
'
normal
'
, or
'
uniform
'
The random distribution to use.
domain : Domainoid
the intended domain of the output field
dtype : type
data type of the output field (e.g. numpy.float64)
**kwargs : additional parameters for the random distribution
(
'
mean
'
and
'
std
'
for
'
normal
'
,
'
low
'
and
'
high
'
for
'
uniform
'
)
Returns
-------
Field / MultiField : the newly created random field
"""
if
isinstance
(
domain
,
(
dict
,
MultiDomain
)):
return
MultiField
.
from_random
(
random_type
,
domain
,
dtype
,
**
kwargs
)
return
Field
.
from_random
(
random_type
,
domain
,
dtype
,
**
kwargs
)
def
from_global_data
(
domain
,
arr
,
sum_up
=
False
):
"""
Convenience function creating Fields/MultiFields from Numpy arrays or
dicts of Numpy arrays.
Parameters
----------
domain : Domainoid
the intended domain of the output field
arr : Numpy array if `domain` corresponds to a `DomainTuple`,
dictionary of Numpy arrays if `domain` corresponds to a `MultiDomain`
sum_up : bool
Only meaningful if MPI is enabled
If `True`, the contents of the arrays on all tasks are added together,
otherwise it is assumed that the array on each task holds the correct
field values.
Returns
-------
Field / MultiField : the newly created random field
"""
if
isinstance
(
domain
,
(
dict
,
MultiDomain
)):
return
MultiField
.
from_global_data
(
domain
,
arr
,
sum_up
)
return
Field
.
from_global_data
(
domain
,
arr
,
sum_up
)
def
from_local_data
(
domain
,
arr
):
"""
Convenience function creating Fields/MultiFields from Numpy arrays or
dicts of Numpy arrays.
Parameters
----------
domain : Domainoid
the intended domain of the output field
arr : Numpy array if `domain` corresponds to a `DomainTuple`,
dictionary of Numpy arrays if `domain` corresponds to a `MultiDomain`
Returns
-------
Field / MultiField : the newly created field
"""
if
isinstance
(
domain
,
(
dict
,
MultiDomain
)):
return
MultiField
.
from_local_data
(
domain
,
arr
)
return
Field
.
from_local_data
(
domain
,
arr
)
def
makeDomain
(
domain
):
"""
Convenience function creating DomainTuples/MultiDomains Domainoids.
Parameters
----------
domain : Domainoid (can be DomainTuple, MultiDomain, dict, Domain or
list of Domains)
the description of the requested (multi-)domain
Returns
-------
DomainTuple / MultiDomain : the newly created domain object
"""
if
isinstance
(
domain
,
(
MultiDomain
,
dict
)):
return
MultiDomain
.
make
(
domain
)
return
DomainTuple
.
make
(
domain
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment