Sometimes, it is convenient to create an empty polynomial system (for example, in my case the input polynomials are of two possible kinds, each will be assembled into a PolynomialSystem, but it might very well be the case that one of the two kinds is not available).
This can be done manually: PolynomialSystem{0,NVars,NParams,Tuple{}}(Tuple{}()), but using the convenience constructors will fail, as they try to access the first polynomial in the system.
Note here that just because the systems does not have any polynomials does not mean that it also has no variables or parameters if they were specified manually.
Of course, it then remains to think about the behavior of the functions (which is why I don't do a pull request but would like to discuss this first):
- The mutating variants (I checked
evaluate!, jacobian!, hessian!) all work nicely; they check that the output is large enough to hold the number of variables and then are no-ops. They do not check that the number of inputs is equal to the number of variables.
- The allocating variants are more difficult:
evaluate on such an empty system will always give Union{}[] (if the argument was an arbitrarly-typed AbstractVector), or SVector{0,Union{}}() (if the argument was an arbitrarily-typed SVector). Given that the type of coefficients is unknown, this is probably the most general thing that can be returned, though there could be two alternatives: nothing or a Vector/SVector typed with the eltype of the input. No check on the length of the input is performed.
- The allocating
jacobian currently fails, as assemble_matrix does not work with a zero dimension.
Sometimes, it is convenient to create an empty polynomial system (for example, in my case the input polynomials are of two possible kinds, each will be assembled into a
PolynomialSystem, but it might very well be the case that one of the two kinds is not available).This can be done manually:
PolynomialSystem{0,NVars,NParams,Tuple{}}(Tuple{}()), but using the convenience constructors will fail, as they try to access the first polynomial in the system.Note here that just because the systems does not have any polynomials does not mean that it also has no variables or parameters if they were specified manually.
Of course, it then remains to think about the behavior of the functions (which is why I don't do a pull request but would like to discuss this first):
evaluate!,jacobian!,hessian!) all work nicely; they check that the output is large enough to hold the number of variables and then are no-ops. They do not check that the number of inputs is equal to the number of variables.evaluateon such an empty system will always giveUnion{}[](if the argument was an arbitrarly-typedAbstractVector), orSVector{0,Union{}}()(if the argument was an arbitrarily-typedSVector). Given that the type of coefficients is unknown, this is probably the most general thing that can be returned, though there could be two alternatives:nothingor aVector/SVectortyped with theeltypeof the input. No check on the length of the input is performed.jacobiancurrently fails, asassemble_matrixdoes not work with a zero dimension.