Skip to content

Make Ops class assessible from sub-ops classes (i.e. MathOps) #147

@rnett

Description

@rnett

I'm writing some Kotlin extension functions, which if you aren't familiar with them, take this as an argument like python's self but hide it. Essentially adding a function to MathOps or one of the other ops classes, like this:

fun <T: TType> MathOps.mean(x: Operand<T>, vararg axis: Int, keepDims: Boolean? = null) = mean(x, constant(axis), Mean.keepDims(keepDims))

However, if you look at the above snippet, there's a problem: there is no constant in scope, it's in Ops and not accessible from MathOps. This happens whenever you want to use ops from other holder classes. I would like to make Ops accessible from the sub-ops classes, probably just by passing it as a parameter to the constructor (which is package private and only called from Ops). You could pass it instead of the Scope and get the scope from it if you make Ops' scope package private. I most likely won't be the only person creating extension functions that want to use other ops.

I can make a PR if the idea is approved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions