All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nd4j.linalg.api.ops.random.BaseRandomOp Maven / Gradle / Ivy

There is a newer version: 1.0.0-M2.1
Show newest version
package org.nd4j.linalg.api.ops.random;

import lombok.NoArgsConstructor;
import lombok.val;
import org.nd4j.autodiff.samediff.SDVariable;
import org.nd4j.autodiff.samediff.SameDiff;
import org.nd4j.linalg.api.ops.BaseOp;
import org.nd4j.linalg.api.ops.RandomOp;
import org.nd4j.linalg.api.shape.Shape;

import java.util.ArrayList;
import java.util.List;

/**
 * @author [email protected]
 */
@NoArgsConstructor
public abstract class BaseRandomOp extends BaseOp implements RandomOp {

    public BaseRandomOp(SameDiff sameDiff,
                            SDVariable i_v) {
        if (i_v != null) {
            this.sameDiff = sameDiff;
            this.xVertexId = i_v.getVarName();
            sameDiff.addArgsFor(new String[]{xVertexId},this);
            if(Shape.isPlaceholderShape(i_v.getShape())) {
                sameDiff.addPropertyToResolve(this,i_v.getVarName());
            }
        } else {
            throw new IllegalArgumentException("Input can't be null.");
        }
    }

    @Override
    public Type opType() {
        return Type.RANDOM;
    }

    @Override
    public List calculateOutputShape() {
        List ret = new ArrayList<>(1);
        val shape = sameDiff.getShapeForVarName(args()[0].getVarName());
        if(shape != null)
            ret.add(shape);
        return ret;
    }


}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy