Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
On Thursday, 7th July from 1 to 3 pm there will be a maintenance with a short downtime of GitLab.
Open sidebar
ift
NIFTy
Commits
c6aa285b
Commit
c6aa285b
authored
Jan 11, 2018
by
Martin Reinecke
Browse files
Merge branch 'nifty2go' into fun_with_operators
parents
f3a3a97a
7c69cf19
Pipeline
#25253
passed with stage
in 9 minutes and 35 seconds
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
nifty/data_objects/random.py
View file @
c6aa285b
...
...
@@ -32,6 +32,16 @@ class Random(object):
@
staticmethod
def
normal
(
dtype
,
shape
,
mean
=
0.
,
std
=
1.
):
if
not
(
np
.
issubdtype
(
dtype
,
np
.
floating
)
or
np
.
issubdtype
(
dtype
,
np
.
complexfloating
)):
raise
TypeError
(
"dtype must be float or complex"
)
if
not
np
.
isscalar
(
mean
)
or
not
np
.
isscalar
(
std
):
raise
TypeError
(
"mean and std must be scalars"
)
if
np
.
issubdtype
(
type
(
std
),
np
.
complexfloating
):
raise
TypeError
(
"std must not be complex"
)
if
((
not
np
.
issubdtype
(
dtype
,
np
.
complexfloating
))
and
np
.
issubdtype
(
type
(
mean
),
np
.
complexfloating
)):
raise
TypeError
(
"mean must not be complex for a real result field"
)
if
np
.
issubdtype
(
dtype
,
np
.
complexfloating
):
x
=
np
.
empty
(
shape
,
dtype
=
dtype
)
x
.
real
=
np
.
random
.
normal
(
mean
.
real
,
std
*
np
.
sqrt
(
0.5
),
shape
)
...
...
@@ -42,12 +52,20 @@ class Random(object):
@
staticmethod
def
uniform
(
dtype
,
shape
,
low
=
0.
,
high
=
1.
):
if
not
np
.
isscalar
(
low
)
or
not
np
.
isscalar
(
high
):
raise
TypeError
(
"low and high must be scalars"
)
if
(
np
.
issubdtype
(
type
(
low
),
np
.
complexfloating
)
or
np
.
issubdtype
(
type
(
high
),
np
.
complexfloating
)):
raise
TypeError
(
"low and high must not be complex"
)
if
np
.
issubdtype
(
dtype
,
np
.
complexfloating
):
x
=
np
.
empty
(
shape
,
dtype
=
dtype
)
x
.
real
=
np
.
random
.
uniform
(
low
,
high
,
shape
)
x
.
imag
=
np
.
random
.
uniform
(
low
,
high
,
shape
)
elif
np
.
issubdtype
(
dtype
,
np
.
integer
):
x
=
np
.
random
.
random
.
randint
(
low
,
high
+
1
,
shape
)
if
not
(
np
.
issubdtype
(
type
(
low
),
np
.
integer
)
and
np
.
issubdtype
(
type
(
high
),
np
.
integer
)):
raise
TypeError
(
"low and high must be integer"
)
x
=
np
.
random
.
randint
(
low
,
high
+
1
,
shape
)
else
:
x
=
np
.
random
.
uniform
(
low
,
high
,
shape
)
return
x
.
astype
(
dtype
,
copy
=
False
)
nifty/field.py
View file @
c6aa285b
...
...
@@ -427,13 +427,19 @@ class Field(object):
return
self
.
_contraction_helper
(
'max'
,
spaces
)
def
mean
(
self
,
spaces
=
None
):
return
self
.
_contraction_helper
(
'mean'
,
spaces
)
if
self
.
scalar_weight
(
spaces
)
is
not
None
:
return
self
.
_contraction_helper
(
'mean'
,
spaces
)
raise
NotImplementedError
def
var
(
self
,
spaces
=
None
):
return
self
.
_contraction_helper
(
'var'
,
spaces
)
if
self
.
scalar_weight
(
spaces
)
is
not
None
:
return
self
.
_contraction_helper
(
'var'
,
spaces
)
raise
NotImplementedError
def
std
(
self
,
spaces
=
None
):
return
self
.
_contraction_helper
(
'std'
,
spaces
)
if
self
.
scalar_weight
(
spaces
)
is
not
None
:
return
self
.
_contraction_helper
(
'std'
,
spaces
)
return
sqrt
(
self
.
var
(
spaces
))
def
copy_content_from
(
self
,
other
):
if
not
isinstance
(
other
,
Field
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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