Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Rémy Mozul
FortHon
Commits
68da62ce
Commit
68da62ce
authored
Jul 21, 2014
by
Mozul Rémy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
managing to reference the whole derived type instead of copy of non-pointer data
parent
ef980a04
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
126 additions
and
6 deletions
+126
-6
fortran_shared_db/dtype.h
fortran_shared_db/dtype.h
+2
-0
fortran_shared_db/dtype.pxd
fortran_shared_db/dtype.pxd
+2
-0
fortran_shared_db/dtype.pyx
fortran_shared_db/dtype.pyx
+14
-1
fortran_shared_db/mod_dtype.f90
fortran_shared_db/mod_dtype.f90
+105
-0
fortran_shared_db/test.py
fortran_shared_db/test.py
+1
-2
test.pyx
test.pyx
+2
-3
No files found.
fortran_shared_db/dtype.h
View file @
68da62ce
...
...
@@ -21,5 +21,7 @@ typedef struct
}
C_datatype
;
void
getOne
(
int
id
,
C_datatype
*
d
);
C_datatype
*
addOne
(
char
*
nn
,
double
rv
,
int
iv
);
void
display
(
int
id
);
void
change
(
int
id
,
char
*
nn
,
double
rv
,
int
iv
);
fortran_shared_db/dtype.pxd
View file @
68da62ce
...
...
@@ -15,5 +15,7 @@ cdef extern from 'dtype.h':
C_param
*
weird
void
getOne
(
int
id
,
C_datatype
*
d
)
C_datatype
*
addOne
(
char
*
nn
,
double
rv
,
int
iv
)
void
display
(
int
id
)
void
change
(
int
id
,
char
*
nn
,
double
rv
,
int
iv
)
fortran_shared_db/dtype.pyx
View file @
68da62ce
...
...
@@ -12,19 +12,23 @@ cdef class P_datatype(object):
cdef
int
id
cdef
C_datatype
f_image
cdef
C_datatype
*
f_image_ptr
cdef
public
np
.
ndarray
rtab
@
ct
.
locals
(
i
=
int
)
def
__init__
(
self
,
i
):
def
__init__
(
self
,
i
,
nn
,
rv
,
iv
):
self
.
id
=
i
getOne
(
i
,
&
self
.
f_image
)
self
.
rtab
=
np
.
PyArray_SimpleNewFromData
(
1
,
[
self
.
f_image
.
itab
[
0
]],
np
.
NPY_DOUBLE
,
self
.
f_image
.
rtab
)
self
.
f_image_ptr
=
addOne
(
nn
,
rv
,
iv
)
def
cythonChange
(
self
,
nn
,
rv
,
iv
):
#&self.f_image.nickname[0] = nn
self
.
f_image
.
rsingle
=
rv
self
.
f_image
.
isingle
=
iv
self
.
f_image_ptr
.
rsingle
=
rv
self
.
f_image_ptr
.
isingle
=
iv
def
fortranChange
(
self
,
nn
,
rv
,
iv
):
change
(
self
.
id
,
nn
,
rv
,
iv
)
...
...
@@ -39,6 +43,7 @@ cdef class P_datatype(object):
display
(
self
.
id
)
def
cythonContent
(
self
):
print
'f_image :'
cdef
int
i
print
self
.
f_image
.
nickname
print
self
.
f_image
.
rsingle
...
...
@@ -48,4 +53,12 @@ cdef class P_datatype(object):
print
self
.
rtab
for
i
in
range
(
self
.
f_image
.
itab
[
1
]):
print
self
.
f_image
.
weird
[
i
]
print
'f_image_ptr :'
print
self
.
f_image_ptr
.
nickname
print
self
.
f_image_ptr
.
rsingle
print
self
.
f_image_ptr
.
isingle
for
i
in
range
(
self
.
f_image_ptr
.
itab
[
0
]):
print
self
.
f_image_ptr
.
rtab
[
i
]
for
i
in
range
(
self
.
f_image_ptr
.
itab
[
1
]):
print
self
.
f_image_ptr
.
weird
[
i
]
fortran_shared_db/mod_dtype.f90
View file @
68da62ce
...
...
@@ -41,6 +41,13 @@ module data_type
type
(
T_datatype
),
dimension
(:),
allocatable
::
mydatas
type
T_dt_link
type
(
t_datatype
),
pointer
::
d
=>
null
()
type
(
T_dt_link
)
,
pointer
::
n
=>
null
()
end
type
type
(
T_dt_link
),
pointer
::
root
=>
null
()
type
(
T_dt_link
),
pointer
::
curr
=>
null
()
!----------------------------------------------------------------------
integer
::
nb_data
=
0
...
...
@@ -96,6 +103,59 @@ contains
end
subroutine
function
add_one
(
nn
,
rv
,
iv
)
bind
(
c
,
name
=
'addOne'
)
implicit
none
real
(
kind
=
c_double
),
intent
(
in
),
value
::
rv
integer
(
kind
=
c_int
),
intent
(
in
),
value
::
iv
type
(
c_ptr
),
value
::
nn
type
(
c_ptr
)
::
add_one
!
real
(
kind
=
8
)
,
dimension
(:),
pointer
::
rtab
type
(
T_param
),
dimension
(:),
pointer
::
weird
character
(
kind
=
c_char
,
len
=
30
),
pointer
::
nname
integer
(
kind
=
4
)
::
i
type
(
T_dt_link
),
pointer
::
new
allocate
(
new
)
allocate
(
new
%
d
)
call
c_f_pointer
(
cptr
=
nn
,
fptr
=
nname
)
i
=
0
do
while
(
i
<
30
.and.
nname
(
i
+1
:
i
+1
)
/
=
c_null_char
)
i
=
i
+
1
end
do
new
%
d
%
nickname
(
1
:
i
)
=
nname
(
1
:
i
)
new
%
d
%
nickname
(
i
+1
:)
=
''
new
%
d
%
rsingle
=
rv
new
%
d
%
isingle
=
iv
new
%
d
%
itab
=
(/
2
,
3
/)
allocate
(
rtab
(
2
))
rtab
=
(/
0.d0
,
0.d0
/)
new
%
d
%
rtab
=
c_loc
(
rtab
(
1
))
allocate
(
weird
(
3
))
do
i
=
1
,
3
weird
(
i
)
%
itype
=
i
weird
(
i
)
%
val
=
1.
write
(
weird
(
i
)
%
field
,
'(A,I0)'
)
'field of '
,
i
end
do
new
%
d
%
weird
=
c_loc
(
weird
(
1
))
if
(
.not.
associated
(
root
)
)
then
root
=>
new
else
curr
%
n
=>
new
curr
=>
new
end
if
add_one
=
c_loc
(
new
%
d
)
end
function
subroutine
display
(
id
)
bind
(
c
,
name
=
'display'
)
implicit
none
integer
(
kind
=
c_int
),
intent
(
in
),
value
::
id
...
...
@@ -103,6 +163,7 @@ contains
integer
(
kind
=
4
)
::
i
real
(
kind
=
8
)
,
dimension
(:),
pointer
::
rtab
type
(
T_param
),
dimension
(:),
pointer
::
weird
type
(
T_dt_link
)
,
pointer
::
dl
print
*
,
'T_DATA of id '
,
id
print
*
,
' nickname : '
,
mydatas
(
id
)
%
nickname
...
...
@@ -121,6 +182,34 @@ contains
print
*
,
' --field : '
,
weird
(
i
)
%
field
end
do
print
*
,
'T_DATA of in linked list of rank '
,
id
dl
=>
Root
do
i
=
1
,
id
-1
if
(
associated
(
dl
%
n
)
)
then
dl
=>
dl
%
n
else
print
*
,
'rank given higher than number of elements... get last'
exit
end
if
end
do
print
*
,
' nickname : '
,
dl
%
d
%
nickname
print
*
,
' rsingle : '
,
dl
%
d
%
rsingle
print
*
,
' isingle : '
,
dl
%
d
%
isingle
print
*
,
' itab : '
,
dl
%
d
%
itab
call
c_f_pointer
(
dl
%
d
%
rtab
,
rtab
,(/
dl
%
d
%
itab
(
1
)/))
call
c_f_pointer
(
dl
%
d
%
weird
,
weird
,(/
dl
%
d
%
itab
(
2
)/))
print
*
,
' rtab : '
,
rtab
do
i
=
1
,
dl
%
d
%
itab
(
2
)
print
*
,
' weird : '
,
i
print
*
,
' --itype : '
,
weird
(
i
)
%
itype
print
*
,
' --val : '
,
weird
(
i
)
%
val
print
*
,
' --field : '
,
weird
(
i
)
%
field
end
do
end
subroutine
subroutine
change
(
id
,
nn
,
rv
,
iv
)
bind
(
c
,
name
=
'change'
)
...
...
@@ -132,6 +221,7 @@ contains
!
character
(
kind
=
c_char
,
len
=
30
),
pointer
::
nname
integer
(
kind
=
4
)
::
i
type
(
T_dt_link
)
,
pointer
::
dl
call
c_f_pointer
(
cptr
=
nn
,
fptr
=
nname
)
i
=
0
...
...
@@ -144,6 +234,21 @@ contains
mydatas
(
id
)
%
rsingle
=
rv
mydatas
(
id
)
%
isingle
=
iv
dl
=>
Root
do
i
=
1
,
id
-1
if
(
associated
(
dl
%
n
)
)
then
dl
=>
dl
%
n
else
print
*
,
'rank given higher than number of elements... no modif'
return
end
if
end
do
dl
%
d
%
nickname
(
1
:
i
)
=
nname
(
1
:
i
)
dl
%
d
%
nickname
(
i
+1
:)
=
''
dl
%
d
%
rsingle
=
rv
dl
%
d
%
isingle
=
iv
end
subroutine
end
module
data_type
...
...
fortran_shared_db/test.py
View file @
68da62ce
import
dtype
dat
=
dtype
.
P_datatype
(
1
)
dat
=
dtype
.
P_datatype
(
1
,
'new from p'
,
12.
,
5
)
test.pyx
View file @
68da62ce
...
...
@@ -19,11 +19,10 @@ cdef class pytype(object):
@
cython
.
locals
(
a
=
numpy
.
ndarray
)
def
__init__
(
self
,
a
):
a
=
numpy
.
asfarray
(
a
)
self
.
x
=
{
'i'
:
a
.
shape
[
0
],
'j'
:
a
.
shape
[
1
],
'mat'
:
<
double
*>
a
.
data
}
#cdef double * params = cython.address(self.x).params
#self.p_params = numpy.asfarray(<numpy.double64_t[:4]> params)
#self.p_params = numpy.asfarray(<numpy.double64_t[:4]> cython.address(self.x).params)
cdef
numpy
.
npy_intp
s
[
1
]
s
[
0
]
=
<
numpy
.
npy_intp
>
4
self
.
p_params
=
numpy
.
PyArray_SimpleNewFromData
(
1
,
s
,
numpy
.
NPY_DOUBLE
,
cython
.
address
(
self
.
x
).
params
)
...
...
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