Yes, but it duplicates the code horribly. Because orthogonal_array is a long sequence of tests and answers
Besides, this is pretty clear :
sage: designs.orthogonal_array(4,3,existence=True)
True
Volker, you should read the code, and then we discuss it.
> Just because you can (in Python) doesn't mean that its a good idea.Just because you tell me I can't does not mean that it is a bad idea either.
> But the fact that it interacts badly with decorators should be a hint that my argument is true nevertheless.
Why should it be ? We write functions, we update them, we change them
If I do that as in your example, then I have on one side the tests
corresponding to each construction, and on the other side the
functions corresponding to the tests
Note that it changes nothing to my caching problem
@cached_function
def is_construction_possible(n):
if whatever:
return actual_construction #just the function
No, you haven't read what I wrote. In English, "is possible" asks for a boolean outcome, so is_possible() shall return a boolean.Here is again what I originally wrote, maybe you'll read it this time:
def work_for_case_1():return long_computation_1()def work_for_case_2():return long_computation_2()def _select_case():if case1:return work_for_case_1elif case2:return work_for_case_2else:raise NotImplementedErrordef orthogonal_array():return _select_case()()def is_constructible():try:_select_case()return Trueexcept NotImplementedError:return False
--
You received this message because you are subscribed to a topic in the Google Groups "sage-devel" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sage-devel/OPe5VJpBiB4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sage-devel+...@googlegroups.com.
To post to this group, send email to sage-...@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.
On the other hand the best for me would be that you would all come to your senses and accept the idea that filtering what you want to cache is a good idea.
I would accept the argument of "speed issue", but of course you cannot use that one AND defend the "key" parameter, which has an easier workaround than my problem here and a higher cost. So it is both or none, see ? :-P
> If
> designs.orthogonal_array doesn't return some kind of array then it is poorly
> named. Use three different functions, e.g. orthogonal_array() /
> is_constructible() / size_of_array()
>
> This basic design pattern also fixes your caching problem.
Yes, but it duplicates the code horribly. Because orthogonal_array is a long sequence of tests and answers,and you do not want to find this long collection of tests and answers copied and pasted into three different functions, nor to find out that "for some reason" they are not always consistent with each other.
More precisely :
> designs.orthogonal_array doesn't return some kind of array then it is poorly named
No. Because if you want to build orthogonal arrays, you *will* find a function named orthogonal_array. You may not find a function named size_of_maximal_orthogonal_array.
By the way, I love how nobody has a problem with
sage: designs.OrthogonalArray(4,3).exists()
True
sage: designs.OrthogonalArray(4,3).matrix()
BigMatrix
while on the other hand
sage: designs.orthogonal_array(4,3,existence=True)
True
sage: designs.orthogonal_array(4,3)
BigMatrix
is "clearly bad design". Come on guys, we write Python code ! The point is not only to make our code dead slow, it is ALSO to use the advantages of the language. Stop writing Java and C wrapped in Python ! Do you complain when "wc -l" returns an integer and "wc" returns three integers and a filename ? Do you prefer wc.complete_info() and wc.just_the_number_of_lines() ?
Nevertheless, there is an intermediate solution which I proposed
recently in #16347 comment:12. Let me repeat it here. Instead of
returning an OA or a boolean we can write a function
"orthogonal_array_construction(k, n)" whose specification would be
"return a pair (f, args) such that f(*args) is an OA(k,n) or return
None if Sage has no idea how to build it". That way, even the internal
function would be clean.
For the external, as Nathann already said, multiplying the namespace with
designs.orthogonal_array(k, n)
designs.orthogonal_array_existence(k, n)
designs.orthogonal_array_maximum_size(n)
looks ugly to me as there are many combinatorial designs on which you
would have the same.
Note that I would also need to triple MANY functions in the graph code, for the very reason that you insist on writing Python code as if it were C code.
I have been doing this in the Graph code for years. And I think that I remember how it began :It was the early days of Linear Programming. I was writing functions to solve NP hard stuff, returning partitions of vertices or list of vertices, and though that perhaps I could save this with a "value_only" flag. When a graph function has such a flag, it means that it will not return the actual list of vertices, but its size instead.This, because in the optimization world, we deal with existence problems. And existence problems have what is called a "certificate", ie "some information which can be used to check, in polynomial time, that the answer given to the decision problem is right".Thus in the graph code you will have functions with a "certificate" flag, others with a "value_only" flag. And their output changes according to that.Python is *NOT* typed. Accept it.
I don't want to have to create objects that will be only used to access methods.If I create those objects, I will need to write a OrthogonalArray class, a TransversalDesign class, and these objects (which, currently, are lists of lists) will HAVE to be immutable.
Those are all the changes that are triggered if I have to use those cursed objects where they don't belong.
> (And ones that also don't use
> "who_asked", a purely internal thing - that should be some internal
> attribute, not a keyword.)This keyword is used to break infinite recursions. If you see a way around I am interested.
I don't mind the work if it makes sense. But having to pick a worse data structure and having to generate useless objects just because you cannot stand a syntax that the language allows really is bad work.
Please don't consider sage/combinat/designs/ as part of the combinat/ code :-P
But right now, what Nathann is trying to do is rather orthogonal to
these questions. If somebody comes with a nice class that *does not*
slow down his construction code, everybody will be happy. Sage is open
to contributions and not only to critics ;-P
Thanks for having a look into this.