Skip to content

Lack of InferiorClasses support in Octave causing function calls to resolve to the wrong method #17

@kolmanthomas

Description

@kolmanthomas

Here's a temporary workaround for the problem: the octfile infclass.cpp will take in two classes A and B, and set A as the superior class and B as the inferior class. I've wrote a quick .m file that sets all the Chebfun classes which should be inferior to one another.

To get the code working you would need to put the two files in the root Chebfun directory, and then run (only once, ever)

mkoctfile infclass.cpp

and then, every time you start up to the Octave interpreter to run Chebfun code, you'd run

octave> setinfclasses

which, to remind you that you've run the method, I had the method change the interpreter prompt to

octave_infclass>

This is all temporary until I try to add InferiorClasses support to Octave proper. So, we don't need to add these two files to the repo.

Files:

infclass.cpp

#include <octave/oct.h>

#include <octave/interpreter.h>
#include <octave/ov-classdef.h>

DEFUN_DLD (infclass, args, nargout,
           "infclass method")
{
    if (args.length () != 2)
    {
        octave_stdout << "usage: infclass(\"sup_class\", \"inf_class\")\n";
        return octave_value_list();
    }
    if ( !args(0).is_defined() || !args(0).is_string() )
    {
        error("First and second arguments must be strings of a class name");
    }

    auto interp = octave::interpreter::the_interpreter();

    interp->get_symbol_table().set_class_relationship(args(0).string_value(), args(1).string_value());

    // If all is successful, change the prompt
    interp->set_PS1("octave_infclass> ");
    
    return octave_value_list();
}

setinfclasses.m

function retval = setinfclasses()
    infclass("adchebfun", "chebfun");
    infclass("adchebfun2", "chebfun2");

    infclass("chebdouble", "chebfun");

    infclass("chebmatrix", "chebfun");
    infclass("chebmatrix", "operatorBlock");
    infclass("chebmatrix", "functionalBlock");

    infclass("deltafun", "bndfun");
    infclass("deltafun", "unbndfun");

    infclass("linBlock", "chebfun");

    infclass("linop", "chebfun"); 
    infclass("linop", "operatorBlock"); 
    infclass("linop", "functionalBlock"); 

    infclass("operatorBlock", "chebfun");

    infclass("singfun", "chebtech1");
    infclass("singfun", "chebtech2");

    infclass("treeVar", "chebfun"); 
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions