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
47b6395f
Commit
47b6395f
authored
Dec 09, 2013
by
Marco Selig
Browse files
minor update due to feature request.
parent
8ae46d85
Changes
2
Show whitespace changes
Inline
Side-by-side
nifty_core.py
View file @
47b6395f
...
@@ -486,7 +486,7 @@ class _about(object): ## nifty support class for global settings
...
@@ -486,7 +486,7 @@ class _about(object): ## nifty support class for global settings
"""
"""
## version
## version
self
.
_version
=
"0.6.
7
"
self
.
_version
=
"0.6.
8
"
## switches and notifications
## switches and notifications
self
.
_errors
=
notification
(
default
=
True
,
ccode
=
notification
.
_code
)
self
.
_errors
=
notification
(
default
=
True
,
ccode
=
notification
.
_code
)
...
...
nifty_explicit.py
View file @
47b6395f
...
@@ -55,7 +55,7 @@ class explicit_operator(operator):
...
@@ -55,7 +55,7 @@ class explicit_operator(operator):
"""
"""
epsilon
=
1E-12
## absolute precision for comparisons to identity
epsilon
=
1E-12
## absolute precision for comparisons to identity
def
__init__
(
self
,
domain
,
matrix
,
bare
=
True
,
sym
=
None
,
uni
=
None
,
target
=
None
):
def
__init__
(
self
,
domain
,
matrix
=
None
,
bare
=
True
,
sym
=
None
,
uni
=
None
,
target
=
None
):
## FIXME: None
"""
"""
TODO: documentation
TODO: documentation
...
@@ -63,16 +63,22 @@ class explicit_operator(operator):
...
@@ -63,16 +63,22 @@ class explicit_operator(operator):
## check domain
## check domain
if
(
not
isinstance
(
domain
,
space
)):
if
(
not
isinstance
(
domain
,
space
)):
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
elif
(
np
.
size
(
matrix
,
axis
=
None
)
%
domain
.
dim
(
split
=
False
)
!=
0
):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: dimension mismatch ( "
+
str
(
np
.
size
(
matrix
,
axis
=
None
))
+
" <> "
+
str
(
domain
.
dim
(
split
=
False
))
+
" )."
))
self
.
domain
=
domain
self
.
domain
=
domain
## check shape
## check matrix and target
if
(
matrix
is
None
):
if
(
target
is
None
):
val
=
np
.
zeros
((
self
.
domain
.
dim
(
split
=
False
),
self
.
domain
.
dim
(
split
=
False
)),
dtype
=
np
.
int
,
order
=
'C'
)
target
=
self
.
domain
else
:
if
(
not
isinstance
(
target
,
space
)):
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
elif
(
target
!=
self
.
domain
):
sym
=
False
uni
=
False
val
=
np
.
zeros
((
target
.
dim
(
split
=
False
),
self
.
domain
.
dim
(
split
=
False
)),
dtype
=
np
.
int
,
order
=
'C'
)
elif
(
np
.
size
(
matrix
,
axis
=
None
)
%
self
.
domain
.
dim
(
split
=
False
)
==
0
):
val
=
np
.
array
(
matrix
).
reshape
((
-
1
,
self
.
domain
.
dim
(
split
=
False
)))
val
=
np
.
array
(
matrix
).
reshape
((
-
1
,
self
.
domain
.
dim
(
split
=
False
)))
if
(
val
.
size
>
1048576
):
about
.
infos
.
cprint
(
"INFO: matrix size > 2 ** 20."
)
## check target
if
(
target
is
not
None
):
if
(
target
is
not
None
):
if
(
not
isinstance
(
target
,
space
)):
if
(
not
isinstance
(
target
,
space
)):
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
...
@@ -85,6 +91,10 @@ class explicit_operator(operator):
...
@@ -85,6 +91,10 @@ class explicit_operator(operator):
target
=
self
.
domain
target
=
self
.
domain
else
:
else
:
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: insufficient input."
))
raise
TypeError
(
about
.
_errors
.
cstring
(
"ERROR: insufficient input."
))
else
:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: dimension mismatch ( "
+
str
(
np
.
size
(
matrix
,
axis
=
None
))
+
" <> "
+
str
(
self
.
domain
.
dim
(
split
=
False
))
+
" )."
))
if
(
val
.
size
>
1048576
):
about
.
infos
.
cprint
(
"INFO: matrix size > 2 ** 20."
)
self
.
target
=
target
self
.
target
=
target
## check datatype
## check datatype
...
@@ -106,30 +116,6 @@ class explicit_operator(operator):
...
@@ -106,30 +116,6 @@ class explicit_operator(operator):
else
:
else
:
self
.
val
=
val
.
astype
(
datatype
)
self
.
val
=
val
.
astype
(
datatype
)
# if(np.iscomplexobj(val)):
# if(np.all(np.imag(val)==0)):
# val = np.real(val).astype(min(val.dtype,self.domain.vol.dtype,self.target.vol.dtype))
# else:
# val = val.astype(min(val.dtype,self.domain.datatype,self.target.datatype))
# else:
# val = val.astype(min(val.dtype,self.domain.vol.dtype,self.target.vol.dtype))
# ## weight if ... (given `domain` and `target`)
# if(isinstance(bare,tuple)):
# if(len(bare)!=2):
# raise ValueError(about._errors.cstring("ERROR: invalid input."))
# else:
# val = self._calc_weight_rows(val,-bool(bare[0]))
# val = self._calc_weight_cols(val,-bool(bare[1]))
# elif(not bare):
# val = self._calc_weight_rows(val,-1)
# self.val = val
## check hidden degrees of freedom
## check hidden degrees of freedom
self
.
_hidden
=
np
.
array
([
self
.
domain
.
dim
(
split
=
False
)
<
self
.
domain
.
dof
(),
self
.
target
.
dim
(
split
=
False
)
<
self
.
target
.
dof
()],
dtype
=
np
.
bool
)
self
.
_hidden
=
np
.
array
([
self
.
domain
.
dim
(
split
=
False
)
<
self
.
domain
.
dof
(),
self
.
target
.
dim
(
split
=
False
)
<
self
.
target
.
dof
()],
dtype
=
np
.
bool
)
# if(np.any(self._hidden)):
# if(np.any(self._hidden)):
...
@@ -175,29 +161,35 @@ class explicit_operator(operator):
...
@@ -175,29 +161,35 @@ class explicit_operator(operator):
TODO: documentation
TODO: documentation
"""
"""
## check shape
## check matrix
val
=
np
.
array
(
newmatrix
).
reshape
((
-
1
,
self
.
domain
.
dim
(
split
=
False
)))
if
(
np
.
size
(
newmatrix
,
axis
=
None
)
==
self
.
domain
.
dim
(
split
=
False
)
*
self
.
target
.
dim
(
split
=
False
)):
val
=
np
.
array
(
newmatrix
).
reshape
((
self
.
target
.
dim
(
split
=
False
),
self
.
domain
.
dim
(
split
=
False
)))
if
(
self
.
target
!=
self
.
domain
):
sym
=
False
uni
=
False
if
(
val
.
size
>
1048576
):
if
(
val
.
size
>
1048576
):
about
.
warnings
.
cprint
(
"WARNING: matrix size > 2 ** 20."
)
about
.
infos
.
cprint
(
"INFO: matrix size > 2 ** 20."
)
else
:
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: dimension mismatch ( "
+
str
(
np
.
size
(
matrix
,
axis
=
None
))
+
" <> "
+
str
(
self
.
nrow
())
+
" x "
+
str
(
self
.
ncol
())
+
" )."
))
## check datatype
## check datatype
if
(
np
.
iscomplexobj
(
val
)):
if
(
np
.
any
(
np
.
iscomplex
(
val
))):
if
(
np
.
all
(
np
.
imag
(
val
)
==
0
)):
datatype
,
purelyreal
=
max
(
min
(
val
.
dtype
,
self
.
domain
.
datatype
),
min
(
val
.
dtype
,
self
.
target
.
datatype
)),
False
val
=
np
.
real
(
val
).
astype
(
min
(
val
.
dtype
,
self
.
domain
.
vol
.
dtype
,
self
.
target
.
vol
.
dtype
))
else
:
val
=
val
.
astype
(
min
(
val
.
dtype
,
self
.
domain
.
datatype
,
self
.
target
.
datatype
))
else
:
else
:
val
=
val
.
astype
(
min
(
val
.
dtype
,
self
.
domain
.
vol
.
dtype
,
self
.
target
.
vol
.
dtype
))
datatype
,
purelyreal
=
max
(
min
(
val
.
dtype
,
self
.
domain
.
vol
.
dtype
),
min
(
val
.
dtype
,
self
.
target
.
vol
.
dtype
))
,
True
## weight if ... (given `domain` and `target`)
## weight if ... (given `domain` and `target`)
if
(
isinstance
(
bare
,
tuple
)):
if
(
isinstance
(
bare
,
tuple
)):
if
(
len
(
bare
)
!=
2
):
if
(
len
(
bare
)
!=
2
):
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
raise
ValueError
(
about
.
_errors
.
cstring
(
"ERROR: invalid input."
))
else
:
else
:
val
=
self
.
_calc_weight_rows
(
val
,
power
=
-
bool
(
bare
[
0
]))
val
=
self
.
_calc_weight_rows
(
val
,
-
bool
(
bare
[
0
]))
val
=
self
.
_calc_weight_cols
(
val
,
power
=
-
bool
(
bare
[
1
]))
val
=
self
.
_calc_weight_cols
(
val
,
-
bool
(
bare
[
1
]))
elif
(
not
bare
):
elif
(
not
bare
):
val
=
self
.
_calc_weight_rows
(
val
,
-
1
)
val
=
self
.
_calc_weight_rows
(
val
,
-
1
)
self
.
val
=
val
if
(
purelyreal
):
self
.
val
=
np
.
real
(
val
).
astype
(
datatype
)
else
:
self
.
val
=
val
.
astype
(
datatype
)
## check flags
## check flags
self
.
sym
,
self
.
uni
=
self
.
_check_flags
(
sym
=
sym
,
uni
=
uni
)
self
.
sym
,
self
.
uni
=
self
.
_check_flags
(
sym
=
sym
,
uni
=
uni
)
...
...
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