Closed multimeric closed 3 years ago
I agree that the Fit
's owning of a reference to the originating Model
is a bit awkward, although it's not obvious to me how to best de-couple it (or if it should in fact be completely de-coupled). I can imagine an application that runs fits with different settings to compare the results; for such a situation I don't think we'd want to take ownership of the data and force the user to clone a potentially large dataset. I also don't think a Fit
is sensibly defined without the Model
it originates from, so I think that forcing the user to pass a Model
into every call would permit nonsensical use (not to mention it's un-ergonomic).
I can think of two suggestions, depending on your use-case:
Array
rather than a value. The Fit
you get will store a reference to that data anyway. (Do you run into any issues with this approach?)FitSummary
class that holds all the quantities you're interested in and return that instead. Then you will no longer need the data to be in memory and it will be dropped when your function returns.Both good suggestions, and I take your point about it being nonsensical to allow for the wrong model to be passed in. Considering this, the current functionality is probably fine.
I encountered an annoying case where I wanted to write a function that was basically
fn(data: Array2<T>) -> Fit<Linear, T>
. Unfortunately theFit
struct holds a reference to theModel
used to create it, so it's basically impossible to return theFit
at all. The best you could do is useowning_ref
to return both together, but this is certainly awkward. I could of course return just the model, but then I have to callfit()
and therefor re-run the substantial processing involved each time I want access to theFit
. Can you think of a way to make this use case a bit nicer? Maybe removing theModel
reference fromFit
, and instead make it an argument to the functions that require it?