Skip to content

Commit 1567d06

Browse files
committed
Implement fit! for Polynomial
1 parent 0131cad commit 1567d06

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/poly.jl

+25
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,31 @@ function fit(model::Polynomial, data)
4343
FittedPolynomial(model, state)
4444
end
4545

46+
function fit!(fitted::FittedPolynomial, newdata)
47+
model = fitted.model
48+
state = fitted.state
49+
50+
# check compatibility of data size
51+
checkdatasize(fitted, newdata)
52+
53+
# update state data
54+
state.data = newdata
55+
56+
# set coordinate matrix
57+
setproj!(model, state.proj, newdata)
58+
59+
nothing
60+
end
61+
62+
function checkdatasize(fitted::FittedPolynomial, data)
63+
proj = fitted.state.proj
64+
nproj = size(proj, 2)
65+
nobs = nrow(data)
66+
if nobs > nproj
67+
throw(ArgumentError("in-place fit called with $nobs data row(s) and $nproj maximum size"))
68+
end
69+
end
70+
4671
function prealloc(model::Polynomial, data)
4772
# retrieve parameters
4873
deg = model.degree

0 commit comments

Comments
 (0)