Changeset 8091:31d9055f38df in orange


Ignore:
Timestamp:
07/07/11 19:06:19 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
f4a2ecd889c28ad19770b9556bdb855d55e2732a
Message:

Fixed SimpleTreeLearner compiling on Windows

Location:
source/orange
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • source/orange/Orange.vcproj

    r8088 r8091  
    895895            <File 
    896896                RelativePath="tdidt.hpp" 
     897                > 
     898            </File> 
     899            <File 
     900                RelativePath=".\tdidt_simple.cpp" 
     901                > 
     902            </File> 
     903            <File 
     904                RelativePath=".\tdidt_simple.hpp" 
    897905                > 
    898906            </File> 
  • source/orange/tdidt_simple.cpp

    r8065 r8091  
    3030#include "table.hpp" 
    3131#include "classify.hpp" 
    32 #include "err.h" 
    3332 
    3433#include "tdidt_simple.ppp" 
    3534 
    36 #define ASSERT(x) if (!(x)) err(1, "%s:%d", __FILE__, __LINE__) 
    37 #define LOG2(x) log((x)) / log(2.0) 
     35#ifndef _MSC_VER 
     36    #include "err.h" 
     37    #define ASSERT(x) if (!(x)) err(1, "%s:%d", __FILE__, __LINE__) 
     38#else 
     39    #define ASSERT(x) if(!(x)) exit(1) 
     40#endif // _MSC_VER 
     41 
     42#ifndef INFINITY 
     43    #include <limits> 
     44    #define INFINITY numeric_limits<float>::infinity() 
     45#endif // INFINITY 
     46 
     47#define LOG2(x) log((double) (x)) / log(2.0) 
    3848 
    3949enum { DiscreteNode, ContinuousNode, PredictorNode }; 
     
    5060/* This function uses the global variable compar_attr */ 
    5161int 
    52 compar_examples(TExample **e1, TExample **e2) 
    53 { 
     62compar_examples(const void * ptr1, const void * ptr2) 
     63{ 
     64    TExample **e1 = (TExample **) ptr1; 
     65    TExample **e2 = (TExample **) ptr2; 
    5466    if ((*e1)->values[compar_attr].isSpecial()) 
    5567        return 1; 
     
    89101 
    90102    /* allocate space */ 
    91     ASSERT(dist_lt = calloc(cls_vals, sizeof *dist_lt)); 
    92     ASSERT(dist_ge = calloc(cls_vals, sizeof *dist_ge)); 
    93     ASSERT(attr_dist = calloc(2, sizeof *attr_dist)); 
     103    ASSERT(dist_lt = (int*) calloc(cls_vals, sizeof *dist_lt)); 
     104    ASSERT(dist_ge = (int*) calloc(cls_vals, sizeof *dist_ge)); 
     105    ASSERT(attr_dist = (int*) calloc(2, sizeof *attr_dist)); 
    94106 
    95107    /* sort */ 
     
    157169 
    158170    /* allocate space */ 
    159     ASSERT(cont = calloc(cls_vals * attr_vals, sizeof *cont)); 
    160     ASSERT(attr_dist = calloc(attr_vals, sizeof *attr_dist)); 
    161     ASSERT(attr_dist_cls_known = calloc(attr_vals, sizeof *attr_dist)); 
     171    ASSERT(cont = (int *) calloc(cls_vals * attr_vals, sizeof *cont)); 
     172    ASSERT(attr_dist = (int *) calloc(attr_vals, sizeof *attr_dist)); 
     173    ASSERT(attr_dist_cls_known = (int *) calloc(attr_vals, sizeof *attr_dist)); 
    162174 
    163175    /* contingency matrix */ 
     
    213225    domain = examples[0]->domain; 
    214226 
    215     ASSERT(node = malloc(sizeof(*node))); 
     227    ASSERT(node = (SimpleTreeNode *) malloc(sizeof(*node))); 
    216228 
    217229    /* class distribution */ 
    218230    cls_vals = domain->classVar->noOfValues(); 
    219231 
    220     ASSERT(node->dist = calloc(cls_vals, sizeof *node->dist)); 
     232    ASSERT(node->dist = (int *) calloc(cls_vals, sizeof *node->dist)); 
    221233    for (ex = examples, ex_end = examples + size; ex != ex_end; ex++) 
    222234        if (!(*ex)->getClass().isSpecial()) 
     
    287299        no_of_values = domain->attributes->at(best_attr)->noOfValues(); 
    288300 
    289         ASSERT(tmp = calloc(size, sizeof *tmp)); 
    290         ASSERT(cnt = calloc(no_of_values, sizeof *cnt)); 
     301        ASSERT(tmp = (TExample **) calloc(size, sizeof *tmp)); 
     302        ASSERT(cnt = (int *) calloc(no_of_values, sizeof *cnt)); 
    291303         
    292304        for (ex = examples, ex_end = examples + size; ex != ex_end; ex++) 
     
    303315        /* recursively build subtrees */ 
    304316        node->children_size = no_of_values; 
    305         ASSERT(node->children = calloc(no_of_values, sizeof *node->children)); 
     317        ASSERT(node->children = (SimpleTreeNode **) calloc(no_of_values, sizeof *node->children)); 
    306318 
    307319        args->attr_split_so_far[best_attr] = 1; 
     
    328340        /* recursively build subtrees */ 
    329341        node->children_size = 2; 
    330         ASSERT(node->children = calloc(2, sizeof *node->children)); 
     342        ASSERT(node->children = (SimpleTreeNode **) calloc(2, sizeof *node->children)); 
    331343         
    332344        node->children[0] = build_tree(examples, best_rank + 1, depth + 1, args); 
     
    357369     
    358370    /* create a tabel with pointers to examples */ 
    359     ASSERT(examples = calloc(ogen->numberOfExamples(), sizeof(TExample**))); 
     371    ASSERT(examples = (TExample **) calloc(ogen->numberOfExamples(), sizeof(TExample**))); 
    360372    ex = examples; 
    361373    PEITERATE(ei, ogen) 
    362374        *(ex++) = &(*ei); 
    363375 
    364     ASSERT(args.attr_split_so_far = calloc(ogen->domain->attributes->size(), sizeof(int))); 
     376    ASSERT(args.attr_split_so_far = (int *) calloc(ogen->domain->attributes->size(), sizeof(int))); 
    365377    args.minExamples = minExamples; 
    366378    args.maxMajority = maxMajority; 
     
    416428 
    417429            cls_vals = ex.domain->classVar->noOfValues(); 
    418             ASSERT(dist = calloc(cls_vals, sizeof *dist)); 
     430            ASSERT(dist = (int *) calloc(cls_vals, sizeof *dist)); 
    419431            for (i = 0; i < node->children_size; i++) { 
    420432                child_dist = classify(ex, node->children[i], free_dist); 
Note: See TracChangeset for help on using the changeset viewer.