Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102579663
homogeneization.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Feb 22, 05:01
Size
2 KB
Mime Type
text/x-python
Expires
Mon, Feb 24, 05:01 (2 d)
Engine
blob
Format
Raw Data
Handle
24363241
Attached To
R6746 RationalROMPy
homogeneization.py
View Options
# Copyright (C) 2018 by the RROMPy authors
#
# This file is part of RROMPy.
#
# RROMPy is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# RROMPy is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with RROMPy. If not, see <http://www.gnu.org/licenses/>.
#
import
numpy
as
np
from
rrompy.utilities.base.types
import
Np1D
,
Np2D
,
Tuple
,
List
,
paramList
from
rrompy.utilities.poly_fitting.polynomial
import
(
polyvander
,
hashIdxToDerivative
as
hashI
)
from
rrompy.parameter
import
checkParameterList
__all__
=
[
'homogeneizationMask'
,
'homogeneizedpolyvander'
,
'homogeneizedToFull'
]
def
homogeneizationMask
(
degs
:
List
[
int
])
->
Tuple
[
List
[
int
],
List
[
bool
]]:
dim
=
len
(
degs
)
N
=
np
.
prod
([
d
+
1
for
d
in
degs
])
maskN
=
np
.
arange
(
N
,
dtype
=
int
)
remN
=
np
.
zeros
((
N
,
dim
),
dtype
=
int
)
for
j
in
range
(
dim
-
1
,
-
1
,
-
1
):
remN
[:,
j
]
=
maskN
%
(
degs
[
j
]
+
1
)
maskN
//=
degs
[
j
]
+
1
mask
=
np
.
sum
(
remN
,
axis
=
1
)
<=
min
(
degs
)
return
remN
[
mask
],
mask
def
homogeneizedpolyvander
(
x
:
paramList
,
deg
:
int
,
basis
:
str
,
derIdxs
:
List
[
List
[
List
[
int
]]]
=
None
,
reorder
:
List
[
int
]
=
None
,
scl
:
Np1D
=
None
)
\
->
Tuple
[
Np2D
,
List
[
List
[
int
]],
List
[
int
]]:
x
=
checkParameterList
(
x
)[
0
]
degs
=
[
deg
]
*
x
.
shape
[
1
]
VanBase
=
polyvander
(
x
,
degs
,
basis
,
derIdxs
,
reorder
,
scl
)
derIdxs
,
mask
=
homogeneizationMask
(
degs
)
ordIdxs
=
np
.
empty
(
len
(
derIdxs
),
dtype
=
int
)
derTotal
=
np
.
array
([
np
.
sum
(
y
)
for
y
in
derIdxs
])
idxPrev
=
0
rangeAux
=
np
.
arange
(
len
(
derIdxs
))
for
j
in
range
(
deg
+
1
):
idxLocal
=
rangeAux
[
derTotal
==
j
][::
-
1
]
idxPrev
+=
len
(
idxLocal
)
ordIdxs
[
idxPrev
-
len
(
idxLocal
)
:
idxPrev
]
=
idxLocal
return
VanBase
[:,
mask
],
derIdxs
,
ordIdxs
def
homogeneizedToFull
(
shapeFull
:
Tuple
[
int
],
dim
:
int
,
coeffs
:
Np2D
)
->
Np2D
:
full
=
np
.
zeros
(
shapeFull
,
dtype
=
coeffs
.
dtype
)
for
j
in
range
(
len
(
coeffs
)):
full
[
tuple
(
hashI
(
j
,
dim
))]
=
coeffs
[
j
]
return
full
Event Timeline
Log In to Comment