Last night I ran into this problem with dimension(): I wanted to use primary_decomposition() to compute a primary decomposition of an ideal. In Macaulay2, the result of a call to primaryDecomposition is a list of ideals. Fine. (I actually created a class for this, BTW: m2_ideal_list and m2_ideal_list_pointer; it just seems these things will be pretty common.)
The problem became the dimension() is not vectorized in R or Macaulay2. In other words, if you have an ideal I in Macaulay2, you compute its dimension with dim(I). But if it's a List whose elements are ideals, that won't work, and instead you have to use apply(i, dim), so I baked that into dimension(): it now works on ideals and lists of ideals.
I think the same behavior should apply more broadly. Off the top of my head, we have functions like factor_poly() which wraps the M2 code factor(poly), but if you give it a mpolyList or a character vector of poly's, I expect it to error. I think it would be more sensible to have Macaulay2 vectorize it. So: check if the thing is a vector, and if it is use Macaulay2's apply(x, f) construct to get the job done.
Thoughts?
Last night I ran into this problem with
dimension(): I wanted to useprimary_decomposition()to compute a primary decomposition of an ideal. In Macaulay2, the result of a call toprimaryDecompositionis a list of ideals. Fine. (I actually created a class for this, BTW:m2_ideal_listandm2_ideal_list_pointer; it just seems these things will be pretty common.)The problem became the
dimension()is not vectorized in R or Macaulay2. In other words, if you have an idealIin Macaulay2, you compute its dimension withdim(I). But if it's aListwhose elements are ideals, that won't work, and instead you have to useapply(i, dim), so I baked that intodimension(): it now works on ideals and lists of ideals.I think the same behavior should apply more broadly. Off the top of my head, we have functions like
factor_poly()which wraps the M2 codefactor(poly), but if you give it ampolyListor a character vector of poly's, I expect it to error. I think it would be more sensible to have Macaulay2 vectorize it. So: check if the thing is a vector, and if it is use Macaulay2'sapply(x, f)construct to get the job done.Thoughts?