本文整理汇总了Java中com.jmatio.types.MLDouble.getN方法的典型用法代码示例。如果您正苦于以下问题:Java MLDouble.getN方法的具体用法?Java MLDouble.getN怎么用?Java MLDouble.getN使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.jmatio.types.MLDouble
的用法示例。
在下文中一共展示了MLDouble.getN方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
final Map<Integer, String> database = readDatabase();
final File outbase = new File("/Users/jon/Data/lfw/matlab-fvs/");
for (int i = 1; i <= 128; i++) {
final File chunk = new File(
"/Users/jon/Downloads/data/lfw_aligned/SIFT_1pix_PCA64_GMM512/features/poolfv/1/", String.format(
"feat_%d-v6.mat", i));
System.out.println(chunk);
final MatFileReader reader = new MatFileReader(chunk);
final MLSingle feats = (MLSingle) reader.getMLArray("chunk");
final MLDouble index = (MLDouble) reader.getMLArray("index");
for (int j = 0; j < index.getN(); j++) {
final int id = (int) (double) index.get(0, j);
final File outfile = new File(outbase, database.get(id).replace(".jpg", ".bin"));
outfile.getParentFile().mkdirs();
final float[] vec = new float[feats.getM()];
for (int k = 0; k < feats.getM(); k++) {
vec[k] = feats.get(k, j);
}
final FloatFV fv = new FloatFV(vec);
IOUtils.writeBinary(outfile, fv);
}
}
}
示例2: toIntArray
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
private int[] toIntArray(MLDouble training) {
final int[] arr = new int[training.getN()];
for (int i = 0; i < arr.length; i++) {
arr[i] = training.get(0, i).intValue();
}
return arr;
}
示例3: load
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
public static int load(String fileName) {
fileName = fileName.trim();
String matFileName = fileName;
if (fileName.endsWith(".mat") == false)
matFileName = matFileName + ".mat"; // append the default extension
boolean absoluteFileName = false;
if (scalaExec.Interpreter.GlobalValues.hostIsUnix) {
if (fileName.startsWith("/"))
absoluteFileName = true;
} else {
if (fileName.length() > 1)
if (fileName.charAt(1) == ':')
absoluteFileName = true;
}
if (absoluteFileName == false) // construct the path by appending the current directory
matFileName = Directory.Current().get().path() + File.separator + matFileName;
int numVarsReaded = 0;
try {
//read in the file
MatFileReader mfr = new MatFileReader(matFileName);
// a map of MLArray objects that were inside MAT-file. MLArrays are mapped with MLArrays' names
Map matFileVars = mfr.getContent(); // a map of MLArray objects that were inside the MAT-file, mapped with their names
Set varsSet = matFileVars.keySet(); // a set view of the keys contained in the map
Iterator<String> varsIter = varsSet.iterator();
boolean isRoot = true;
while (varsIter.hasNext()) { // for all .mat file variables
String currentVariable = varsIter.next(); // get the String of the Matlab variable
// the value to which the read file maps the specified array name. Returns null if the file contains no content for this name.
MLArray objArrayRetrived = mfr.getMLArray(currentVariable);
if (objArrayRetrived instanceof MLDouble) {
// public MLArray getMLArray(String name)
// Returns the value to which the read file maps the specified array name. Returns null if the file contains no content for this name.
// Returns: - the MLArray to which this file maps the specified name, or null if the file contains no content for this name.
MLDouble mlArrayRetrived = (MLDouble) mfr.getMLArray(currentVariable);
String arrayName = mlArrayRetrived.getName();
int nrows = mlArrayRetrived.getM();
int ncols = mlArrayRetrived.getN();
double[][] data = mlArrayRetrived.getArray(); // get data
scalaExec.Interpreter.GlobalValues.data = new double[nrows][ncols]; // copy of data array
for (int r = 0; r < nrows; r++)
for (int c = 0; c < ncols; c++)
scalaExec.Interpreter.GlobalValues.data[r][c] = data[r][c];
// keep a global reference in order to be accessible from the interpreter
// prepare and execute a "var" command in order to pass the variable to the Interpreter
if (nrows == 1 && ncols == 1) // get as single double
{
double scalarData = data[0][0];
scalaExec.Interpreter.GlobalValues.scalarData = scalarData;
scalaExec.Interpreter.GlobalValues.scalarValuesFromMatlab.put(arrayName, scalarData);
} else {
scalaExec.Interpreter.GlobalValues.arrayValuesFromMatlab.put(arrayName, scalaExec.Interpreter.GlobalValues.data);
}
numVarsReaded++; // one more variable readed
} // for all .mat file variables
}
return numVarsReaded;
} catch (Exception e) {
System.out.println("Exception ");
e.printStackTrace();
return 0;
}
}
示例4: load
import com.jmatio.types.MLDouble; //导入方法依赖的package包/类
public static int load(String fileName) {
fileName=fileName.trim();
String matFileName = fileName;
if (fileName.endsWith(".mat")==false)
matFileName = matFileName+".mat"; // append the default extension
boolean absoluteFileName = false;
if (scalaExec.Interpreter.GlobalValues.hostIsUnix)
{
if (fileName.startsWith("/"))
absoluteFileName = true;
}
else {
if (fileName.length()> 1)
if (fileName.charAt(1)==':')
absoluteFileName = true;
}
if (absoluteFileName == false) // construct the path by appending the current directory
matFileName = Directory.Current().get().path()+File.separator+matFileName;
int numVarsReaded = 0;
try {
//read in the file
MatFileReader mfr = new MatFileReader( matFileName );
// a map of MLArray objects that were inside MAT-file. MLArrays are mapped with MLArrays' names
Map matFileVars = mfr.getContent(); // a map of MLArray objects that were inside the MAT-file, mapped with their names
Set varsSet = matFileVars.keySet(); // a set view of the keys contained in the map
Iterator <String> varsIter = varsSet.iterator();
boolean isRoot = true;
while (varsIter.hasNext()) { // for all .mat file variables
String currentVariable = varsIter.next(); // get the String of the Matlab variable
// the value to which the read file maps the specified array name. Returns null if the file contains no content for this name.
MLArray objArrayRetrived = mfr.getMLArray(currentVariable);
if (objArrayRetrived instanceof MLDouble) {
// public MLArray getMLArray(String name)
// Returns the value to which the read file maps the specified array name. Returns null if the file contains no content for this name.
// Returns: - the MLArray to which this file maps the specified name, or null if the file contains no content for this name.
MLDouble mlArrayRetrived = (MLDouble)mfr.getMLArray(currentVariable);
String arrayName = mlArrayRetrived.getName();
int nrows = mlArrayRetrived.getM();
int ncols = mlArrayRetrived.getN();
double [][] data = mlArrayRetrived.getArray(); // get data
scalaExec.Interpreter.GlobalValues.data = new double[nrows][ncols]; // copy of data array
for (int r=0; r < nrows; r++)
for (int c=0; c< ncols; c++)
scalaExec.Interpreter.GlobalValues.data[r][c] = data[r][c];
// keep a global reference in order to be accessible from the interpreter
// prepare and execute a "var" command in order to pass the variable to the Interpreter
if (nrows == 1 && ncols == 1) // get as single double
{
double scalarData = data[0][0];
scalaExec.Interpreter.GlobalValues.scalarData = scalarData;
scalaExec.Interpreter.GlobalValues.scalarValuesFromMatlab.put(arrayName, scalarData);
}
else {
scalaExec.Interpreter.GlobalValues.arrayValuesFromMatlab.put(arrayName, scalaExec.Interpreter.GlobalValues.data);
}
numVarsReaded++; // one more variable readed
} // for all .mat file variables
}
return numVarsReaded;
}
catch (Exception e)
{
System.out.println("Exception ");
e.printStackTrace();
return 0;
}
}