Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Karsa Zoltán István
/
politopok
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
301a5e9c
authored
Jan 18, 2023
by
Zoltan Karsa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cupy integrate
parent
b9a0229d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
49 deletions
+67
-49
genax.py
+64
-47
utils.py
+3
-2
No files found.
genax.py
View file @
301a5e9c
import
numpy
,
matplotlib
.
pyplot
as
plt
import
cupy
as
cp
,
matplotlib
.
pyplot
as
plt
from
numba
import
cuda
from
numba
import
cuda
from
utils
import
expSpace
from
utils
import
expSpace
...
@@ -6,41 +6,57 @@ def gen_angels_to_pick(n, plot = False):
...
@@ -6,41 +6,57 @@ def gen_angels_to_pick(n, plot = False):
if
n
%
2
==
0
:
if
n
%
2
==
0
:
raise
"n
%2
==0"
raise
"n
%2
==0"
N
=
int
((
n
+
3
)
/
2
)
N
=
int
((
n
+
3
)
/
2
)
X1
=
expSpace
(
0.0
,
numpy
.
pi
/
2.0
,
N
)
X1
=
expSpace
(
0.0
,
cp
.
pi
/
2.0
,
N
)
X3
=
expSpace
(
numpy
.
pi
/
2.0
,
numpy
.
pi
,
N
)
X3
=
expSpace
(
cp
.
pi
/
2.0
,
cp
.
pi
,
N
)
X3
=
-
1
*
X3
+
3.0
*
numpy
.
pi
/
2.0
X3
=
-
1
*
X3
+
3.0
*
cp
.
pi
/
2.0
anglestopick
=
numpy
.
concatenate
((
X1
,
X3
),
axis
=
None
)
anglestopick
=
cp
.
concatenate
((
X1
,
X3
),
axis
=
None
)
anglestopick
=
numpy
.
unique
(
anglestopick
)
# Vigyázni vele!
anglestopick
=
cp
.
unique
(
anglestopick
)
# Vigyázni vele!
anglestopick
=
anglestopick
[
1
:
-
1
]
anglestopick
=
anglestopick
[
1
:
-
1
]
if
plot
:
if
plot
:
Y
=
numpy
.
zeros
(
n
)
Y
=
cp
.
zeros
(
n
)
plt
.
plot
(
anglestopick
,
Y
,
'|'
)
plt
.
plot
(
anglestopick
,
Y
,
'|'
)
plt
.
show
()
plt
.
show
()
return
anglestopick
return
anglestopick
def
angles_alap
(
anglestopick
,
plot
=
False
):
parosit
=
cp
.
RawKernel
(
r'''
alpha_arr
=
numpy
.
array
([])
extern "C"
beta_arr
=
numpy
.
array
([])
__global__
void my_add(const double* x1, const double* x2, double* a, double* b, const size_t m, const float PI) {
int tid = blockDim.x * blockIdx.x + threadIdx.x;
float alpha = x1[tid];
for (size_t i = 0; i < m; i++) {
float betha = x2[i];
if ((alpha + betha) < PI && betha > alpha && alpha > 0.0) {
a[tid*m+i] = alpha;
b[tid*m+i] = betha;
} else {
a[tid*m+i] = -1.0;
b[tid*m+i] = -1.0;
}
}
}
'''
,
'parosit'
)
for
alpha
in
anglestopick
:
def
angles_alap
(
anglestopick
,
plot
=
False
):
for
beta
in
anglestopick
:
m
=
anglestopick
.
size
if
alpha
+
beta
<
numpy
.
pi
and
beta
>=
alpha
and
alpha
!=
0.0
:
# vigyázni
alpha_arr
=
cp
.
zeros
((
m
,
m
),
dtype
=
cp
.
float64
)
alpha_arr
=
numpy
.
insert
(
alpha_arr
,
0
,
alpha
)
beta_arr
=
cp
.
zeros
((
m
,
m
),
dtype
=
cp
.
float64
)
beta_arr
=
numpy
.
insert
(
beta_arr
,
0
,
beta
)
parosit
((
1
,),
(
m
,),
(
anglestopick
,
anglestopick
,
alpha_arr
,
beta_arr
,
m
,
cp
.
pi
))
tompa_beta_arr
=
beta_arr
[
beta_arr
>
numpy
.
pi
]
tompa_beta_arr
=
beta_arr
[
beta_arr
>
cp
.
pi
]
tompa_beta_mpi_arr
=
tompa_beta_arr
-
numpy
.
pi
/
2
tompa_beta_mpi_arr
=
tompa_beta_arr
-
cp
.
pi
/
2
hegyes_beta_arr
=
beta_arr
[
beta_arr
<=
numpy
.
pi
]
hegyes_beta_arr
=
beta_arr
[
beta_arr
<=
cp
.
pi
]
tompa_alpha_arr
=
alpha_arr
[
beta_arr
>
numpy
.
pi
]
tompa_alpha_arr
=
alpha_arr
[
beta_arr
>
cp
.
pi
]
hegyes_alpha_arr
=
alpha_arr
[
alpha_arr
<=
numpy
.
pi
]
hegyes_alpha_arr
=
alpha_arr
[
alpha_arr
<=
cp
.
pi
]
tghB
=
numpy
.
tan
(
hegyes_beta_arr
)
tghB
=
cp
.
tan
(
hegyes_beta_arr
)
tghA
=
numpy
.
tan
(
hegyes_alpha_arr
)
tghA
=
cp
.
tan
(
hegyes_alpha_arr
)
tgtB_mpi
=
numpy
.
tan
(
tompa_beta_mpi_arr
)
tgtB_mpi
=
cp
.
tan
(
tompa_beta_mpi_arr
)
tgtA
=
numpy
.
tan
(
tompa_alpha_arr
)
tgtA
=
cp
.
tan
(
tompa_alpha_arr
)
# hegyes
# hegyes
sztgh
=
tghB
*
tghA
sztgh
=
tghB
*
tghA
...
@@ -54,32 +70,32 @@ def angles_alap(anglestopick, plot = False):
...
@@ -54,32 +70,32 @@ def angles_alap(anglestopick, plot = False):
tCy
=
tgtA
/
mtgt
tCy
=
tgtA
/
mtgt
tCx
=
tCy
/
tgtA
tCx
=
tCy
/
tgtA
Cy
=
numpy
.
concatenate
((
hCy
,
tCy
),
axis
=
None
)
Cy
=
cp
.
concatenate
((
hCy
,
tCy
),
axis
=
None
)
Cx
=
numpy
.
concatenate
((
hCx
,
tCx
),
axis
=
None
)
Cx
=
cp
.
concatenate
((
hCx
,
tCx
),
axis
=
None
)
return
Cx
,
Cy
return
Cx
,
Cy
def
angles_ratet
(
anglestopick
,
plot
=
False
):
def
angles_ratet
(
anglestopick
,
plot
=
False
):
alpha_arr
=
numpy
.
array
([])
alpha_arr
=
cp
.
array
([])
beta_arr
=
numpy
.
array
([])
beta_arr
=
cp
.
array
([])
for
alpha
in
anglestopick
:
for
alpha
in
anglestopick
:
for
beta
in
anglestopick
:
for
beta
in
anglestopick
:
if
alpha
+
beta
<
numpy
.
pi
and
alpha
!=
0.0
:
# vigyázni
if
alpha
+
beta
<
cp
.
pi
and
alpha
!=
0.0
:
# vigyázni
alpha_arr
=
numpy
.
inser
t
(
alpha_arr
,
0
,
alpha
)
alpha_arr
=
cp
.
pu
t
(
alpha_arr
,
0
,
alpha
)
beta_arr
=
numpy
.
inser
t
(
beta_arr
,
0
,
beta
)
beta_arr
=
cp
.
pu
t
(
beta_arr
,
0
,
beta
)
tompa_beta_arr
=
beta_arr
[
beta_arr
>
numpy
.
pi
]
tompa_beta_arr
=
beta_arr
[
beta_arr
>
cp
.
pi
]
tompa_beta_mpi_arr
=
tompa_beta_arr
-
numpy
.
pi
/
2
tompa_beta_mpi_arr
=
tompa_beta_arr
-
cp
.
pi
/
2
hegyes_beta_arr
=
beta_arr
[
beta_arr
<=
numpy
.
pi
]
hegyes_beta_arr
=
beta_arr
[
beta_arr
<=
cp
.
pi
]
tompa_alpha_arr
=
alpha_arr
[
beta_arr
>
numpy
.
pi
]
tompa_alpha_arr
=
alpha_arr
[
beta_arr
>
cp
.
pi
]
hegyes_alpha_arr
=
alpha_arr
[
alpha_arr
<=
numpy
.
pi
]
hegyes_alpha_arr
=
alpha_arr
[
alpha_arr
<=
cp
.
pi
]
tghB
=
numpy
.
tan
(
hegyes_beta_arr
)
tghB
=
cp
.
tan
(
hegyes_beta_arr
)
tghA
=
numpy
.
tan
(
hegyes_alpha_arr
)
tghA
=
cp
.
tan
(
hegyes_alpha_arr
)
tgtB_mpi
=
numpy
.
tan
(
tompa_beta_mpi_arr
)
tgtB_mpi
=
cp
.
tan
(
tompa_beta_mpi_arr
)
tgtA
=
numpy
.
tan
(
tompa_alpha_arr
)
tgtA
=
cp
.
tan
(
tompa_alpha_arr
)
# hegyes
# hegyes
sztgh
=
tghB
*
tghA
sztgh
=
tghB
*
tghA
...
@@ -93,14 +109,14 @@ def angles_ratet(anglestopick, plot = False):
...
@@ -93,14 +109,14 @@ def angles_ratet(anglestopick, plot = False):
tCy
=
tgtA
/
mtgt
tCy
=
tgtA
/
mtgt
tCx
=
tCy
/
tgtA
tCx
=
tCy
/
tgtA
Ey
=
numpy
.
concatenate
((
hCy
,
tCy
),
axis
=
None
)
Ey
=
cp
.
concatenate
((
hCy
,
tCy
),
axis
=
None
)
Ex
=
numpy
.
concatenate
((
hCx
,
tCx
),
axis
=
None
)
Ex
=
cp
.
concatenate
((
hCx
,
tCx
),
axis
=
None
)
cos
=
numpy
.
cos
(
anglestopick
)
cos
=
cp
.
cos
(
anglestopick
)
sin
=
numpy
.
sin
(
anglestopick
)
sin
=
cp
.
sin
(
anglestopick
)
Dx
=
numpy
.
outer
(
numpy
.
full
(
anglestopick
.
size
,
1.0
),
Ex
)
.
flatten
()
Dx
=
cp
.
outer
(
cp
.
full
(
anglestopick
.
size
,
1.0
),
Ex
)
.
flatten
()
Dy
=
numpy
.
outer
(
cos
,
Ey
)
.
flatten
()
Dy
=
cp
.
outer
(
cos
,
Ey
)
.
flatten
()
Dz
=
numpy
.
outer
(
sin
,
Ey
)
.
flatten
()
Dz
=
cp
.
outer
(
sin
,
Ey
)
.
flatten
()
return
Dx
,
Dy
,
Dz
return
Dx
,
Dy
,
Dz
\ No newline at end of file
utils.py
View file @
301a5e9c
import
numpy
import
cupy
as
cp
def
expSpace
(
min
,
max
,
N
,
exponentialliness
=
20.0
):
def
expSpace
(
min
,
max
,
N
,
exponentialliness
=
20.0
):
LinVec
=
numpy
.
linspace
(
0
,
numpy
.
log10
(
exponentialliness
+
1
),
N
)
LinVec
=
cp
.
linspace
(
0
,
cp
.
log10
(
exponentialliness
+
1
),
N
)
return
(
max
-
min
)
/
exponentialliness
*
(
10.0
**
LinVec
-
1
)
+
min
return
(
max
-
min
)
/
exponentialliness
*
(
10.0
**
LinVec
-
1
)
+
min
\ No newline at end of file
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