diff --git a/demos/octave/octaveToJavaIntArray.m b/demos/octave/octaveToJavaIntArray.m index 8692a0e..626775a 100755 --- a/demos/octave/octaveToJavaIntArray.m +++ b/demos/octave/octaveToJavaIntArray.m @@ -32,7 +32,12 @@ function jIntArray = octaveToJavaIntArray(octaveArray) if (length(octaveArray) > 1) % Do this the normal way tmp = javaObject('infodynamics.utils.OctaveMatrix'); - tmp.loadIntData(octaveArray,[1, length(octaveArray)]); + try + tmp.loadIntData(octaveArray,[1, length(octaveArray)]); + catch + % Most likely error here is that octaveArray is interpreted as booleans, so try loading as booleans: + tmp.loadBooleanAsIntData(octaveArray,[1, length(octaveArray)]); + end jIntArray = tmp.asIntVector(); else % For length 1 arrays, we need to perform a hack here or else diff --git a/demos/octave/octaveToJavaIntMatrix.m b/demos/octave/octaveToJavaIntMatrix.m index 77bd55b..f4768b8 100755 --- a/demos/octave/octaveToJavaIntMatrix.m +++ b/demos/octave/octaveToJavaIntMatrix.m @@ -32,7 +32,12 @@ function jIntMatrix = octaveToJavaIntMatrix(octaveMatrix) if ((rows(octaveMatrix)*columns(octaveMatrix)) > 1) % Do this the normal way tmp = javaObject('infodynamics.utils.OctaveMatrix'); - tmp.loadIntData(reshape(octaveMatrix,1,rows(octaveMatrix)*columns(octaveMatrix)),[rows(octaveMatrix), columns(octaveMatrix)]); + try + tmp.loadIntData(reshape(octaveMatrix,1,rows(octaveMatrix)*columns(octaveMatrix)),[rows(octaveMatrix), columns(octaveMatrix)]); + catch + % Most likely error here is that octaveMatrix is interpreted as booleans, so try loading as booleans: + tmp.loadBooleanAsIntData(reshape(octaveMatrix,1,rows(octaveMatrix)*columns(octaveMatrix)),[rows(octaveMatrix), columns(octaveMatrix)]); + end jIntMatrix = tmp.asIntMatrix(); else % For length 1 arrays, we need to perform a hack here or else diff --git a/java/source/infodynamics/utils/OctaveMatrix.java b/java/source/infodynamics/utils/OctaveMatrix.java index c9d1bd7..7b30518 100755 --- a/java/source/infodynamics/utils/OctaveMatrix.java +++ b/java/source/infodynamics/utils/OctaveMatrix.java @@ -124,8 +124,10 @@ public class OctaveMatrix * @param data array of booleans * @param dims array of true dimensions of the data */ - public void loadIntData (boolean[] data, int[] dims) + public void loadBooleanAsIntData (boolean[] data, int[] dims) { + // We'll print a warning for the user in case this is not the expected method signature: + System.out.printf("Loading boolean array of length %d into Java\n", data.length); this.dims = dims; int[] intData = new int[data.length]; for (int i = 0; i < data.length; i++) { @@ -238,7 +240,7 @@ public class OctaveMatrix public static Object ident (Object o) { - System.out.println (o); + // System.out.println (o); return o; }