Updating octave-java interface to use non-overloaded method signatures for int and boolean arrays (this seemed to have caused an issue on some versions with ints being converted to boolean first, thus losing all values except 0-1)

This commit is contained in:
Joseph Lizier 2019-07-23 11:33:04 +10:00
parent fba941362d
commit 17bf0e0be7
3 changed files with 16 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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;
}