Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rémy Mozul
FortHon
Commits
844bf463
Commit
844bf463
authored
Apr 03, 2014
by
Mozul Rémy
Browse files
array management
parent
a8655ca8
Changes
4
Hide whitespace changes
Inline
Side-by-side
ctest.pxd
View file @
844bf463
...
...
@@ -2,7 +2,7 @@
cdef
extern
from
'type.h'
:
ctypedef
struct
myctype
:
int
i
,
j
double
s
double
*
s
void
print_type
(
myctype
*
ct
)
...
...
mod_type.f90
View file @
844bf463
...
...
@@ -7,27 +7,39 @@ module test_type
type
,
bind
(
c
)
::
myftype
integer
(
c_int
)
::
i
,
j
real
(
c_double
)
::
s
,
s2
type
(
c_ptr
)
::
s
end
type
myftype
contains
subroutine
print_type
(
ft
)
bind
(
c
,
name
=
'print_type'
)
type
(
myftype
)
::
ft
!
real
(
c_double
),
dimension
(:,:),
pointer
::
tab
call
c_f_pointer
(
fptr
=
tab
,
cptr
=
ft
%
s
,
shape
=
(/
ft
%
j
,
ft
%
i
/))
print
*
,
ft
%
i
print
*
,
ft
%
j
print
*
,
ft
%
s
print
*
,
tab
end
subroutine
subroutine
increment
(
ft
)
bind
(
c
,
name
=
'increment'
)
implicit
none
type
(
myftype
)
::
ft
!
integer
(
c_int
)
::
i
,
j
real
(
c_double
),
dimension
(:,:),
pointer
::
tab
call
c_f_pointer
(
fptr
=
tab
,
cptr
=
ft
%
s
,
shape
=
(/
ft
%
j
,
ft
%
i
/))
do
i
=
1
,
ft
%
i
do
j
=
1
,
ft
%
j
tab
(
j
,
i
)
=
0.1d0
*
i
*
j
end
do
end
do
ft
%
i
=
ft
%
i
+1
ft
%
j
=
ft
%
j
-1
ft
%
s
=
dsqrt
(
real
(
ft
%
i
,
c_double
)
*
ft
%
i
+
real
(
ft
%
j
,
c_double
)
*
ft
%
j
)
end
subroutine
end
module
test_type
...
...
test.pyx
View file @
844bf463
import
math
cimport
numpy
import
numpy
import
cython
from
ctest
cimport
myctype
,
increment
,
print_type
@
cython
.
locals
(
x
=
myctype
)
cdef
build_type
(
i
,
j
,
s
):
#cdef myctype x = {'i':i,'j':j,'s':s}
x
=
{
'i'
:
i
,
'j'
:
j
,
's'
:
s
}
def
build_pytype
(
i
,
j
,
s
):
build_type
(
i
,
j
,
s
)
cdef
class
pytype
(
object
):
x
=
cython
.
declare
(
myctype
)
def
__init__
(
self
,
i
,
j
,
s
):
self
.
x
=
{
'i'
:
i
,
'j'
:
j
,
's'
:
s
}
@
cython
.
locals
(
a
=
numpy
.
ndarray
)
def
__init__
(
self
,
a
):
a
=
numpy
.
asfarray
(
a
)
self
.
x
=
{
'i'
:
a
.
shape
[
0
],
'j'
:
a
.
shape
[
1
],
's'
:
<
double
*>
a
.
data
}
def
dist
(
self
):
return
math
.
sqrt
(
self
.
x
.
i
**
2
+
self
.
x
.
j
**
2
)
...
...
type.h
View file @
844bf463
typedef
struct
{
int
i
,
j
;
double
s
,
s2
;
double
*
s
;
}
myctype
;
//void init_type(int n, int i, int j);
...
...
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