Skip to content

Native function support #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import org.tensorflow.ConcreteFunction;
import org.tensorflow.DeviceSpec;
import org.tensorflow.EagerSession;
import org.tensorflow.ExecutionEnvironment;
Expand Down Expand Up @@ -82,6 +84,7 @@
import org.tensorflow.op.core.ExtractVolumePatches;
import org.tensorflow.op.core.Fill;
import org.tensorflow.op.core.Fingerprint;
import org.tensorflow.op.core.Function;
import org.tensorflow.op.core.Gather;
import org.tensorflow.op.core.GatherNd;
import org.tensorflow.op.core.GetSessionHandle;
Expand Down Expand Up @@ -347,10 +350,10 @@ public final class Ops {

public final SignalOps signal;

public final QuantizationOps quantization;

public final TrainOps train;

public final QuantizationOps quantization;

private final Scope scope;

private Ops(Scope scope) {
Expand All @@ -372,8 +375,8 @@ private Ops(Scope scope) {
math = new MathOps(this);
audio = new AudioOps(this);
signal = new SignalOps(this);
quantization = new QuantizationOps(this);
train = new TrainOps(this);
quantization = new QuantizationOps(this);
}

/**
Expand Down Expand Up @@ -1068,6 +1071,21 @@ public Bucketize bucketize(Operand<? extends TNumber> input, List<Float> boundar
return Bucketize.create(scope, input, boundaries);
}

/**
* empty
*/
public Operand<?> call(ConcreteFunction function, Operand<?> argument) {
return Function.call(scope, function, argument);
}

/**
* empty
*/
public Map<String, Operand<?>> call(ConcreteFunction function,
Map<String, Operand<?>> arguments) {
return Function.call(scope, function, arguments);
}

/**
* Clips tensor values to a specified min and max.
* <p>
Expand Down Expand Up @@ -1834,13 +1852,14 @@ public Constant<TInt32> constant(Shape shape, IntDataBuffer data) {
}

/**
* Creates a scalar of {@code type}, with the value of {@code number}.
* {@code number} may be truncated if it does not fit in the target type.
* Creates a scalar of {@code type}, with the value of {@code number}. {@code number} may be truncated if it does not
* fit in the target type.
*
* @param type the type of tensor to create. Must be concrete (i.e. not {@link org.tensorflow.types.family.TFloating})
* @param number the value of the tensor
* @return a constant of the passed type
* @throws IllegalArgumentException if the type is abstract (i.e. {@link org.tensorflow.types.family.TFloating}) or unknown.
* @throws IllegalArgumentException if the type is abstract (i.e. {@link org.tensorflow.types.family.TFloating}) or
* unknown.
*/
public <T extends TNumber> Constant<T> constant(Class<T> type, Number number) {
return Constant.tensorOf(scope, type, number);
Expand Down Expand Up @@ -1892,14 +1911,14 @@ public <T extends TType> Constant<T> constantOf(T tensor) {
}

/**
* Creates a scalar of the same type as {@code toMatch}, with the value of {@code number}.
* {@code number} may be truncated if it does not fit in the target type.
* Creates a scalar of the same type as {@code toMatch}, with the value of {@code number}. {@code number} may be
* truncated if it does not fit in the target type.
*
* @param toMatch the operand providing the target type
* @param number the value of the tensor
* @return a constant with the same type as {@code toMatch}
* @see Ops#constant(Class, Number)
* @throws IllegalArgumentException if the type is unknown (which should be impossible).
* @see Ops#constant(Class, Number)
*/
public <T extends TNumber> Constant<T> constantOfSameType(Operand<T> toMatch, Number number) {
return Constant.tensorOfSameType(scope, toMatch, number);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@

package org.tensorflow.internal.c_api;

import java.nio.*;
import org.bytedeco.javacpp.*;
import org.bytedeco.javacpp.annotation.*;

import static org.tensorflow.internal.c_api.global.tensorflow.*;
import org.bytedeco.javacpp.Pointer;
import org.bytedeco.javacpp.annotation.Opaque;
import org.bytedeco.javacpp.annotation.Properties;


// TF_Function is a grouping of operations with defined inputs and outputs.
// Once created and added to graphs, functions can be invoked by creating an
// operation whose operation type matches the function name.
@Opaque @Properties(inherit = org.tensorflow.internal.c_api.presets.tensorflow.class)
public class TF_Function extends Pointer {
/** Empty constructor. Calls {@code super((Pointer)null)}. */
public TF_Function() { super((Pointer)null); }
/** Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}. */
public TF_Function(Pointer p) { super(p); }
@Opaque
@Properties(inherit = org.tensorflow.internal.c_api.presets.tensorflow.class)
public class TF_Function extends org.tensorflow.internal.c_api.AbstractTF_Function {

/**
* Empty constructor. Calls {@code super((Pointer)null)}.
*/
public TF_Function() {
super((Pointer) null);
}

/**
* Pointer cast constructor. Invokes {@link Pointer#Pointer(Pointer)}.
*/
public TF_Function(Pointer p) {
super(p);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,17 @@ public Output<?>[] outputList(int idx, int length) {

@Override
public <T extends TType> Output<T> output(int idx) {
if (getUnsafeNativeHandle(idx) != null && !getUnsafeNativeHandle(idx).isNull()) {
int numOutputs = this.numOutputs();
if (idx >= numOutputs) {
throw new IndexOutOfBoundsException(
"Can't get output with index " + idx + ", this op only has " + numOutputs + " outputs.");
}

if (idx < 0) {
throw new IndexOutOfBoundsException("Can't get output with index < 0.");
}
}
return new Output<>(this, idx);
}

Expand Down
Loading