comparison @pyobject/pyobject.m @ 356:6cd581661176

pyobject.int64: New method to convert integer object to Octave int64 * __py_struct_from_dict__.cc (F__py_int64_scalar_value__): New function to extract int64 scalar value from a pyobject. * @pyobject/pyobject.m: Add conversion method int64 as a wrapper around __py_int64_scalar_value__. Add %!tests of int64 value extraction.
author Mike Miller <mtmiller@octave.org>
date Mon, 22 Aug 2016 17:33:20 -0700
parents e89a8a37fd8a
children d41fc23d4b9f
comparison
equal deleted inserted replaced
355:8cdc94b83e98 356:6cd581661176
136 else 136 else
137 y = pycall ("float", x); 137 y = pycall ("float", x);
138 endif 138 endif
139 endfunction 139 endfunction
140 140
141 function y = int64 (x)
142 y = __py_int64_scalar_value__ (x);
143 endfunction
144
141 function y = struct (x) 145 function y = struct (x)
142 y = __py_struct_from_dict__ (x); 146 y = __py_struct_from_dict__ (x);
143 endfunction 147 endfunction
144 148
145 function vargout = help (x) 149 function vargout = help (x)
342 346
343 %!error double (pyobject ("this is not a number")) 347 %!error double (pyobject ("this is not a number"))
344 %!error double (pyobject ()) 348 %!error double (pyobject ())
345 %!error double (pyeval ("[1, 2, 3]")) 349 %!error double (pyeval ("[1, 2, 3]"))
346 350
351 ## Test conversion method pyobject.int64
352 %!assert (int64 (pyobject (int8 (0))), int64 (0))
353 %!assert (int64 (pyobject (int64 (42))), int64 (42))
354 %!assert (int64 (pyobject (intmax ("int64"))), intmax ("int64"))
355 %!assert (int64 (pyobject (intmin ("int64"))), intmin ("int64"))
356 %!assert (int64 (pycall ("int", 1e100)), intmax ("int64"))
357 %!assert (int64 (pycall ("int", -1e100)), intmin ("int64"))
358
347 ## Test conversion method pyobject.struct 359 ## Test conversion method pyobject.struct
348 %!assert (struct (pycall ("dict")), struct ()) 360 %!assert (struct (pycall ("dict")), struct ())
349 %!assert (struct (pyobject (struct ())), struct ()) 361 %!assert (struct (pyobject (struct ())), struct ())
350 %!test 362 %!test
351 %! a = struct ("a", 1, "b", 2, "three", 3); 363 %! a = struct ("a", 1, "b", 2, "three", 3);