By default, I mean if use_numba=False and reshape_vecs=True.
Previously, only ndarrays could be passed as vector args to generated code. However, lists in python are ubiquitous and natural, so it would be good for our generated functions to accept them.
So, this commit allows generated functions to accept lists for matrix arguments when the argument is either a row vector or a column vector.
Nested lists are not accepted to represent matrices because I simply did not consider that until right now. (Perhaps we should add that?)
PythonConfig.use_numba must be False because list arguments have been deprecated in numba (instead you should use numba.typed.List, but if you have to use that you might as well use numpy.ndarray as far as I can tell).
PythonConfig.reshape_vecs must be True because accepting lists requires conversion to an ndarray and reshaping, which is presumably more or less the entire thing meant to be avoided by setting reshape_vecs to False.
This change did involve mucking up a bit the python util.jinja type printing macros, as a sf.Matrix type should be rendered as an numpy.ndarray is it is a return type, reshape_vectors=False, use_numba=True, or is not a row or column vector, and rendered as T.Union[T.Sequence[float], numpy.ndarray] otherwise.
By default, I mean if
use_numba=False
andreshape_vecs=True
.Previously, only ndarrays could be passed as vector args to generated code. However, lists in python are ubiquitous and natural, so it would be good for our generated functions to accept them.
So, this commit allows generated functions to accept lists for matrix arguments when the argument is either a row vector or a column vector.
Nested lists are not accepted to represent matrices because I simply did not consider that until right now. (Perhaps we should add that?)
PythonConfig.use_numba
must beFalse
because list arguments have been deprecated in numba (instead you should usenumba.typed.List
, but if you have to use that you might as well usenumpy.ndarray
as far as I can tell).PythonConfig.reshape_vecs
must beTrue
because accepting lists requires conversion to an ndarray and reshaping, which is presumably more or less the entire thing meant to be avoided by settingreshape_vecs
toFalse
.This change did involve mucking up a bit the python
util.jinja
type printing macros, as asf.Matrix
type should be rendered as annumpy.ndarray
is it is a return type,reshape_vectors=False
,use_numba=True
, or is not a row or column vector, and rendered asT.Union[T.Sequence[float], numpy.ndarray]
otherwise.