The NMatrix constructor is up for a re-factoring. Clearly no one but me uses the current initialize, which is
NMatrix.new(stype, shape, c, dtype)
- with optional stype defaulting to :dense, and
- with optional c as the initial capacity for yale, the default value for a list matrix, or an initial array or value for dense, and
- with dtype optional for dense or list when c is provided, and never optional for yale.
This has the following problems:
- It confuses new users that c can mean so many things.
- It's slow.
- It's currently not possible to control Yale's default value, except via #cast, but it should be.
I propose that we rewrite this constructor to be as clear and fast as possible and then make use of it in each of the shortcuts (zeros, ones, N[], etc.).
Here are the parameters that should be provided:
- stype mandatory
- initial_capacity for Yale (technically can be thought of as 0 for list and #size for dense)
- default_value (optional; 0 for yale/list, 0 for :object or :rational dense, undefined for other dense)
- default_array (allows us to pass in an Array of initial values to be repeated throughout the matrix; overrides default_value for dense)
- dtype (can be extrapolated from default_value/default_array)
- initial_capacity (optional and ignored for non-Yale types)
I suspect an options hash will be slow, but would probably be the clearest way to set all of these options. I want fast. I'm tempted to just ask for all six values and ignore those that are irrelevant.
We'll probably still allow the old type of construction too, for backwards compatibility.
Thoughts?
John