Skip to content

Easier and future proof way to tell is a vertex is constant. #149

@chris-major-improbable

Description

@chris-major-improbable

While analysing a network of Vertices it's not obvious which have constant values.
For example I've got the following code:

    private static boolean isConstant(DoubleVertex vertex) {
        if ( vertex instanceof ConstantDoubleVertex ){
            return true;
        } else if ( vertex instanceof DoubleBinaryOpVertex ){
            DoubleBinaryOpVertex dbv = (DoubleBinaryOpVertex)vertex;
            return isConstant(dbv.getLeft()) && isConstant(dbv.getRight());
        }
        return false;
    }

I think this would be useful as a core part of keanu so it's maintained

Alternatives
The main issue with this would be "custom" vertices from other sources. It may be better to provide an interface that let's code understand a vertex isn't going to change.

Additional context
Eventually this might even allow some automatic optimisations (e.g. cache values if they can never change).

Metadata

Metadata

Assignees

Labels

questionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions