Example #1
0
    void load(std::string const& filename, xml_node & node)
    {
        if (!mapnik::util::exists(filename))
        {
            throw config_error(std::string("Could not load map file: File does not exist"), 0, filename);
        }
        filename_ = filename;
#ifdef _WINDOWS
        std::basic_ifstream<char> stream(mapnik::utf8_to_utf16(filename));
#else
        std::basic_ifstream<char> stream(filename.c_str());
#endif
        if (!stream)
        {
            throw config_error("Could not load map file", 0, filename);
        }
        stream.unsetf(std::ios::skipws);
        std::vector<char> v(std::istreambuf_iterator<char>(stream.rdbuf()),
                            std::istreambuf_iterator<char>());
        if (!stream.good())
        {
            throw config_error("Could not load map file", 0, filename_);
        }
        v.push_back(0); // zero-terminate
        load_array(v, node);
    }
int main(int argc, char *argv[]) {

    std::vector<double> a = load_array(argv[1]);
    std::vector<double> b = load_array(argv[2]);
    std::string q_name = argv[3];
    std::vector<double> q = load_array(q_name);

    double dist_a = dist_get(a,q);
    double dist_b = dist_get(b,q);

    std::ofstream ofs( "res_class_hist.txt",std::ios::app);  
    if(dist_a > dist_b){
      ofs << "B" << std::endl;
    }else{
      ofs << "A" << std::endl;
    }

 return 0;
}
Example #3
0
int main(void)
{
    int         size = SIZE_ARRAY;
    int         Array[SIZE_ARRAY];
    double      res;


    load_array(size, Array);

    show_array(size, Array);

    res = get_mean(size, Array);
    printf("%.3f\n", res);

    return (0);
}
Example #4
0
 void load(std::string const& filename, xml_node &node)
 {
     filename_ = filename;
     std::basic_ifstream<char> stream(filename.c_str());
     if (!stream)
     {
         throw config_error("Could not load map file", 0, filename);
     }
     stream.unsetf(std::ios::skipws);
     std::vector<char> v(std::istreambuf_iterator<char>(stream.rdbuf()),
                         std::istreambuf_iterator<char>());
     if (!stream.good())
     {
         throw config_error("Could not load map file", 0, filename_);
     }
     v.push_back(0); // zero-terminate
     load_array(v, node);
 }
 void load(serialization::array<T> const& x)
 {
   load_array(x,0u);
 }
Example #6
0
 void load_string(std::string const& buffer, xml_node & node, std::string const & )
 {
     // Note: base_path ignored because its not relevant - only needed for xml2 to load entities (see libxml2_loader.cpp)
     load_array(std::string(buffer), node);
 }
int main(int argc, char **argv) {
    int status;

    if(argc < 3) {
        usage(argv[0], stderr);
        return 1;
    }

    // First, bump up our stack size.
    struct rlimit rlim;

    status = getrlimit(RLIMIT_STACK, &rlim);
    if(status == -1) {
        int err = errno;
        fprintf(stderr, "Could not get system resource limits. %s\n", strerror(err));
        return 1;
    }

    rlim.rlim_cur = 1024 * 1024 * 1024; // 1 GB
    status = setrlimit(RLIMIT_STACK, &rlim);
    if(status == -1) {
        int err = errno;
        fprintf(stderr, "Could not set system stack size. %s\n", strerror(err));
        return 1;
    }

    // Read in the file headers
    FILE *a_file, *b_file;
    int m_a, n_a, m_b, n_b;

    a_file = fopen(argv[1], "r");
    if(a_file == NULL) {
        int err = errno;
        fprintf(stderr, "Could not open file %s: %s\n", argv[1], strerror(err));
        return 1;
    }
    b_file = fopen(argv[2], "r");
    if(b_file == NULL) {
        int err = errno;
        fprintf(stderr, "Could not open file %s: %s\n", argv[2], strerror(err));
        return 1;
    }

    status = fscanf(a_file, "%d %d", &m_a, &n_a);
    if(status < 2) {
        fprintf(stderr, "Could not parse file header for %s\n", argv[1]);
        return 1;
    }

    status = fscanf(b_file, "%d %d", &m_b, &n_b);
    if(status < 2) {
        fprintf(stderr, "Could not parse file header for %s\n", argv[2]);
        return 1;
    }

    printf("%d %d\n", m_a, n_b);
    // Allocate the buffers
    float a_matrix[m_a][n_a];
    float b_matrix[m_b][n_b];

    status = load_array(a_file, &a_matrix[0][0], m_a * n_a);
    if(status < m_a * n_a) {
        fprintf(stderr, "Error: could not parse all entries of %s\n", argv[1]);
        return 1;
    }

    status = load_array(b_file, &b_matrix[0][0], m_b * n_b);
    if(status < m_b * n_b) {
        fprintf(stderr, "Error: could not parse all entries of %s\n", argv[2]);
        return 1;
    }

    float c_matrix[m_a][n_b];
    matrix_multiply(&a_matrix[0][0],
                    &b_matrix[0][0],
                    &c_matrix[0][0],
                    m_a, m_b, n_b);

    matrix_print(stdout, &c_matrix[0][0], m_a, n_b);

    return 0;
}