Skip to content

Commit

Permalink
Oops, had a bunch of methods bound wrong
Browse files Browse the repository at this point in the history
They were bound as if returned arrays, when they only returned scalars.

Added
- Somewhat more aggressive error reporting on bad calls.
- Removed superfluous print
  • Loading branch information
ggcrunchy authored and pavanky committed Dec 23, 2015
1 parent 7d28a45 commit c4f0fb6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
23 changes: 17 additions & 6 deletions wrapper/arrayfire/impl/array.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,30 @@ local MetaValue = {}

local Constants = setmetatable({}, { __mode = "k" })

--
local function ErrorOut (what)
if traceback then
print(traceback())
end

error(what)
end

--
local function CallFromName_Checked (name, ...)
if type(name) ~= "string" then
if traceback then
print(traceback())
end
local func = af[name]

error("Expected string name, got: " .. tostring(name))
if type(func) ~= "function" then
if type(name) ~= "string" then
ErrorOut("Expected string name, got: " .. tostring(name))
else
ErrorOut(name .. " is not a function")
end
end

Name = name

return _CheckError_(af[name](...))
return _CheckError_(func(...))
end

--
Expand Down
42 changes: 22 additions & 20 deletions wrapper/arrayfire/methods/methods.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ function M.Add (array_module, meta)
local GetLib = array_module.GetLib

--
local function Wrap (name)
local function Get (name)
name = "af_" .. name

return function(arr)
return CallWrap(name, arr:get())
return Call(name, arr:get())
end
end

Expand Down Expand Up @@ -53,7 +53,9 @@ function M.Add (array_module, meta)
end,

--
copy = Wrap("copy_array"),
copy = function(arr)
return CallWrap("af_copy_array", arr:get())
end,

--
dims = function(arr, i)
Expand All @@ -65,51 +67,51 @@ function M.Add (array_module, meta)
end,

--
elements = function(arr)
return Call("af_get_elements", arr:get())
end,
elements = Get("get_elements"),

--
eval = Wrap("eval"),
eval = function(arr)
Call("af_eval", arr:get())
end,

--
get = array_module.GetHandle,

--
isbool = Wrap("is_bool"),
isbool = Get("is_bool"),

--
iscolumn = Wrap("is_column"),
iscolumn = Get("is_column"),

--
iscomplex = Wrap("is_complex"),
iscomplex = Get("is_complex"),

--
isdouble = Wrap("is_double"),
isdouble = Get("is_double"),

--
isempty = Wrap("is_empty"),
isempty = Get("is_empty"),

--
isfloating = Wrap("is_floating"),
isfloating = Get("is_floating"),

--
isinteger = Wrap("is_integer"),
isinteger = Get("is_integer"),

--
isrealfloating = Wrap("is_real_floating"),
isrealfloating = Get("is_real_floating"),

--
isrow = Wrap("is_row"),
isrow = Get("is_row"),

--
isscalar = Wrap("is_scalar"),
isscalar = Get("is_scalar"),

--
issingle = Wrap("is_single"),
issingle = Get("is_single"),

--
isvector = Wrap("is_vector"),
isvector = Get("is_vector"),

--
H = function(arr)
Expand All @@ -129,7 +131,7 @@ function M.Add (array_module, meta)
return GetLib().transpose(arr)
end,

type = Wrap("get_type")
type = Get("get_type")
} do
meta[k] = v
end
Expand Down

0 comments on commit c4f0fb6

Please sign in to comment.