![]() |
Blitz Support : |
From: Navneet Dalal (navneet.dalal_at_[hidden])
Date: 2003-09-16 07:18:59
Hi,
> The main reason not to pass by const reference here is that for the most
> typical case where the argument type is a built-in numerical type, it
> will be *slower* than passing by value because of the work required to
> access the referenced memory. It doesn't make sense to make the most
> common case less efficient, so that rare cases might go faster. If
> others here on the list have a different take on this, please chime in,
> but that is my understanding of this issue and why the code is written
> the way it is.
This makes more sense to me. Thanks.
>>>> 4. in file array_impl.h, isInRange should be changed to
>>>>
>>>> template<class T>
>>>> _bz_bool isInRange(const TinyVector<T,N_rank>& index) const
>>>> // Was : _bz_bool isInRange(const T_index& index) const
>>>>
>>>>
>>>> This will allow to check range for TinyVector values of types double.
>>>> T_index is typedef to TinyVector<int, rank>.
>>>>
>>> The reason why this is limited to TinyVectors of ints is that blitz
>>> Arrays can only
>>> be indexed with int arguments. Indexing an Array with floating-point
>>> indices is
>>> not defined. Thus, there is really no purpose to checking whether a
>>> TinyVector
>>> of doubles falls within the index domain of an Array (at least, none
>>> that I can think of).
>>> Of course, if you *really* need to do this, you can loop over the
>>> elements of your
>>> TinyVector and check that each value lies between base(d) and base(d)
>>> +length(d).
>>
>>
>> I use blitz in image processing. Frequently, I need to check if a point
>> (of double)
>> is in domain of image-space (i.e. blitz array). So here is the need.
>>
>> Ofcourse, one can loop over the elements, but if one looks isInrange
>> function code, then this
>> is exactly what is written. My policy in this manner is, if one can
>> avoid rewriting the same code again and again, one should avoid (esp if
>> it is already present in the library).
>> And further, I donot see any problems with this change. It is a small
>> extension without any compromise on efficiency.
>>
>> In fact, I feel that all overloaded isInRange functions should accept
>> template arguments.
>>
> I agree that this change would not harm efficiency. But if you look at
> the code comments, you will see that these isInRange() functions are
> meant to be internal debugging functions. They are used solely to check
> Array indexing arguments before an indexing operation is done. These
> checks are performed only when Blitz is compiled in debug mode. The
> isInRange() functions are not listed in the Blitz library documentation,
> and I believe they were never intended for end users. (Todd, am I wrong
> here?) Thus, if anything, these functions should be made "private" to
> the Array class. I am loathe to extend parts of Blitz that aren't part
> of the official interface, especially when the existing interface already
> provides a means of performing a task. Nothing is stopping you from
> writing the function that takes a Blitz Array and a TinyVector of doubles
> and tests whether the point is within the domain of the Array. I don't
> think this needs to be part of the Array interface.
Julian, I agree with your comments. However, I think that blitz arrays (or
all array libraries)
should have bound checking functions and these functions should be part
of a release. Rest is for blitz-community to decide.
thanks
navneet