Static method for returning CommonVars

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Static method for returning CommonVars

igitur
Hi all,

In preparation for some future development (including the long-awaited fix for the inflation reference period that Peter and I discussed a while back), I want to first add some tests to the inflationcpibond.cpp file. My new tests will be based on South African CPI bonds and I thought it would be good to move the CommonVars constructor to a static method for returning the current UK-related data and then later do a similar static method for South African related data.


What I did there was just the first part of my goal. I moved the CommonVars struct constructor to a static method UKVars that returns the UK-data.  This compiles, but for some reason the test fails. It looks like the link between the zero inflation index and PiecewiseZeroInflationCurve is broken. I can't figure out how to get the tests to work again. 

I suspect this is more of a C++ query than a QuantLib query, but I'd appreciate your help.

thanks
Francois Botha

------------------------------------------------------------------------------

_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Static method for returning CommonVars

Peter Caspers-4
Hi Francois,

I merged the commit you mention into Luigi's current master and there
does not seem to be any problem. The test case runs fine, also
memcheck does not detect any problem. I ran the tests on the branch
"francois" in my repository, if you want to cross check. The problem
on your side seems to come from another difference ?

Best regards
Peter


On 11 September 2015 at 10:50, Francois Botha <[hidden email]> wrote:

> Hi all,
>
> In preparation for some future development (including the long-awaited fix
> for the inflation reference period that Peter and I discussed a while back),
> I want to first add some tests to the inflationcpibond.cpp file. My new
> tests will be based on South African CPI bonds and I thought it would be
> good to move the CommonVars constructor to a static method for returning the
> current UK-related data and then later do a similar static method for South
> African related data.
>
> Please have a look at this commit:
> https://github.com/igitur/quantlib/commit/6dc07bcb465f632017ea037b243c691eef42fbcc
>
> What I did there was just the first part of my goal. I moved the CommonVars
> struct constructor to a static method UKVars that returns the UK-data.  This
> compiles, but for some reason the test fails. It looks like the link between
> the zero inflation index and PiecewiseZeroInflationCurve is broken. I can't
> figure out how to get the tests to work again.
>
> I suspect this is more of a C++ query than a QuantLib query, but I'd
> appreciate your help.
>
> thanks
> Francois Botha
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>

------------------------------------------------------------------------------
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Static method for returning CommonVars

igitur
Thanks, you're right! I tried it now at home on LInux / gcc / Boost 1.57 and there is no problem. 

I got the problem on my office PC, with MSVC, Boost 1.58. I think the problem lies there somewhere.

thanks for your help.

Francois Botha

On 11 September 2015 at 22:02, Peter Caspers <[hidden email]> wrote:
Hi Francois,

I merged the commit you mention into Luigi's current master and there
does not seem to be any problem. The test case runs fine, also
memcheck does not detect any problem. I ran the tests on the branch
"francois" in my repository, if you want to cross check. The problem
on your side seems to come from another difference ?

Best regards
Peter


On 11 September 2015 at 10:50, Francois Botha <[hidden email]> wrote:
> Hi all,
>
> In preparation for some future development (including the long-awaited fix
> for the inflation reference period that Peter and I discussed a while back),
> I want to first add some tests to the inflationcpibond.cpp file. My new
> tests will be based on South African CPI bonds and I thought it would be
> good to move the CommonVars constructor to a static method for returning the
> current UK-related data and then later do a similar static method for South
> African related data.
>
> Please have a look at this commit:
> https://github.com/igitur/quantlib/commit/6dc07bcb465f632017ea037b243c691eef42fbcc
>
> What I did there was just the first part of my goal. I moved the CommonVars
> struct constructor to a static method UKVars that returns the UK-data.  This
> compiles, but for some reason the test fails. It looks like the link between
> the zero inflation index and PiecewiseZeroInflationCurve is broken. I can't
> figure out how to get the tests to work again.
>
> I suspect this is more of a C++ query than a QuantLib query, but I'd
> appreciate your help.
>
> thanks
> Francois Botha
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>


------------------------------------------------------------------------------

_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Static method for returning CommonVars

igitur
I'm encountering this with MSVC14/Boost 1.58 as well as MSVC10/Boost 1.55 on a different machine. Are there any Windows users who can confirm this for me, please?

and this test: ./QuantLib-test-suite-vc100-mt-gd.exe -t "*/*CPI*" 


This is the output I get:
Running 6 test cases...
unknown location(0): fatal error in "QuantLib::detail::quantlib_test_case(&InflationCPIBondTest::testCleanPrice)": std::exception: empty Handle cannot be dereferenced
d:\dev\quantlib\quantlib\test-suite\utilities.hpp(74): last checkpoint

*** 1 failure detected in test suite "Master Test Suite"


thanks

Francois Botha

On 12 September 2015 at 12:03, Francois Botha <[hidden email]> wrote:
Thanks, you're right! I tried it now at home on LInux / gcc / Boost 1.57 and there is no problem. 

I got the problem on my office PC, with MSVC, Boost 1.58. I think the problem lies there somewhere.

thanks for your help.

Francois Botha

On 11 September 2015 at 22:02, Peter Caspers <[hidden email]> wrote:
Hi Francois,

I merged the commit you mention into Luigi's current master and there
does not seem to be any problem. The test case runs fine, also
memcheck does not detect any problem. I ran the tests on the branch
"francois" in my repository, if you want to cross check. The problem
on your side seems to come from another difference ?

Best regards
Peter


On 11 September 2015 at 10:50, Francois Botha <[hidden email]> wrote:
> Hi all,
>
> In preparation for some future development (including the long-awaited fix
> for the inflation reference period that Peter and I discussed a while back),
> I want to first add some tests to the inflationcpibond.cpp file. My new
> tests will be based on South African CPI bonds and I thought it would be
> good to move the CommonVars constructor to a static method for returning the
> current UK-related data and then later do a similar static method for South
> African related data.
>
> Please have a look at this commit:
> https://github.com/igitur/quantlib/commit/6dc07bcb465f632017ea037b243c691eef42fbcc
>
> What I did there was just the first part of my goal. I moved the CommonVars
> struct constructor to a static method UKVars that returns the UK-data.  This
> compiles, but for some reason the test fails. It looks like the link between
> the zero inflation index and PiecewiseZeroInflationCurve is broken. I can't
> figure out how to get the tests to work again.
>
> I suspect this is more of a C++ query than a QuantLib query, but I'd
> appreciate your help.
>
> thanks
> Francois Botha
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>



------------------------------------------------------------------------------

_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Static method for returning CommonVars

Luigi Ballabio
I haven't tested it, but I suspect that when you say:

CommonVars common = CommonVars::UKVars();

first "common" is built, then the temporary returned from "CommonVars::UKVars()" is destroyed and its destructor unlinks the handle. I also suspect that it resets the evaluation date, to, since its SavedSettings data member would also be destroyed.

Instead of returning the whole thing from the static method, I'd just build and return the curve and then write something like:

CommonVars common;
common.cpiTS.linkTo(CommonVars::UKCurve());

Luigi

On Mon, Sep 14, 2015 at 11:44 PM Francois Botha <[hidden email]> wrote:
I'm encountering this with MSVC14/Boost 1.58 as well as MSVC10/Boost 1.55 on a different machine. Are there any Windows users who can confirm this for me, please?

and this test: ./QuantLib-test-suite-vc100-mt-gd.exe -t "*/*CPI*" 


This is the output I get:
Running 6 test cases...
unknown location(0): fatal error in "QuantLib::detail::quantlib_test_case(&InflationCPIBondTest::testCleanPrice)": std::exception: empty Handle cannot be dereferenced
d:\dev\quantlib\quantlib\test-suite\utilities.hpp(74): last checkpoint

*** 1 failure detected in test suite "Master Test Suite"


thanks

Francois Botha

On 12 September 2015 at 12:03, Francois Botha <[hidden email]> wrote:
Thanks, you're right! I tried it now at home on LInux / gcc / Boost 1.57 and there is no problem. 

I got the problem on my office PC, with MSVC, Boost 1.58. I think the problem lies there somewhere.

thanks for your help.

Francois Botha

On 11 September 2015 at 22:02, Peter Caspers <[hidden email]> wrote:
Hi Francois,

I merged the commit you mention into Luigi's current master and there
does not seem to be any problem. The test case runs fine, also
memcheck does not detect any problem. I ran the tests on the branch
"francois" in my repository, if you want to cross check. The problem
on your side seems to come from another difference ?

Best regards
Peter


On 11 September 2015 at 10:50, Francois Botha <[hidden email]> wrote:
> Hi all,
>
> In preparation for some future development (including the long-awaited fix
> for the inflation reference period that Peter and I discussed a while back),
> I want to first add some tests to the inflationcpibond.cpp file. My new
> tests will be based on South African CPI bonds and I thought it would be
> good to move the CommonVars constructor to a static method for returning the
> current UK-related data and then later do a similar static method for South
> African related data.
>
> Please have a look at this commit:
> https://github.com/igitur/quantlib/commit/6dc07bcb465f632017ea037b243c691eef42fbcc
>
> What I did there was just the first part of my goal. I moved the CommonVars
> struct constructor to a static method UKVars that returns the UK-data.  This
> compiles, but for some reason the test fails. It looks like the link between
> the zero inflation index and PiecewiseZeroInflationCurve is broken. I can't
> figure out how to get the tests to work again.
>
> I suspect this is more of a C++ query than a QuantLib query, but I'd
> appreciate your help.
>
> thanks
> Francois Botha
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>


------------------------------------------------------------------------------
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
--

------------------------------------------------------------------------------

_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Static method for returning CommonVars

igitur
Yes, the destructor is called. So that's the reason.

But why would it work on gcc, but not msvc. Is this kind of discrepancy common?

Anyway, I'll look into the workaround you suggested. Excuse my C++ ignorance. ;)


Francois Botha

On 15 September 2015 at 10:28, Luigi Ballabio <[hidden email]> wrote:
I haven't tested it, but I suspect that when you say:

CommonVars common = CommonVars::UKVars();

first "common" is built, then the temporary returned from "CommonVars::UKVars()" is destroyed and its destructor unlinks the handle. I also suspect that it resets the evaluation date, to, since its SavedSettings data member would also be destroyed.

Instead of returning the whole thing from the static method, I'd just build and return the curve and then write something like:

CommonVars common;
common.cpiTS.linkTo(CommonVars::UKCurve());

Luigi

On Mon, Sep 14, 2015 at 11:44 PM Francois Botha <[hidden email]> wrote:
I'm encountering this with MSVC14/Boost 1.58 as well as MSVC10/Boost 1.55 on a different machine. Are there any Windows users who can confirm this for me, please?

and this test: ./QuantLib-test-suite-vc100-mt-gd.exe -t "*/*CPI*" 


This is the output I get:
Running 6 test cases...
unknown location(0): fatal error in "QuantLib::detail::quantlib_test_case(&InflationCPIBondTest::testCleanPrice)": std::exception: empty Handle cannot be dereferenced
d:\dev\quantlib\quantlib\test-suite\utilities.hpp(74): last checkpoint

*** 1 failure detected in test suite "Master Test Suite"


thanks

Francois Botha

On 12 September 2015 at 12:03, Francois Botha <[hidden email]> wrote:
Thanks, you're right! I tried it now at home on LInux / gcc / Boost 1.57 and there is no problem. 

I got the problem on my office PC, with MSVC, Boost 1.58. I think the problem lies there somewhere.

thanks for your help.

Francois Botha

On 11 September 2015 at 22:02, Peter Caspers <[hidden email]> wrote:
Hi Francois,

I merged the commit you mention into Luigi's current master and there
does not seem to be any problem. The test case runs fine, also
memcheck does not detect any problem. I ran the tests on the branch
"francois" in my repository, if you want to cross check. The problem
on your side seems to come from another difference ?

Best regards
Peter


On 11 September 2015 at 10:50, Francois Botha <[hidden email]> wrote:
> Hi all,
>
> In preparation for some future development (including the long-awaited fix
> for the inflation reference period that Peter and I discussed a while back),
> I want to first add some tests to the inflationcpibond.cpp file. My new
> tests will be based on South African CPI bonds and I thought it would be
> good to move the CommonVars constructor to a static method for returning the
> current UK-related data and then later do a similar static method for South
> African related data.
>
> Please have a look at this commit:
> https://github.com/igitur/quantlib/commit/6dc07bcb465f632017ea037b243c691eef42fbcc
>
> What I did there was just the first part of my goal. I moved the CommonVars
> struct constructor to a static method UKVars that returns the UK-data.  This
> compiles, but for some reason the test fails. It looks like the link between
> the zero inflation index and PiecewiseZeroInflationCurve is broken. I can't
> figure out how to get the tests to work again.
>
> I suspect this is more of a C++ query than a QuantLib query, but I'd
> appreciate your help.
>
> thanks
> Francois Botha
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>


------------------------------------------------------------------------------
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
--


------------------------------------------------------------------------------

_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
Reply | Threaded
Open this post in threaded view
|

Re: Static method for returning CommonVars

Luigi Ballabio
It might depend on the level of optimization and whether return-value optimization is used.


On Tue, Sep 15, 2015 at 3:53 PM Francois Botha <[hidden email]> wrote:
Yes, the destructor is called. So that's the reason.

But why would it work on gcc, but not msvc. Is this kind of discrepancy common?

Anyway, I'll look into the workaround you suggested. Excuse my C++ ignorance. ;)


Francois Botha

On 15 September 2015 at 10:28, Luigi Ballabio <[hidden email]> wrote:
I haven't tested it, but I suspect that when you say:

CommonVars common = CommonVars::UKVars();

first "common" is built, then the temporary returned from "CommonVars::UKVars()" is destroyed and its destructor unlinks the handle. I also suspect that it resets the evaluation date, to, since its SavedSettings data member would also be destroyed.

Instead of returning the whole thing from the static method, I'd just build and return the curve and then write something like:

CommonVars common;
common.cpiTS.linkTo(CommonVars::UKCurve());

Luigi

On Mon, Sep 14, 2015 at 11:44 PM Francois Botha <[hidden email]> wrote:
I'm encountering this with MSVC14/Boost 1.58 as well as MSVC10/Boost 1.55 on a different machine. Are there any Windows users who can confirm this for me, please?

and this test: ./QuantLib-test-suite-vc100-mt-gd.exe -t "*/*CPI*" 


This is the output I get:
Running 6 test cases...
unknown location(0): fatal error in "QuantLib::detail::quantlib_test_case(&InflationCPIBondTest::testCleanPrice)": std::exception: empty Handle cannot be dereferenced
d:\dev\quantlib\quantlib\test-suite\utilities.hpp(74): last checkpoint

*** 1 failure detected in test suite "Master Test Suite"


thanks

Francois Botha

On 12 September 2015 at 12:03, Francois Botha <[hidden email]> wrote:
Thanks, you're right! I tried it now at home on LInux / gcc / Boost 1.57 and there is no problem. 

I got the problem on my office PC, with MSVC, Boost 1.58. I think the problem lies there somewhere.

thanks for your help.

Francois Botha

On 11 September 2015 at 22:02, Peter Caspers <[hidden email]> wrote:
Hi Francois,

I merged the commit you mention into Luigi's current master and there
does not seem to be any problem. The test case runs fine, also
memcheck does not detect any problem. I ran the tests on the branch
"francois" in my repository, if you want to cross check. The problem
on your side seems to come from another difference ?

Best regards
Peter


On 11 September 2015 at 10:50, Francois Botha <[hidden email]> wrote:
> Hi all,
>
> In preparation for some future development (including the long-awaited fix
> for the inflation reference period that Peter and I discussed a while back),
> I want to first add some tests to the inflationcpibond.cpp file. My new
> tests will be based on South African CPI bonds and I thought it would be
> good to move the CommonVars constructor to a static method for returning the
> current UK-related data and then later do a similar static method for South
> African related data.
>
> Please have a look at this commit:
> https://github.com/igitur/quantlib/commit/6dc07bcb465f632017ea037b243c691eef42fbcc
>
> What I did there was just the first part of my goal. I moved the CommonVars
> struct constructor to a static method UKVars that returns the UK-data.  This
> compiles, but for some reason the test fails. It looks like the link between
> the zero inflation index and PiecewiseZeroInflationCurve is broken. I can't
> figure out how to get the tests to work again.
>
> I suspect this is more of a C++ query than a QuantLib query, but I'd
> appreciate your help.
>
> thanks
> Francois Botha
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> QuantLib-dev mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/quantlib-dev
>


------------------------------------------------------------------------------
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev
--

--

------------------------------------------------------------------------------

_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev