Context-use-in-variable-transformers

Context use in variable transformers

Introduction

This is a "low-level" design note.

Problem with the initial design

Initially, Math::NIntegrate::VariableTransformer had this attribute:

    #| Contextual variable transformer (e.g. Composite)
    has Math::NIntegrate::VariableTransformer $.context is rw;

And methods like:

    #| Get original bounds
    method get-original-bounds(-->Map:D) {
        return do if $!context {
            $!context.get-original-bounds()
        } else {
            %(min => @!min-original-bounds, max => @!max-original-bounds)
        }
    }

    #| Get transformation bounds
    method get-transform-bounds(-->Map:D) {
        return do if $!context {
            $!context.get-transform-bounds()
        } else {
            %(min => @!min-transform-bounds, max => @!max-transform-bounds)
        }
    }

    #| Get region object
    method get-region() {
        return do if $!context {
            $!context.get-region()
        } else {
            self.region
        }
    }

Unfortunately, Raku hangs when initializations like this a made in TWEAK:

        for @!stack -> $vt { $vt.context = self }

Or when like this in a dedicated Math::NIntegerate::Builder method of Math::NIntegerate::VariableTransformer::Composite:

    method make-variable-transformer-composite(
            :$region
            --> Math::NIntegrate::VariableTransformer::Composite) {
    
        my $obj = Math::NIntegrate::VariableTransformer::Composite.new(:$region);

        my @min-original-bounds = $region.min;
        my @max-original-bounds = $region.max;
        my $vtInf = Math::NIntegrate::VariableTransformer::Infinity.new(:@min-original-bounds, :@max-original-bounds);
        $obj.add($vtInf);
        return $obj
    }

Where the method add has the line:

        @!stack.push($obj);
        $obj.context = self;

Remark: In C and C++ implementations of that design the stack would be just pointers, so, there would be no inherent problems.

Remedy

Have the argument :$context = Nil of the transform methods of the Math::NIntegerate::VariableTransformer classes.

That would require a more explicit management of the use of the objects Math::NIntegerate::VariableTransformer::Compoiste and Math::NIntegrate::Region.

Math::NIntegrate v0.0.1

Raku package for numerical integration.

Authors

  • Anton Antonov

License

Artistic-2.0

Dependencies

Data::TransformersHash::Merge:ver<2.0.0>:api<2>LeftistHeapMath::Polynomial::Chebyshev

Test Dependencies

Provides

  • Math::NIntegrate
  • Math::NIntegrate::Builder
  • Math::NIntegrate::Codes
  • Math::NIntegrate::NumericalFunction
  • Math::NIntegrate::Processing::Actions::MethodSpec
  • Math::NIntegrate::Processing::Grammar
  • Math::NIntegrate::Region
  • Math::NIntegrate::Rule
  • Math::NIntegrate::Rule::Cartesian
  • Math::NIntegrate::Rule::ClenshawCurtis
  • Math::NIntegrate::Rule::GaussKronrod
  • Math::NIntegrate::Rule::General
  • Math::NIntegrate::Rule::MonteCarlo
  • Math::NIntegrate::Rule::MultiDimensional
  • Math::NIntegrate::Rule::NewtonCotes
  • Math::NIntegrate::Rule::Trapezoidal
  • Math::NIntegrate::Spec
  • Math::NIntegrate::Strategy
  • Math::NIntegrate::Strategy::AdaptiveMonteCarlo
  • Math::NIntegrate::Strategy::DoubleExponential
  • Math::NIntegrate::Strategy::GlobalAdaptive
  • Math::NIntegrate::Strategy::LocalAdaptive
  • Math::NIntegrate::Strategy::MonteCarlo
  • Math::NIntegrate::Strategy::Saturating
  • Math::NIntegrate::Strategy::Trapezoidal
  • Math::NIntegrate::Utilities
  • Math::NIntegrate::VariableTransformer
  • Math::NIntegrate::VariableTransformer::Affine
  • Math::NIntegrate::VariableTransformer::Composite
  • Math::NIntegrate::VariableTransformer::IMT
  • Math::NIntegrate::VariableTransformer::Infinity
  • Math::NIntegrate::VariableTransformer::Reverse

The Camelia image is copyright 2009 by Larry Wall. "Raku" is a trademark of the Yet Another Society. All rights reserved.

Built with Podlite — the markup and publishing tools behind this site.