Skip to content
Snippets Groups Projects
Commit a617429d authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

support functions returning doubles

parent 44720de4
No related branches found
No related tags found
No related merge requests found
...@@ -241,7 +241,7 @@ def ivectorvectordouble(name, value=None, python_value=None, julia_value=None): ...@@ -241,7 +241,7 @@ def ivectorvectordouble(name, value=None, python_value=None, julia_value=None):
class oint(arg): class oint(arg):
rcpp_type = "int" rcpp_type = "int"
rc_type = "int" rc_type = "int"
rtexi_type = "integer" rtexi_type = "integer value"
rjulia_type = "Cint" rjulia_type = "Cint"
def __init__(self, name, value=None, python_value=None, julia_value=None): def __init__(self, name, value=None, python_value=None, julia_value=None):
arg.__init__(self, name, value, python_value, julia_value, arg.__init__(self, name, value, python_value, julia_value,
...@@ -257,20 +257,24 @@ class oint(arg): ...@@ -257,20 +257,24 @@ class oint(arg):
self.julia_arg = api_name self.julia_arg = api_name
self.julia_return = api_name + "[]" self.julia_return = api_name + "[]"
def odouble(name, value=None, python_value=None, julia_value=None): class odouble(arg):
a = arg(name, value, python_value, julia_value, rcpp_type = "double"
rc_type = "double"
rtexi_type = "floating point value"
rjulia_type = "Cdouble"
def __init__(self, name, value=None, python_value=None, julia_value=None):
arg.__init__(self, name, value, python_value, julia_value,
"double &", "double *", True) "double &", "double *", True)
api_name = "api_" + name + "_" api_name = "api_" + name + "_"
a.c_arg = "*" + name self.c_arg = "*" + name
a.cwrap_arg = "&" + name self.cwrap_arg = "&" + name
a.python_pre = api_name + " = c_double()" self.python_pre = api_name + " = c_double()"
a.python_arg = "byref(" + api_name + ")" self.python_arg = "byref(" + api_name + ")"
a.python_return = api_name + ".value" self.python_return = api_name + ".value"
a.julia_ctype = "Ptr{Cdouble}" self.julia_ctype = "Ptr{Cdouble}"
a.julia_pre = api_name + " = Ref{Cdouble}()" self.julia_pre = api_name + " = Ref{Cdouble}()"
a.julia_arg = api_name self.julia_arg = api_name
a.julia_return = api_name + "[]" self.julia_return = api_name + "[]"
return a
def ostring(name, value=None, python_value=None, julia_value=None): def ostring(name, value=None, python_value=None, julia_value=None):
a = arg(name, value, python_value, julia_value, a = arg(name, value, python_value, julia_value,
...@@ -1031,7 +1035,7 @@ class API: ...@@ -1031,7 +1035,7 @@ class API:
fcwrap.write(indent + " " + a.cwrap_pre) fcwrap.write(indent + " " + a.cwrap_pre)
fcwrap.write(indent + " ") fcwrap.write(indent + " ")
if rtype: if rtype:
fcwrap.write("int result_api_ = ") fcwrap.write(rt + " result_api_ = ")
fcwrap.write(fname + "(" + ", ".join((a.cwrap_arg for a in args))) fcwrap.write(fname + "(" + ", ".join((a.cwrap_arg for a in args)))
if args: if args:
fcwrap.write(", &ierr);\n") fcwrap.write(", &ierr);\n")
...@@ -1088,14 +1092,15 @@ class API: ...@@ -1088,14 +1092,15 @@ class API:
f.write(indent + ("\n" + indent).join(textwrap.wrap(doc, 75)) + "\n") f.write(indent + ("\n" + indent).join(textwrap.wrap(doc, 75)) + "\n")
if rtype or oargs: if rtype or oargs:
f.write("\n" + indent + "Return " + ", ".join( f.write("\n" + indent + "Return " + ", ".join(
(["an " + rtype.rtexi_type] if rtype else[]) ([("an " if rtype.rtexi_type == "integer value" else "a ") +
rtype.rtexi_type] if rtype else[])
+ [("`" + a.name + "'") for a in oargs]) + [("`" + a.name + "'") for a in oargs])
+ ".\n") + ".\n")
f.write(indent + '"""\n') f.write(indent + '"""\n')
for a in args: for a in args:
if a.python_pre: f.write(indent + a.python_pre + "\n") if a.python_pre: f.write(indent + a.python_pre + "\n")
f.write(indent + "ierr = c_int()\n") f.write(indent + "ierr = c_int()\n")
f.write(indent + "api__result__ = " if rtype is oint else (indent)) f.write(indent + "api__result__ = " if ((rtype is oint) or (rtype is odouble)) else (indent))
c_name = modulepath + name[0].upper() + name[1:] c_name = modulepath + name[0].upper() + name[1:]
f.write("lib." + c_name + "(\n " + indent + f.write("lib." + c_name + "(\n " + indent +
(",\n" + indent + " ").join( (",\n" + indent + " ").join(
...@@ -1145,7 +1150,8 @@ class API: ...@@ -1145,7 +1150,8 @@ class API:
f.write("\n".join(textwrap.wrap(doc, 80)).replace("'", "`") + "\n") f.write("\n".join(textwrap.wrap(doc, 80)).replace("'", "`") + "\n")
if rtype or oargs: if rtype or oargs:
f.write("\nReturn " + ", ".join( f.write("\nReturn " + ", ".join(
(["an " + rtype.rtexi_type] if rtype else[]) ([("an " if rtype.rtexi_type == "integer value" else "a ") +
rtype.rtexi_type] if rtype else[])
+ [("`" + a.name + "`") for a in oargs]) + [("`" + a.name + "`") for a in oargs])
+ ".\n") + ".\n")
f.write('"""\n') f.write('"""\n')
...@@ -1155,7 +1161,7 @@ class API: ...@@ -1155,7 +1161,7 @@ class API:
for a in args: for a in args:
if a.julia_pre: f.write(" " + a.julia_pre + "\n") if a.julia_pre: f.write(" " + a.julia_pre + "\n")
f.write(" ierr = Ref{Cint}()\n ") f.write(" ierr = Ref{Cint}()\n ")
f.write("api__result__ = " if rtype is oint else "") f.write("api__result__ = " if ((rtype is oint) or (rtype is odouble)) else "")
c_name = c_mpath + name[0].upper() + name[1:] c_name = c_mpath + name[0].upper() + name[1:]
f.write("ccall((:" + c_name + ", " + f.write("ccall((:" + c_name + ", " +
("" if c_mpath == ns else ns + ".") + "lib), " + ("" if c_mpath == ns else ns + ".") + "lib), " +
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment