Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F85889153
sample_list.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
Wed, Oct 2, 19:33
Size
6 KB
Mime Type
text/x-python
Expires
Fri, Oct 4, 19:33 (2 d)
Engine
blob
Format
Raw Data
Handle
21291441
Attached To
R6746 RationalROMPy
sample_list.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/>.
#
from
copy
import
deepcopy
as
copy
import
numpy
as
np
from
rrompy.utilities.exception_manager
import
RROMPyAssert
from
rrompy.utilities.base.types
import
Np1D
,
List
__all__
=
[
'emptySampleList'
,
'sampleList'
]
class
sampleList
:
"""HERE"""
def
__init__
(
self
,
data
:
List
[
Np1D
],
lengthCheck
:
int
=
None
,
deep
:
bool
=
True
):
if
isinstance
(
data
,
(
self
.
__class__
,)):
data
=
data
.
data
if
isinstance
(
data
,
(
np
.
ndarray
,)):
self
.
data
=
copy
(
data
)
if
deep
else
data
if
self
.
data
.
ndim
<=
1
:
self
.
data
.
shape
=
(
self
.
data
.
shape
[
0
],
1
)
else
:
if
not
isinstance
(
data
,
(
list
,)):
data
=
[
data
]
self
.
data
=
np
.
empty
((
len
(
data
[
0
]),
len
(
data
)),
dtype
=
data
[
0
]
.
dtype
)
for
j
,
par
in
enumerate
(
data
):
self
[
j
]
=
copy
(
data
[
j
])
if
deep
else
data
[
j
]
if
j
==
0
and
lengthCheck
is
None
:
lengthCheck
=
self
.
shape
[
0
]
RROMPyAssert
(
len
(
data
[
j
]),
lengthCheck
,
"Number of parameters"
)
def
__len__
(
self
):
return
self
.
shape
[
1
]
def
__str__
(
self
):
return
str
(
self
.
data
)
def
__repr__
(
self
):
return
repr
(
self
.
data
)
@property
def
shape
(
self
):
return
self
.
data
.
shape
@property
def
re
(
self
):
return
sampleList
(
np
.
real
(
self
.
data
))
@property
def
im
(
self
):
return
sampleList
(
np
.
imag
(
self
.
data
))
@property
def
abs
(
self
):
return
sampleList
(
np
.
abs
(
self
.
data
))
@property
def
angle
(
self
):
return
sampleList
(
np
.
angle
(
self
.
data
))
def
conj
(
self
):
return
sampleList
(
np
.
conj
(
self
.
data
))
@property
def
T
(
self
):
return
sampleList
(
self
.
data
.
T
)
@property
def
H
(
self
):
return
sampleList
(
self
.
data
.
T
.
conj
())
@property
def
dtype
(
self
):
return
self
.
data
.
dtype
@dtype.setter
def
dtype
(
self
,
dtype
):
self
.
data
.
dtype
=
dtype
def
__getitem__
(
self
,
key
):
return
self
.
data
[:,
key
]
def
__call__
(
self
,
key
):
return
sampleList
(
self
.
data
[:,
key
])
def
__setitem__
(
self
,
key
,
value
):
if
isinstance
(
key
,
(
tuple
,
list
,)):
RROMPyAssert
(
len
(
key
),
len
(
value
),
"Slice length"
)
for
k
,
val
in
zip
(
key
,
value
):
self
[
k
]
=
val
else
:
self
.
data
[:,
key
]
=
value
def
__iter__
(
self
):
return
self
.
data
.
T
def
__eq__
(
self
,
other
):
if
not
hasattr
(
other
,
"shape"
)
or
self
.
shape
!=
other
.
shape
:
return
False
if
isinstance
(
other
,
self
.
__class__
):
fac
=
other
.
data
else
:
fac
=
other
return
np
.
allclose
(
self
.
data
,
fac
)
def
__ne__
(
self
,
other
):
return
not
self
==
other
def
__copy__
(
self
):
return
sampleList
(
self
.
data
)
def
__deepcopy__
(
self
,
memo
):
return
sampleList
(
copy
(
self
.
data
,
memo
))
def
__add__
(
self
,
other
):
if
isinstance
(
other
,
self
.
__class__
):
RROMPyAssert
(
self
.
shape
,
other
.
shape
,
"Sample shape"
)
fac
=
other
.
data
else
:
fac
=
other
return
sampleList
(
self
.
data
+
fac
)
def
__iadd__
(
self
,
other
):
self
.
data
=
(
self
+
other
)
.
data
return
self
def
__sub__
(
self
,
other
):
if
isinstance
(
other
,
self
.
__class__
):
RROMPyAssert
(
self
.
shape
,
other
.
shape
,
"Sample shape"
)
fac
=
other
.
data
else
:
fac
=
other
return
sampleList
(
self
.
data
-
fac
)
def
__isub__
(
self
,
other
):
self
.
data
=
(
self
-
other
)
.
data
return
self
def
__mul__
(
self
,
other
):
if
isinstance
(
other
,
self
.
__class__
):
RROMPyAssert
(
self
.
shape
,
other
.
shape
,
"Sample shape"
)
fac
=
other
.
data
else
:
fac
=
other
return
sampleList
(
self
.
data
*
fac
)
def
__imul__
(
self
,
other
):
self
.
data
=
(
self
*
other
)
.
data
return
self
def
__truediv__
(
self
,
other
):
if
isinstance
(
other
,
self
.
__class__
):
RROMPyAssert
(
self
.
shape
,
other
.
shape
,
"Sample shape"
)
fac
=
other
.
data
else
:
fac
=
other
return
sampleList
(
self
.
data
/
fac
)
def
__idiv__
(
self
,
other
):
self
.
data
=
(
self
/
other
)
.
data
return
self
def
__pow__
(
self
,
other
):
if
isinstance
(
other
,
self
.
__class__
):
RROMPyAssert
(
self
.
shape
,
other
.
shape
,
"Sample shape"
)
fac
=
other
.
data
else
:
fac
=
other
return
sampleList
(
np
.
power
(
self
.
data
,
fac
))
def
__ipow__
(
self
,
other
):
self
.
data
=
(
self
**
other
)
.
data
return
self
def
__neg__
(
self
):
return
sampleList
(
-
self
.
data
)
def
__pos__
(
self
):
return
sampleList
(
self
.
data
)
def
reset
(
self
,
size
,
dtype
=
np
.
float
):
self
.
data
=
np
.
empty
(
size
,
dtype
=
dtype
)
self
.
data
[:]
=
np
.
nan
def
append
(
self
,
items
):
if
isinstance
(
items
,
self
.
__class__
):
fac
=
items
.
data
else
:
fac
=
items
if
fac
.
ndim
==
1
:
fac
=
fac
[:,
np
.
newaxis
]
self
.
data
=
np
.
append
(
self
.
data
,
fac
,
axis
=
1
)
def
pop
(
self
,
idx
=
-
1
):
self
.
data
=
np
.
delete
(
self
.
data
,
idx
,
axis
=
1
)
def
dot
(
self
,
other
,
sampleListOut
:
bool
=
True
):
if
isinstance
(
other
,
self
.
__class__
):
other
=
other
.
data
prod
=
self
.
data
.
dot
(
other
)
if
sampleListOut
:
prod
=
sampleList
(
prod
)
return
prod
class
emptySampleList
(
sampleList
):
def
__init__
(
self
):
super
()
.
__init__
(
np
.
empty
((
0
,
0
)))
Event Timeline
Log In to Comment