فهرست منبع

added test prog for MatFileIO

Alexander Freytag 12 سال پیش
والد
کامیت
89ce7d634d
2فایلهای تغییر یافته به همراه239 افزوده شده و 0 حذف شده
  1. 88 0
      matlabAccess/progs/Makefile.inc
  2. 151 0
      matlabAccess/progs/testMatFileIO.cpp

+ 88 - 0
matlabAccess/progs/Makefile.inc

@@ -0,0 +1,88 @@
+# BINARY-DIRECTORY-MAKEFILE
+# conventions:
+# - there are no subdirectories, they are ignored!
+# - all ".C", ".cpp" and ".c" files in the current directory are considered
+#   independent binaries, and linked as such.
+# - the binaries depend on the library of the parent directory
+# - the binary names are created with $(BINNAME), i.e. it will be more or less
+#   the name of the .o file
+# - all binaries will be added to the default build list ALL_BINARIES
+
+# --------------------------------
+# - remember the last subdirectory
+#
+# set the variable $(SUBDIR) correctly to the current subdirectory. this
+# variable can be used throughout the current makefile.inc. The many 
+# SUBDIR_before, _add, and everything are only required so that we can recover
+# the previous content of SUBDIR before exitting the makefile.inc
+
+SUBDIR_add:=$(dir $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
+SUBDIR_before:=$(SUBDIR)
+SUBDIR:=$(strip $(SUBDIR_add))
+SUBDIR_before_$(SUBDIR):=$(SUBDIR_before)
+
+# ------------------------
+# - include subdirectories
+#
+# note the variables $(SUBDIRS_OF_$(SUBDIR)) are required later on to recover
+# the dependencies automatically. if you handle dependencies on your own, you
+# can also dump the $(SUBDIRS_OF_$(SUBDIR)) variable, and include the
+# makefile.inc of the subdirectories on your own...
+
+#SUBDIRS_OF_$(SUBDIR):=$(patsubst %/Makefile.inc,%,$(wildcard $(SUBDIR)*/Makefile.inc))
+#include $(SUBDIRS_OF_$(SUBDIR):%=%/Makefile.inc)
+
+# ----------------------------
+# - include local dependencies
+#
+# include the libdepend.inc file, which gives additional dependencies for the
+# libraries and binaries. additionally, an automatic dependency from the library
+# of the parent directory is added (commented out in the code below).
+
+-include $(SUBDIR)libdepend.inc
+
+PARENTDIR:=$(patsubst %/,%,$(dir $(patsubst %/,%,$(SUBDIR))))
+$(eval $(call PKG_DEPEND_INT,$(PARENTDIR)))
+
+# ---------------------------
+# - objects in this directory
+#
+# the use of the variable $(OBJS) is not mandatory. it is mandatory however
+# to update $(ALL_OBJS) in a way that it contains the path and name of
+# all objects. otherwise we can not include the appropriate .d files.
+
+OBJS:=$(patsubst %.cpp,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.cpp))) \
+      $(patsubst %.C,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.C))) \
+      $(shell grep -ls Q_OBJECT $(SUBDIR)*.h | sed -e's@^@/@;s@.*/@$(OBJDIR)moc_@;s@\.h$$@.o@') \
+      $(patsubst %.c,$(OBJDIR)%.o,$(notdir $(wildcard $(SUBDIR)*.c)))
+ALL_OBJS += $(OBJS)
+
+# ----------------------------
+# - binaries in this directory
+#
+# output of binaries in this directory. none of the variables has to be used.
+# but everything you add to $(ALL_LIBRARIES) and $(ALL_BINARIES) will be
+# compiled with `make all`. be sure again to add the files with full path.
+
+BINARIES:=$(patsubst %.o,$(BINDIR)%,$(filter-out moc_%,$(notdir $(OBJS))))
+ALL_BINARIES+=$(BINARIES)
+
+# ---------------------
+# - binary dependencies
+#
+# there is no way of determining the binary dependencies automatically, so we
+# follow conventions. each binary depends on the corresponding .o file and
+# on the libraries specified by the INTLIBS/EXTLIBS. these dependencies can be
+# specified manually or they are automatically stored in a .bd file.
+
+$(foreach head,$(wildcard $(SUBDIR)*.h),$(eval $(shell grep -q Q_OBJECT $(head) && echo $(head) | sed -e's@^@/@;s@.*/\(.*\)\.h$$@$(BINDIR)\1:$(OBJDIR)moc_\1.o@')))
+-include $(OBJS:%.o=%.bd)
+
+# -------------------
+# - subdir management
+#
+# as the last step, always add this line to correctly recover the subdirectory
+# of the makefile including this one!
+
+SUBDIR:=$(SUBDIR_before_$(SUBDIR))
+

+ 151 - 0
matlabAccess/progs/testMatFileIO.cpp

@@ -0,0 +1,151 @@
+/** 
+* @file testMatFileIO.cpp
+* @brief 
+* @author Paul Bodesheim
+* @date 06/01/2012 (dd-mm-yyyy)
+*/
+
+#include <vector>
+#include <iostream>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include "fast-hik/matio/src/matio.h"
+#include "fast-hik/MatFileIO.h"
+
+using namespace std;
+using namespace NICE;
+
+int main (int argc, char* argv[]) {
+	
+  std::string filenameA = "/home/bodesheim/data/2012-01-09-testMatFileIO/sparse3x3matrixA.mat";
+
+  // A
+  MatFileIO matfileIOA = MatFileIO(filenameA,MAT_ACC_RDONLY);
+  printf("\n%d \n", matfileIOA.getNumberOfVariables());
+  
+  sparse_t sparseA;
+  matfileIOA.getSparseVariableViaName(sparseA,"A");
+  for (uint i = 0; i < sparseA.nzmax; i++) std::cout << ((double*)sparseA.data)[i]<< "  "; 
+  std::cerr << std::endl;
+  std::cerr << "now start reading imagenet-data" << std::endl;
+  
+  std::string filename = "/home/dbv/bilder/imagenet/devkit-1.0/demo/demo.train.mat";
+  std::string variable1 = "training_instance_matrix";
+  std::string variable2 = "training_label_vector";
+
+  //
+  // test matvar functions
+  //
+  
+  mat_t * mat;
+  matvar_t * matvar;
+  
+  mat = Mat_Open(filename.c_str(),MAT_ACC_RDONLY);
+  matvar = Mat_VarReadNext(mat);
+
+  while (matvar != NULL) {
+
+    printf("dimension of variable: %i : ",matvar->rank);
+    printf("%i ",*(matvar->dims));
+    for (int i = 2; i<=matvar->rank; i++) {
+		  
+      matvar->dims++;	  
+      printf("x %i ",*(matvar->dims));
+      
+    }
+    printf("\n");
+    matvar = Mat_VarReadNext(mat);
+
+  };
+  
+  //
+  // test class MatFileIO
+  //
+  
+  MatFileIO matfileIO = MatFileIO(filename,MAT_ACC_RDONLY);
+  printf("\nnumber of variables: %d \n", matfileIO.getNumberOfVariables()); 
+  
+  sparse_t *sparse;
+  matfileIO.getSparseVariableViaName(*sparse,variable1);
+  
+  printf("\nSparse Matrix \n"); 
+
+  for ( int i = 0; i < 5; i++ ) {
+    for ( int j = sparse->jc[i]; j < sparse->jc[i+1] && j < sparse->ndata && j < sparse->jc[i]+5; j++ ) {
+                              
+	printf("\t\t(%d,%d)\t%f", sparse->ir[j]+1,i+1,((double*)sparse->data)[j]);
+    }
+    printf("\n");
+  }
+  
+//   int count = 0;
+//   
+//   for ( int i = 0; i < sparse->njc-1; i++ ) {
+//     for ( int j = sparse->jc[i]; j < sparse->jc[i+1] && j < sparse->ndata; j++ )
+//                          
+//       if (count < 15) {
+//       
+// 	printf("    (%d,%d)  %f\n", sparse->ir[j]+1,i+1, data[j]);
+// 	count++;
+//       }     
+//   }
+
+  NICE::Vector vec;
+  matfileIO.getVectorViaName(vec,variable2);
+  
+  std::cout << std::endl << "Vector" << std::endl << std::endl; 
+  
+  for (size_t k = 0; k < 15; k++) {
+    
+    std::cout << vec[k] << "  ";
+  }
+  
+  std::cout << "..." <<std::endl;
+  
+  return 0;
+}
+
+
+// int main (int argc, char* argv[]) {
+//  
+//   std::string filenameA = "/home/bodesheim/data/2012-01-09-testMatFileIO/sparse3x3matrixA.mat";
+//   std::string filenameB = "/home/bodesheim/data/2012-01-09-testMatFileIO/full3x3matrixB.mat";
+//   std::string filenameC = "/home/bodesheim/data/2012-01-09-testMatFileIO/uint8bit3x3matrixC.mat";
+//   std::string filenameD = "/home/bodesheim/data/2012-01-09-testMatFileIO/int8bit3x3matrixD.mat";
+// 
+//   // A
+//   MatFileIO matfileIO = MatFileIO(filenameA,MAT_ACC_RDONLY);
+//   printf("\n%d \n", matfileIO.getNumberOfVariables());
+//   
+//   sparse_t sparse;
+//   matfileIO.getSparseVariableViaName(sparse,"A");
+//   for (uint i = 0; i < sparse.nzmax; i++) std::cout << ((double*)sparse.data)[i]<< "  "; 
+//   
+//   // B
+//   matfileIO = MatFileIO(filenameB,MAT_ACC_RDONLY);
+//   printf("\n%d \n", matfileIO.getNumberOfVariables());
+//   
+//   std::vector<std::vector<double> > features;
+//   matfileIO.getFeatureMatrixViaName(features,"B");
+//   for (uint i = 0; i < features.size(); i++) for (uint j = 0; j < features[i].size(); j++) std::cout << (features[i])[j] << "  "; 
+//   
+//   // C
+//   matfileIO = MatFileIO(filenameC,MAT_ACC_RDONLY);
+//   printf("\n%d \n", matfileIO.getNumberOfVariables());
+// 
+//   matfileIO.getFeatureMatrixViaName(features,"C");
+//   for (uint i = 0; i < features.size(); i++) for (uint j = 0; j < features[i].size(); j++) std::cout << (features[i])[j] << "  "; 
+//   
+//   // D
+//   matfileIO = MatFileIO(filenameD,MAT_ACC_RDONLY);
+//   printf("\n%d \n", matfileIO.getNumberOfVariables());
+//   
+//   matfileIO.getFeatureMatrixViaName(features,"D");
+//   for (uint i = 0; i < features.size(); i++) for (uint j = 0; j < features[i].size(); j++) std::cout << (features[i])[j] << "  "; 
+//   printf("\n");
+//   
+//   return 0;
+// }