How often do you think people want to compute the image under the identity 
map? If that is a common code path you could just have an cached 
is_identity() and check it before doing the matrix multiplication. 

Writing a specialization for a particular value precisely saves you that 
one check of a boolean flag at the end of the day. Unless you have 
benchmarked the need for this minor optimization it you are almost 
certainly wasting your time.



On Wednesday, February 4, 2015 at 11:47:07 AM UTC-5, Eric Gourgoulhon wrote:
>
> As for the "identity map" example, if that were a subclass then you would 
>> also have to check that a map is the identity whenever you compose maps and 
>> construct the subclass. From a performance point of view that is most 
>> likely sub-optimal.
>>
>
> Well, probably this depends on the use case, i.e. if you compose maps more 
> often than you use them to get images of elements of their domains. If the 
> latter operation is performed, let's say, via some matrix multiplication, 
> it is clear that having def __call__(x): return x is more efficient than 
> multiplying by the identity matrix. 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To post to this group, send email to sage-devel@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-devel.
For more options, visit https://groups.google.com/d/optout.

Reply via email to