Skip to content

Instantly share code, notes, and snippets.

@AlexDBlack
Last active November 4, 2019 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexDBlack/a2e9f87e46dc20dbc5eadcab39a8a993 to your computer and use it in GitHub Desktop.
Save AlexDBlack/a2e9f87e46dc20dbc5eadcab39a8a993 to your computer and use it in GitHub Desktop.
import org.nd4j.linalg.api.buffer.DataType;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.api.ops.DynamicCustomOp;
import org.nd4j.linalg.factory.Nd4j;
public class SSBP {
public static void main(String[] args) {
INDArray in = Nd4j.create(DataType.FLOAT, 1, 2);
INDArray grad = Nd4j.create(DataType.FLOAT, 1);
INDArray out = Nd4j.create(DataType.FLOAT, 1, 2);
//Backprop for [1,2].get(all, point(0)) -> fwd output has shape [1]
DynamicCustomOp op = DynamicCustomOp.builder("strided_slice_bp")
.addInputs(in, grad)
.addOutputs(out)
.addIntegerArguments(
1, //Begin mask
0, //Ellipsis mask
1, //End mask
0, //new axis mask
2, //shrink axis mask
0, //begin 0
0, //begin 1
0, //end 0
1, //end 1
1, //stride 0
1) //stride 1
.build();
for( int i=0; i<1000; i++ ){
System.out.println(i);
Nd4j.exec(op);
}
}
}
0
1
2
3
4
5
6
7
8
9
Process finished with exit code -1073740940 (0xC0000374)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment