problem with between

Asked by Chaffra Affouda

Hi, can anyone reproduce the example below. It seem between is not always inclusive. Is this a bug?
Thanks, Chaffra

from dolfin.cpp import between

print "between(0,0.5,0.5) = ", between(0,0.5,0.5) #returns True, OK
print "between(0.5,0.5,1) = ", between(0.5,0.5,1) #returns True, OK

print "between(0,5,5) = ", between(0,5,5) #returns False but should be True
print "between(5,5,10) = ", between(5,5,10) #returns False but should be True

Question information

Language:
English Edit question
Status:
Solved
For:
DOLFIN Edit question
Assignee:
No assignee Edit question
Solved by:
Garth Wells
Solved:
Last query:
Last reply:
Revision history for this message
Chaffra Affouda (chaffra) said :
#1

The same way,

near(2,2) return True but near(4,4) returns False. This is strange, I must be missing something.

Revision history for this message
Johan Hake (johan-hake) said :
#2

I think you need to use floats. There might be some unpredictable behaviour
when the python ints are cast to doubles. We might want to add an int version
of these functions too...

But! These functions are gone in the development version. They were removed in
revision 5923 when the Legendre code was removed. Was this intentional Garth?

Johan

On Monday June 20 2011 10:45:54 Chaffra wrote:
> Question #162103 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/162103
>
> Chaffra gave more information on the question:
> The same way,
>
> near(2,2) return True but near(4,4) returns False. This is strange, I
> must be missing something.

Revision history for this message
Best Garth Wells (garth-wells) said :
#3

On 20/06/11 19:01, Johan Hake wrote:
> Question #162103 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/162103
>
> Status: Open => Answered
>
> Johan Hake proposed the following answer:
> I think you need to use floats. There might be some unpredictable behaviour
> when the python ints are cast to doubles. We might want to add an int version
> of these functions too...
>
> But! These functions are gone in the development version. They were removed in
> revision 5923 when the Legendre code was removed. Was this intentional Garth?
>

Yes.

The functions were present to support extended precision comparisons,
but extended precision support has been removed.

Garth

> Johan
>
> On Monday June 20 2011 10:45:54 Chaffra wrote:
>> Question #162103 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/162103
>>
>> Chaffra gave more information on the question:
>> The same way,
>>
>> near(2,2) return True but near(4,4) returns False. This is strange, I
>> must be missing something.
>

Revision history for this message
Anders Logg (logg) said :
#4

On Mon, Jun 20, 2011 at 06:01:33PM -0000, Johan Hake wrote:
> Question #162103 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/162103
>
> Status: Open => Answered
>
> Johan Hake proposed the following answer:
> I think you need to use floats. There might be some unpredictable behaviour
> when the python ints are cast to doubles. We might want to add an int version
> of these functions too...
>
> But! These functions are gone in the development version. They were removed in
> revision 5923 when the Legendre code was removed. Was this intentional Garth?

I hadn't noticed. I think they should be included, and they are
already included in the book.

--
Anders

> Johan
>
> On Monday June 20 2011 10:45:54 Chaffra wrote:
> > Question #162103 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/162103
> >
> > Chaffra gave more information on the question:
> > The same way,
> >
> > near(2,2) return True but near(4,4) returns False. This is strange, I
> > must be missing something.
>

Revision history for this message
Chaffra Affouda (chaffra) said :
#5

Thanks Garth Wells, that solved my question.

Revision history for this message
Anders Logg (logg) said :
#6

On Mon, Jun 20, 2011 at 06:11:15PM -0000, Garth Wells wrote:
> Question #162103 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/162103
>
> Garth Wells proposed the following answer:
>
> On 20/06/11 19:01, Johan Hake wrote:
> > Question #162103 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/162103
> >
> > Status: Open => Answered
> >
> > Johan Hake proposed the following answer:
> > I think you need to use floats. There might be some unpredictable behaviour
> > when the python ints are cast to doubles. We might want to add an int version
> > of these functions too...
> >
> > But! These functions are gone in the development version. They were removed in
> > revision 5923 when the Legendre code was removed. Was this intentional Garth?
> >
>
> Yes.
>
> The functions were present to support extended precision comparisons,
> but extended precision support has been removed.

I thought they were generally useful for setting boundary
conditions etc without needing to use DOLFIN_EPS.

It's used in the book:

for facet in facets(mesh):
    p = facet.midpoint()
    if near(p.y(), 0.0) or near(p.y(), 1.0):
        boundary_markers[facet] = 1

Could you please add it back?

--
Anders

> Garth
>
> > Johan
> >
> > On Monday June 20 2011 10:45:54 Chaffra wrote:
> >> Question #162103 on DOLFIN changed:
> >> https://answers.launchpad.net/dolfin/+question/162103
> >>
> >> Chaffra gave more information on the question:
> >> The same way,
> >>
> >> near(2,2) return True but near(4,4) returns False. This is strange, I
> >> must be missing something.
> >
>

Revision history for this message
Garth Wells (garth-wells) said :
#7

On 20/06/11 19:15, Anders Logg wrote:
> Question #162103 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/162103
>
> Anders Logg proposed the following answer:
> On Mon, Jun 20, 2011 at 06:01:33PM -0000, Johan Hake wrote:
>> Question #162103 on DOLFIN changed:
>> https://answers.launchpad.net/dolfin/+question/162103
>>
>> Status: Open => Answered
>>
>> Johan Hake proposed the following answer:
>> I think you need to use floats. There might be some unpredictable behaviour
>> when the python ints are cast to doubles. We might want to add an int version
>> of these functions too...
>>
>> But! These functions are gone in the development version. They were removed in
>> revision 5923 when the Legendre code was removed. Was this intentional Garth?
>
> I hadn't noticed. I think they should be included, and they are
> already included in the book.
>

We can grep the book to remove them.

Garth

> --
> Anders
>
>
>> Johan
>>
>> On Monday June 20 2011 10:45:54 Chaffra wrote:
>>> Question #162103 on DOLFIN changed:
>>> https://answers.launchpad.net/dolfin/+question/162103
>>>
>>> Chaffra gave more information on the question:
>>> The same way,
>>>
>>> near(2,2) return True but near(4,4) returns False. This is strange, I
>>> must be missing something.
>>
>

Revision history for this message
Johan Hake (johan-hake) said :
#8

On Monday June 20 2011 11:11:15 Garth Wells wrote:
> Question #162103 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/162103
>
> Garth Wells proposed the following answer:
>
> On 20/06/11 19:01, Johan Hake wrote:
> > Question #162103 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/162103
> >
> > Status: Open => Answered
> >
> > Johan Hake proposed the following answer:
> > I think you need to use floats. There might be some unpredictable
> > behaviour when the python ints are cast to doubles. We might want to add
> > an int version of these functions too...
> >
> > But! These functions are gone in the development version. They were
> > removed in revision 5923 when the Legendre code was removed. Was this
> > intentional Garth?
>
> Yes.
>
> The functions were present to support extended precision comparisons,
> but extended precision support has been removed.

As Anders says, they were included to make comparison between coordinates in
boundary calculations easier and less error prone. There were also just a
double version of each, so they had nothing to do with extended precision
comparisions.

Johan

>
> Garth
>
> > Johan
> >
> > On Monday June 20 2011 10:45:54 Chaffra wrote:
> >> Question #162103 on DOLFIN changed:
> >> https://answers.launchpad.net/dolfin/+question/162103
> >>
> >> Chaffra gave more information on the question:
> >> The same way,
> >>
> >> near(2,2) return True but near(4,4) returns False. This is strange, I
> >> must be missing something.

Revision history for this message
Anders Logg (logg) said :
#9

On Mon, Jun 20, 2011 at 06:35:53PM -0000, Garth Wells wrote:
> Question #162103 on DOLFIN changed:
> https://answers.launchpad.net/dolfin/+question/162103
>
> Garth Wells posted a new comment:
>
> On 20/06/11 19:15, Anders Logg wrote:
> > Question #162103 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/162103
> >
> > Anders Logg proposed the following answer:
> > On Mon, Jun 20, 2011 at 06:01:33PM -0000, Johan Hake wrote:
> >> Question #162103 on DOLFIN changed:
> >> https://answers.launchpad.net/dolfin/+question/162103
> >>
> >> Status: Open => Answered
> >>
> >> Johan Hake proposed the following answer:
> >> I think you need to use floats. There might be some unpredictable behaviour
> >> when the python ints are cast to doubles. We might want to add an int version
> >> of these functions too...
> >>
> >> But! These functions are gone in the development version. They were removed in
> >> revision 5923 when the Legendre code was removed. Was this intentional Garth?
> >
> > I hadn't noticed. I think they should be included, and they are
> > already included in the book.
>
> We can grep the book to remove them.

Yes, I'm sure, but my point is that they are useful so I would like to
keep them both in the code and in the book.

--
Anders

> Garth
>
> >> Johan
> >>
> >> On Monday June 20 2011 10:45:54 Chaffra wrote:
> >>> Question #162103 on DOLFIN changed:
> >>> https://answers.launchpad.net/dolfin/+question/162103
> >>>
> >>> Chaffra gave more information on the question:
> >>> The same way,
> >>>
> >>> near(2,2) return True but near(4,4) returns False. This is strange, I
> >>> must be missing something.
> >>
> >
>

Revision history for this message
Chaffra Affouda (chaffra) said :
#10

In any case they do not work for me even when I am using floats: between(5.0,5.0,10.0) still returns False.

Revision history for this message
Anders Logg (logg) said :
#11

On Mon, Jun 20, 2011 at 08:38:41PM +0200, Anders Logg wrote:
> On Mon, Jun 20, 2011 at 06:35:53PM -0000, Garth Wells wrote:
> > Question #162103 on DOLFIN changed:
> > https://answers.launchpad.net/dolfin/+question/162103
> >
> > Garth Wells posted a new comment:
> >
> > On 20/06/11 19:15, Anders Logg wrote:
> > > Question #162103 on DOLFIN changed:
> > > https://answers.launchpad.net/dolfin/+question/162103
> > >
> > > Anders Logg proposed the following answer:
> > > On Mon, Jun 20, 2011 at 06:01:33PM -0000, Johan Hake wrote:
> > >> Question #162103 on DOLFIN changed:
> > >> https://answers.launchpad.net/dolfin/+question/162103
> > >>
> > >> Status: Open => Answered
> > >>
> > >> Johan Hake proposed the following answer:
> > >> I think you need to use floats. There might be some unpredictable behaviour
> > >> when the python ints are cast to doubles. We might want to add an int version
> > >> of these functions too...
> > >>
> > >> But! These functions are gone in the development version. They were removed in
> > >> revision 5923 when the Legendre code was removed. Was this intentional Garth?
> > >
> > > I hadn't noticed. I think they should be included, and they are
> > > already included in the book.
> >
> > We can grep the book to remove them.
>
> Yes, I'm sure, but my point is that they are useful so I would like to
> keep them both in the code and in the book.

near() and between() are now added back.

--
Anders