Skip to content

Commit c4f0fb6

Browse files
ggcrunchypavanky
authored andcommitted
Oops, had a bunch of methods bound wrong
They were bound as if returned arrays, when they only returned scalars. Added - Somewhat more aggressive error reporting on bad calls. - Removed superfluous print
1 parent 7d28a45 commit c4f0fb6

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

wrapper/arrayfire/impl/array.lua

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,30 @@ local MetaValue = {}
3434

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

37+
--
38+
local function ErrorOut (what)
39+
if traceback then
40+
print(traceback())
41+
end
42+
43+
error(what)
44+
end
45+
3746
--
3847
local function CallFromName_Checked (name, ...)
39-
if type(name) ~= "string" then
40-
if traceback then
41-
print(traceback())
42-
end
48+
local func = af[name]
4349

44-
error("Expected string name, got: " .. tostring(name))
50+
if type(func) ~= "function" then
51+
if type(name) ~= "string" then
52+
ErrorOut("Expected string name, got: " .. tostring(name))
53+
else
54+
ErrorOut(name .. " is not a function")
55+
end
4556
end
4657

4758
Name = name
4859

49-
return _CheckError_(af[name](...))
60+
return _CheckError_(func(...))
5061
end
5162

5263
--

wrapper/arrayfire/methods/methods.lua

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ function M.Add (array_module, meta)
1818
local GetLib = array_module.GetLib
1919

2020
--
21-
local function Wrap (name)
21+
local function Get (name)
2222
name = "af_" .. name
2323

2424
return function(arr)
25-
return CallWrap(name, arr:get())
25+
return Call(name, arr:get())
2626
end
2727
end
2828

@@ -53,7 +53,9 @@ function M.Add (array_module, meta)
5353
end,
5454

5555
--
56-
copy = Wrap("copy_array"),
56+
copy = function(arr)
57+
return CallWrap("af_copy_array", arr:get())
58+
end,
5759

5860
--
5961
dims = function(arr, i)
@@ -65,51 +67,51 @@ function M.Add (array_module, meta)
6567
end,
6668

6769
--
68-
elements = function(arr)
69-
return Call("af_get_elements", arr:get())
70-
end,
70+
elements = Get("get_elements"),
7171

7272
--
73-
eval = Wrap("eval"),
73+
eval = function(arr)
74+
Call("af_eval", arr:get())
75+
end,
7476

7577
--
7678
get = array_module.GetHandle,
7779

7880
--
79-
isbool = Wrap("is_bool"),
81+
isbool = Get("is_bool"),
8082

8183
--
82-
iscolumn = Wrap("is_column"),
84+
iscolumn = Get("is_column"),
8385

8486
--
85-
iscomplex = Wrap("is_complex"),
87+
iscomplex = Get("is_complex"),
8688

8789
--
88-
isdouble = Wrap("is_double"),
90+
isdouble = Get("is_double"),
8991

9092
--
91-
isempty = Wrap("is_empty"),
93+
isempty = Get("is_empty"),
9294

9395
--
94-
isfloating = Wrap("is_floating"),
96+
isfloating = Get("is_floating"),
9597

9698
--
97-
isinteger = Wrap("is_integer"),
99+
isinteger = Get("is_integer"),
98100

99101
--
100-
isrealfloating = Wrap("is_real_floating"),
102+
isrealfloating = Get("is_real_floating"),
101103

102104
--
103-
isrow = Wrap("is_row"),
105+
isrow = Get("is_row"),
104106

105107
--
106-
isscalar = Wrap("is_scalar"),
108+
isscalar = Get("is_scalar"),
107109

108110
--
109-
issingle = Wrap("is_single"),
111+
issingle = Get("is_single"),
110112

111113
--
112-
isvector = Wrap("is_vector"),
114+
isvector = Get("is_vector"),
113115

114116
--
115117
H = function(arr)
@@ -129,7 +131,7 @@ function M.Add (array_module, meta)
129131
return GetLib().transpose(arr)
130132
end,
131133

132-
type = Wrap("get_type")
134+
type = Get("get_type")
133135
} do
134136
meta[k] = v
135137
end

0 commit comments

Comments
 (0)