auds_t *auds_open(char *fname, data_type_t adt) { auds_t *auds=malloc(sizeof(auds_t)); if(!auds) return NULL; memset(auds, 0, sizeof(auds_t)); int rval=-1; int err; auds->channels=2; //default is stereo if(adt==AUD_TYPE_NONE) auds->data_type=get_data_type(fname); else auds->data_type=adt; switch(auds->data_type){ case AUD_TYPE_PCM: rval=pcm_open(auds, fname); break; case AUD_TYPE_NONE: ERRMSG("unknown audio data type\n"); break; } if(rval) goto erexit; return auds; erexit: ERRMSG("errror: %s\n",__func__); auds_close(auds); return NULL; }
void ann::set_num_outputs(int num_outputs) { int curr_num_outputs = 0; get_num_outputs(curr_num_outputs); if (num_outputs == curr_num_outputs) { return; } const data_type data_type = get_data_type(); if (num_outputs < 0) { flext::error("number of outputs must be greater than zero"); } if (data_type == LABELLED_CLASSIFICATION && num_outputs > 1) { flext::error("for classification mode, number of outputs must be 1, for multidimensional output switch mode to %d", LABELLED_REGRESSION); return; } if (data_type == LABELLED_REGRESSION) { bool success = regression_data.setInputAndTargetDimensions(regression_data.getNumInputDimensions(), num_outputs); if (success == false) { flext::error("unable to set input and target dimensions"); return; } } }
uint8_t buscar_lista_elemento(lexical * lexer, uint8_t size) { uint8_t i=0; uint8_t token = 0; uint8_t validar = 0; uint8_t * indice = NULL; uint8_t data_type = 0; for(i=0;i<size;i++) { if(lexer->token == VARIABLE) { token = ht_get(lexer->valor); if(token == LIST) { validar = is_corchetes(lexer); if(validar == 0) { indice = get_list_indice(lexer); if(indice == NULL) return 0; data_type = get_data_type(lexer->valor, indice); if(data_type == 0) return 0; if(!asignar_nuevo_token(lexer,data_type)) return 0; free(indice); } } } lexer = lexer->next; } return 1; }
XLNT_FUNCTION void cell::set_value(std::string s) { d_->set_string(check_string(s), get_parent().get_parent().get_guess_types()); if (get_data_type() == type::string && !s.empty()) { get_parent().get_parent().add_shared_string(s); } }
/***************************************************************************** * DoWork: convert a buffer *****************************************************************************/ static block_t *DoWork( filter_t * p_filter, block_t *p_in_buf ) { size_t i_length = p_in_buf->i_buffer; uint8_t * p_in = p_in_buf->p_buffer; block_t *p_out_buf = NULL; uint16_t i_data_type = get_data_type( p_filter, p_in_buf ); if( i_data_type == 0 || ( i_length + 8 ) > AOUT_SPDIF_SIZE ) goto out; size_t i_out_length = p_in_buf->i_nb_samples * 4; p_out_buf = block_Alloc( i_out_length ); if( !p_out_buf ) goto out; uint8_t *p_out = p_out_buf->p_buffer; /* Copy the S/PDIF headers. */ void (*write16)(void *, uint16_t) = ( p_filter->fmt_out.audio.i_format == VLC_CODEC_SPDIFB ) ? SetWBE : SetWLE; write16( &p_out[0], 0xf872 ); /* syncword 1 */ write16( &p_out[2], 0x4e1f ); /* syncword 2 */ write16( &p_out[4], i_data_type ); /* data type */ write16( &p_out[6], i_length * 8 ); /* length in bits */ bool b_input_big_endian = is_big_endian( p_filter, p_in_buf ); bool b_output_big_endian = p_filter->fmt_out.audio.i_format == VLC_CODEC_SPDIFB; if( b_input_big_endian != b_output_big_endian ) { swab( p_in, p_out + 8, i_length & ~1 ); /* If i_length is odd, we have to adjust swapping a bit... */ if( i_length & 1 && ( i_length + 9 ) <= i_out_length ) { p_out[8 + i_length - 1] = 0; p_out[8 + i_length] = p_in[i_length-1]; i_length++; } } else memcpy( p_out + 8, p_in, i_length ); if( 8 + i_length < i_out_length ) /* padding */ memset( p_out + 8 + i_length, 0, i_out_length - i_length - 8 ); p_out_buf->i_dts = p_in_buf->i_dts; p_out_buf->i_pts = p_in_buf->i_pts; p_out_buf->i_nb_samples = p_in_buf->i_nb_samples; p_out_buf->i_buffer = i_out_length; out: block_Release( p_in_buf ); return p_out_buf; }
void led_set(struct packet_t *packet) { uart_putstr_P(PSTR("led_set()\r\n")); // XXX : WTF ??? if (get_data_type(packet)!=0x49) { uart_putstr_P(PSTR("not an integer")); return; } uart_putc(get_data_type(packet)); if (get_data_int16(packet) == 0) { uart_putstr_P(PSTR("clr_led()\r\n")); clr_output(LED1); } else { uart_putstr_P(PSTR("set_led()\r\n")); set_output(LED1); } }
void ann::get_num_outputs(int &num_outputs) const { const data_type data_type = get_data_type(); if (data_type == LABELLED_CLASSIFICATION) { num_outputs = defaults::num_output_dimensions; } else if (data_type == LABELLED_REGRESSION) { num_outputs = regression_data.getNumTargetDimensions(); } }
u_char * get_uchar_data(DDLSymbolTable *st, double vmin, double vmax, char **errmsg, u_char *outdata) { void *indata = (void *)st->GetData(); int type = get_data_type(st, errmsg); if (!type){ return NULL; } int bits=0; st->GetValue("bits", bits); int datasize = st->DataLength() / (bits/8); if (type != DDL_INT8){ if (!outdata){ outdata = new u_char[datasize]; } if (!outdata){ *errmsg = "Unable to allocate memory."; return NULL; } if (vmin == vmax){ // Auto scale /*autovscale(st, &vmin, &vmax);*/ vmin = 0; vmax = 1; } } switch (type){ case DDL_INT8: // No conversion to do (IGNORE SCALING ALSO) outdata = (u_char *)indata; break; case DDL_INT16: convertdata((u_short *)indata, outdata, datasize, vmin, vmax); break; case DDL_INT32: convertdata( (int *)indata, outdata, datasize, vmin, vmax); break; case DDL_FLOAT32: convertdata( (float *)indata, outdata, datasize, vmin, vmax); break; case DDL_FLOAT64: convertdata( (double *)indata, outdata, datasize, vmin, vmax); break; } return outdata; }
// Methods // NOTE: ANN is special since it supports both regression and classification, we therefore override these methods void ann::train() { const data_type data_type = get_data_type(); GRT::UINT numSamples = data_type == LABELLED_CLASSIFICATION ? classification_data.getNumSamples() : regression_data.getNumSamples(); if (numSamples == 0) { flext::error("no observations added, use 'add' to add training data"); return; } bool success = false; if (data_type == LABELLED_CLASSIFICATION) { grt_ann.init( classification_data.getNumDimensions(), num_hidden_neurons, classification_data.getNumClasses(), input_activation_function, hidden_activation_function, output_activation_function ); success = grt_ann.train(classification_data); } else if (data_type == LABELLED_REGRESSION) { grt_ann.init( regression_data.getNumInputDimensions(), num_hidden_neurons, regression_data.getNumTargetDimensions(), input_activation_function, hidden_activation_function, output_activation_function ); success = grt_ann.train(regression_data); } if (!success) { flext::error("training failed"); } t_atom a_success; SetInt(a_success, success); ToOutAnything(1, get_s_train(), 1, &a_success); }
void cell::set_hyperlink(const std::string &hyperlink) { if (hyperlink.length() == 0 || std::find(hyperlink.begin(), hyperlink.end(), ':') == hyperlink.end()) { throw data_type_exception(); } d_->has_hyperlink_ = true; d_->hyperlink_ = worksheet(d_->parent_).create_relationship(relationship::type::hyperlink, hyperlink); if (get_data_type() == type::null) { set_value(hyperlink); } }
bool ann::write_specialised_dataset(std::string &path) const { const data_type data_type = get_data_type(); if (data_type == LABELLED_CLASSIFICATION) { return classification_data.saveDatasetToFile(path); } else if (data_type == LABELLED_REGRESSION) { return regression_data.saveDatasetToFile(path); } flext::error("unable to write dataset, invalid data type: %d", data_type); return false; }
static void column_name (struct gml_params *params, const char *el) { /* handling a column name */ char prefix[1024]; char name[1024]; int type; if (params->is_point || params->is_multi_point || params->is_linestring || params->is_multi_linestring || params->is_polygon || params->is_multi_polygon) return; if (params->geometry_column) return; else type = get_data_type (params->CharData); split_fid (el, prefix, name); if (strcasecmp (prefix, params->fid_prefix) != 0) return; add_column (params, name, type); }
std::string cell::to_string() const { auto nf = get_number_format(); switch (get_data_type()) { case cell::type::null: return ""; case cell::type::numeric: return get_number_format().format(get_value<long double>(), get_base_date()); case cell::type::string: case cell::type::formula: case cell::type::error: return get_number_format().format(get_value<std::string>()); case cell::type::boolean: return get_value<long double>() == 0 ? "FALSE" : "TRUE"; default: return ""; } }
/* ========================================================================= */ struct pitem *mdf_mkpitem(struct qparts *qp, struct mnt_item *the_mount) { struct pitem *this_pitem; unsigned long sioffset; int data_type; void *data_ptr; /* This is slightly cleaner than an assert */ if ((NULL == qp) || (NULL == the_mount)) return(NULL); /* Determine the data item wanted */ if ( PI_NOT_SET == (sioffset = parse_mpdi(qp->iname)) ) { error_msg("ERROR: Data item \"%s\" not understood.", qp->iname); return(NULL); } /* sioffset is known good at this point. The following two must be good as well */ /* If not (for some reason) then NewPItem() will catch the unsupported value */ data_type = get_data_type(sioffset); data_ptr = make_data_type(sioffset, qp->pargs); /* If all good, then create a pitem */ if ( NULL == (this_pitem = NewPItem(qp, data_type, data_ptr)) ) return(NULL); /* Add the additional data items */ this_pitem->dstruct = (void *)the_mount; this_pitem->sioffset = sioffset; /* The specific data item requested. NOTE: sioffset is NOT used as an offset, but as a flag using one of the TS_* defines above */ /* Shove this into the ui_list */ this_pitem->next_ui = myself->ui_list; myself->ui_list = this_pitem; return(this_pitem); }
int semantic_check(node *ast) { if(!ast) return 0; int btype; switch((int)ast->kind) { case UNKNOWN: break; case NSCOPE: lhs = semantic_check(ast->scope.declarations); if(lhs == -1) return -1; rhs = semantic_check(ast->scope.statements); if(rhs == -1) return -1; if(lhs > rhs) return lhs; else return rhs; break; case NDECLARATIONS: lhs = semantic_check(ast->declarations.declarations); if(lhs == -1) return -1; rhs = semantic_check(ast->declarations.declaration); if(rhs == -1) return -1; else return rhs; break; case NSTATEMENTS: lhs = semantic_check(ast->statements.statements); if(lhs == -1) return -1; rhs = semantic_check(ast->statements.statement); if(rhs == -1) return -1; else return rhs; break; case NTYPE_DECLARATION: if(isVarDeclared(sym_table, ast->type_declaration.id, scopeNum)) { fprintf(errorFile, "Error: Variable cannot be re-declared within the same scope\n"); errorOccurred = 1; return -1; } else return semantic_check(ast->type_declaration.type); break; case NASSIGN_DECLARATION: lhs = semantic_check(ast->assign_declaration.type); if(lhs == -1) return -1; rhs = semantic_check(ast->assign_declaration.expression); if(rhs == -1) return -1; if(isVarDeclared(sym_table, ast->assign_declaration.id, scopeNum)) { fprintf(errorFile, "Error: Variable cannot be re-declared within the same scope\n"); errorOccurred = 1; return -1; } if(lhs == rhs) return lhs; else if((lhs == IVEC2 || lhs == IVEC3 || lhs == IVEC4) && (rhs == INT)) return INT; else if((lhs == BVEC2 || lhs == BVEC3 || lhs == BVEC4) && (rhs == BOOL)) return BOOL; else if((lhs == VEC2 || lhs == VEC3 || lhs == VEC4) && (rhs == FLOAT)) return FLOAT; else { fprintf(errorFile, "Error: Declaration failed, type mismatch in assignment\n"); errorOccurred = 1; return -1; } break; case NCONST_DECLARATION: lhs = semantic_check(ast->const_declaration.type); if(lhs == -1) return -1; rhs = semantic_check(ast->const_declaration.expression); if(rhs == -1) return -1; type_class = get_tClass(sym_table, ast->const_declaration.type->id_variable.id); if(ast->const_declaration.type->kind != NINT_EXPR && ast->const_declaration.type->kind != NFLOAT_EXPR && ast->const_declaration.type->kind != NBOOL_EXPR && ast->const_declaration.type->kind != NTYPE_EXPR && ast->const_declaration.type->kind != NARRAY_VARIABLE && type_class != _CONST && type_class != UNIFORM) { fprintf(errorFile, "Error: 'const' qualified variables must be initialized with a literal value or with a uniform variable\n"); errorOccurred = 1; return -1; } if(lhs == rhs) return lhs; else if((lhs == IVEC2 || lhs == IVEC3 || lhs == IVEC4) && (rhs == INT)) return INT; else if((lhs == VEC2 || lhs == VEC3 || lhs == VEC4) && (rhs == FLOAT)) return FLOAT; else if((lhs == BVEC2 || lhs == BVEC3 || lhs == BVEC4) && (rhs == BOOL)) return BOOL; else { fprintf(errorFile, "Error: Type mismatch in assignment\n"); errorOccurred = 1; return -1; } break; case NASSIGN_STATEMENT: lhs = semantic_check(ast->assign_statement.variable); if(lhs == -1) return -1; rhs = semantic_check(ast->assign_statement.expression); if(rhs == -1) return -1; else return CheckTypes(rhs, lhs); break; case NIF_STATEMENT: lhs = semantic_check(ast->if_statement.condition); if(lhs == -1) return -1; if(lhs == BOOL) semantic_check(ast->if_statement.statement); else { fprintf(errorFile, "Error: Condition must be of type 'bool'\n"); errorOccurred = 1; return -1; } break; case NIF_ELSE_STATEMENT: lhs = semantic_check(ast->if_else_statement.condition); if(lhs == -1) return -1; if(lhs == BOOL) { semantic_check(ast->if_else_statement.statement); semantic_check(ast->if_else_statement.else_statement); } else { fprintf(errorFile, "Error: Condition must be of type 'bool'\n"); errorOccurred = 1; return -1; } break; case NSCOPE_STATEMENT: scopeNum++; check_prog_scope = semantic_check(ast->prog_scope.scope); scopeNum--; return check_prog_scope; break; //unary expression case NUNARY_EXPR: rhs = semantic_check(ast->unary_expr.right); if(rhs == -1) return -1; if(ast->unary_expr.op == MINUS_OPS) { if(rhs == BOOL || rhs == BVEC2|| rhs == BVEC3|| rhs == BVEC4){ fprintf(errorFile, "Error: All operands to arithmetic operators must have arithmetic types\n"); errorOccurred = 1; return -1; } else return rhs; } if(ast->unary_expr.op == NOT_OPS) { if(rhs != BOOL || rhs != BVEC2 || rhs != BVEC3 || rhs != BVEC4) { fprintf(errorFile, "Error: All operands to logical operators must have boolean types\n"); errorOccurred = 1; return -1; } else return rhs; } break; case NBINARY_EXPR: rhs = semantic_check(ast->binary_expr.right); if(rhs == -1) return -1; lhs = semantic_check(ast->binary_expr.left); btype = CheckTypes(rhs, lhs); if(lhs == -1){ return -1; }else if(btype == -1){ fprintf(errorFile, "Error: The operands to binary operators must have same base types\n"); errorOccurred = 1; return -1; }else if(vectorChecking(rhs) == 1 && vectorChecking(lhs) == 1){ if(vectorCompare(rhs, lhs) == 0){ fprintf(errorFile, "Error: The vector operands to binary operators must have same order\n"); errorOccurred = 1; return -1; }else{ btype = BOOL; ast->binary_expr.type = btype; return btype; } }else if(ast->binary_expr.op == AND_OPS || ast->binary_expr.op == OR_OPS ||ast->binary_expr.op == EQ_OPS || ast->binary_expr.op == NEQ_OPS){ if(rhs != BOOL || rhs != BVEC2 || rhs != BVEC3 || rhs != BVEC4 || lhs != BOOL || lhs != BVEC2 || lhs != BVEC3 || lhs != BVEC4){ fprintf(errorFile, "Error: All operands to logical operators must have boolean types\n"); errorOccurred = 1; return -1; }else if((vectorChecking(rhs) && !vectorChecking(lhs)) || (!vectorChecking(rhs) && vectorChecking(lhs))){ fprintf(errorFile, "Error: The operands to logical operators must be both vectors or both scalars\n"); errorOccurred = 1; return -1; }else{ btype = BOOL; ast->binary_expr.type = btype; return btype; } }else if(ast->binary_expr.op == LESS_OPS || ast->binary_expr.op == LEQ_OPS ||ast->binary_expr.op == GTR_OPS || ast->binary_expr.op == GEQ_OPS || ast->binary_expr.op == PLUS_OPS || ast->binary_expr.op == MINUS_OPS || ast->binary_expr.op == DIVIDE_OPS || ast->binary_expr.op == POW_OPS || ast->binary_expr.op == TIMES_OPS){ if(rhs == BOOL || rhs == BVEC2|| rhs == BVEC3|| rhs == BVEC4 || lhs == BOOL || lhs == BVEC2|| lhs == BVEC3|| lhs == BVEC4){ fprintf(errorFile, "Error: All operands to arithmetic operators must have arithmetic types.\n"); errorOccurred = 1; return -1; }else if( ast->binary_expr.op != TIMES_OPS && (vectorChecking(rhs) == 1 || vectorChecking(lhs) == 1)){ fprintf(errorFile, "Error: The operands to arithmetic operators (except for times) must be both vectors or both scalars\n"); errorOccurred = 1; return -1; }else{ btype = BOOL; ast->binary_expr.type = btype; return btype; } } else return -1; break; case NBRACKETS_EXPR: return semantic_check(ast->brackets_expr.expression); break; case NFUNC_EXPR: rhs = semantic_check(ast->func_expr.arguments_opt); if(rhs == -1) return -1; switch(ast->func_expr.func) { case 0: if(rhs == IVEC3 || rhs == IVEC4) return INT; else if(rhs == VEC3 || rhs == VEC4) return FLOAT; else { fprintf(errorFile, "Error: Function argument doesn't match as expected ('db3' supports arguments of type 'vec3', 'vec4', 'ivec3' & 'ivec4')\n"); errorOccurred = 1; return -1; } break; case 1: if(rhs == VEC4) return VEC4; else { fprintf(errorFile, "Error: Function argument doesn't match as expected ('lit' only supports argument of type 'vec4')\n"); errorOccurred = 1; return -1; } break; case 2: if(rhs == FLOAT || rhs == INT) return FLOAT; else { fprintf(errorFile, "Error: Function argument doesn't match as expected ('rsq' supports arguments of type 'int' & 'float')\n"); errorOccurred = 1; return -1; } break; default: fprintf(errorFile, "Error: Function name doesn't match as expected (supported function names - 'db3', 'lit' & 'rsq')\n"); errorOccurred = 1; return -1; break; } break; case NTYPE_EXPR: lhs = semantic_check(ast->type_expr.type); if(lhs == -1) return -1; rhs = semantic_check(ast->type_expr.arguments_opt); if(rhs == -1) return -1; numArgs = countArg(ast->type_expr.arguments_opt); if((lhs == IVEC2 && numArgs == 2) || (lhs == IVEC3 && numArgs == 3) || (lhs == IVEC4 && numArgs == 4) || (lhs == BVEC2 && numArgs == 2) || (lhs == BVEC3 && numArgs == 3) || (lhs == BVEC4 && numArgs == 4) || (lhs == VEC2 && numArgs == 2) || (lhs == VEC3 && numArgs == 3) || (lhs == VEC4 && numArgs == 4) || (lhs == BOOL && numArgs == 1) || (lhs == INT && numArgs == 1) || (lhs == FLOAT && numArgs == 1)) ; else { fprintf(errorFile, "Error: Costructors for basic types (bool, int, float) must have one argument and vector types must have as many arguments as there are elements in the vector\n"); errorOccurred = 1; return -1; } if(lhs == rhs) return lhs; else if((lhs == IVEC2 || lhs == IVEC3 || lhs == IVEC4) && (rhs == INT)) return INT; else if((lhs == VEC2 || lhs == VEC3 || lhs == VEC4) && (rhs == FLOAT)) return FLOAT; else if((lhs == BVEC2 || lhs == BVEC3 || lhs == BVEC4) && (rhs == BOOL)) return BOOL; else { fprintf(errorFile, "Error: Type mismatch found\n"); errorOccurred = 1; return -1; } break; case NVAR_EXPR: return semantic_check(ast->var_expr.variable); break; case NINT_EXPR: return INT; break; case NFLOAT_EXPR: return FLOAT; break; case NBOOL_EXPR: return BOOL; break; case NID_VARIABLE: id = ast->id_variable.id; if(!isVarDeclaredInScope(sym_table, id, scopeNum)) { fprintf(errorFile, "Error: Variable cannot be used before it is declared\n"); errorOccurred = 1; return -1; } else if(strcmp(id, "TEMP") == 0 || strcmp(id, "ADDRESS") == 0) { fprintf(errorFile, "Error: Reserved words can not be used as variable\n"); errorOccurred = 1; return -1; } else { type_class = get_tClass(sym_table, id); if(type_class == _CONST) { fprintf(errorFile, "Error: Variable cannot be used before it is declared\n"); errorOccurred = 1; return -1; } return get_data_type(sym_table, id); } break; case NARRAY_VARIABLE: x = ast->array_variable.index; type = get_data_type(sym_table, ast->array_variable.id); if(type == IVEC2 || type == IVEC3 || type == IVEC4 || type == BVEC2 || type == BVEC3 || type == BVEC4 || type == VEC2 || type == VEC3 || type == VEC4) ; else { fprintf(errorFile, "Error: Only 'vec' type supported\n"); errorOccurred = 1; return -1; } if((type == IVEC2 && x < 2) || (type == IVEC3 && x < 3) || (type == IVEC4 && x < 4) || (type == BVEC2 && x < 2) || (type == BVEC3 && x < 3) || (type == BVEC4 && x < 4) || (type == VEC2 && x < 2) || (type == VEC3 && x < 3) || (type == VEC4 && x < 4)) ; else { fprintf(errorFile, "Error: Index limit exceeded\n"); errorOccurred = 1; return -1; } if(type == IVEC2 || type == IVEC3 || type == IVEC4) return INT; if(type == BVEC2 || type == BVEC3 || type == BVEC4) return BOOL; if(type == VEC2 || type == VEC3 || type == VEC4) return FLOAT; break; case NARGS_ARGUMENTS: lhs = semantic_check(ast->args_arguments.arguments); if(lhs == -1) return -1; rhs = semantic_check(ast->args_arguments.expression); if(rhs == -1) return -1; else if(lhs == rhs) return lhs; else { fprintf(errorFile, "Error: Mismatch in arguments\n"); errorOccurred = 1; return -1; } break; case NEXPR_ARGUMENTS: return semantic_check(ast->expr_arguments.expression); break; case NARGUMENTS_OPT: return semantic_check(ast->arguments_opt.arguments); break; case NTYPE: return ast->type.type_kind; break; case NPROG_SCOPE: scopeNum++; check_prog_scope = semantic_check(ast->prog_scope.scope); scopeNum--; return check_prog_scope; break; default: return -1; break; } return 0; // failed checks }
void ann::map(int argc, const t_atom *argv) { const data_type data_type = get_data_type(); GRT::UINT numSamples = data_type == LABELLED_CLASSIFICATION ? classification_data.getNumSamples() : regression_data.getNumSamples(); if (numSamples == 0) { flext::error("no observations added, use 'add' to add training data"); return; } if (grt_ann.getTrained() == false) { flext::error("model has not been trained, use 'train' to train the model"); return; } GRT::UINT numInputNeurons = grt_ann.getNumInputNeurons(); GRT::VectorDouble query(numInputNeurons); if (argc < 0 || (unsigned)argc != numInputNeurons) { flext::error("invalid input length, expected %d, got %d", numInputNeurons, argc); } for (uint32_t index = 0; index < (uint32_t)argc; ++index) { double value = GetAFloat(argv[index]); query[index] = value; } bool success = grt_ann.predict(query); if (success == false) { flext::error("unable to map input"); return; } if (grt_ann.getClassificationModeActive()) { const GRT::VectorDouble likelihoods = grt_ann.getClassLikelihoods(); const GRT::Vector<GRT::UINT> labels = classification_data.getClassLabels(); const GRT::UINT predicted = grt_ann.getPredictedClassLabel(); const GRT::UINT classification = predicted == 0 ? 0 : get_class_id_for_index(predicted); if (likelihoods.size() != labels.size()) { flext::error("labels / likelihoods size mismatch"); } else if (probs) { AtomList probs_list; for (unsigned count = 0; count < labels.size(); ++count) { t_atom label_a; t_atom likelihood_a; SetFloat(likelihood_a, static_cast<float>(likelihoods[count])); SetInt(label_a, get_class_id_for_index(labels[count])); probs_list.Append(label_a); probs_list.Append(likelihood_a); } ToOutAnything(1, get_s_probs(), probs_list); } ToOutInt(0, classification); } else if (grt_ann.getRegressionModeActive()) { GRT::VectorDouble regression_data = grt_ann.getRegressionData(); GRT::VectorDouble::size_type numOutputDimensions = regression_data.size(); if (numOutputDimensions != grt_ann.getNumOutputNeurons()) { flext::error("invalid output dimensions: %d", numOutputDimensions); return; } AtomList result; for (uint32_t index = 0; index < numOutputDimensions; ++index) { t_atom value_a; double value = regression_data[index]; SetFloat(value_a, value); result.Append(value_a); } ToOutList(0, result); } }
void ann::add(int argc, const t_atom *argv) { if (get_data_type() != data_type::LABELLED_CLASSIFICATION) { ml::add(argc, argv); return; } // work around a bug in GRT where class labels must be contigious if (argc < 2) { flext::error("invalid input length, must contain at least 2 values"); return; } GRT::UINT numInputDimensions = classification_data.getNumDimensions(); GRT::UINT numOutputDimensions = 1; GRT::UINT combinedVectorSize = numInputDimensions + numOutputDimensions; if ((unsigned)argc != combinedVectorSize) { numInputDimensions = argc - numOutputDimensions; if (numInputDimensions < 1) { flext::error(std::string("invalid input length, expected at least " + std::to_string(numOutputDimensions + 1)).c_str()); return; } post("new input vector size, adjusting num_inputs to " + std::to_string(numInputDimensions)); set_num_inputs(numInputDimensions); } GRT::VectorDouble inputVector(numInputDimensions); GRT::VectorDouble targetVector(numOutputDimensions); for (uint32_t index = 0; index < (unsigned)argc; ++index) { float value = GetAFloat(argv[index]); if (index < numOutputDimensions) { targetVector[index] = value; } else { inputVector[index - numOutputDimensions] = value; } } GRT::UINT label = get_index_for_class((GRT::UINT)targetVector[0]); assert(label > 0); // if ((double)label != targetVector[0]) // { // flext::error("class label must be a positive integer"); // return; // } // // if (label == 0) // { // flext::error("class label must be non-zero"); // return; // } classification_data.addSample(label, inputVector); }
static void get_min_max(DDLSymbolTable *st, float *vmin, float *vmax) { char *errmsg; int npts = (get_image_width(st) * get_image_height(st) * get_image_depth(st)); int type = get_data_type(st, &errmsg); switch (type){ case DDL_INT8: { u_char *data = (u_char *)get_ddl_data(st); u_char *end = data + npts; u_char min = *data; u_char max = *data++; u_char x; while (data < end){ if ((x=*data++) < min){ min = x; }else if (x > max){ max = x; } } *vmin = (float)min; *vmax = (float)max; } break; case DDL_INT16: { u_short *data = (u_short *)get_ddl_data(st); u_short *end = data + npts; u_short min = *data; u_short max = *data++; u_short x; while (data < end){ if ((x=*data++) < min){ min = x; }else if (x > max){ max = x; } } *vmin = (float)min; *vmax = (float)max; } break; case DDL_INT32: { int *data = (int *)get_ddl_data(st); int *end = data + npts; int min = *data; int max = *data++; int x; while (data < end){ if ((x=*data++) < min){ min = x; }else if (x > max){ max = x; } } *vmin = (float)min; *vmax = (float)max; } break; case DDL_FLOAT32: { float *data = (float *)get_ddl_data(st); float *end = data + npts; float min = *data; float max = *data++; float x; while (data < end){ if ((x=*data++) < min){ min = x; }else if (x > max){ max = x; } } *vmin = (float)min; *vmax = (float)max; } break; case DDL_FLOAT64: { double *data = (double *)get_ddl_data(st); double *end = data + npts; double min = *data; double max = *data++; double x; while (data < end){ if ((x=*data++) < min){ min = x; }else if (x > max){ max = x; } } *vmin = (float)min; *vmax = (float)max; } break; } }
// Flext attribute getters void ann::get_mode(int &mode) const { mode = get_data_type(); }
static void get_histogram(DDLSymbolTable *st, float min, float max, int *histogram, int nbins) { int i; char *errmsg; int npts = (get_image_width(st) * get_image_height(st) * get_image_depth(st)); float scale = (nbins - 1) / (max - min); for (i=0; i<nbins; i++){ histogram[i] = 0; } int type = get_data_type(st, &errmsg); switch (type){ case DDL_INT8: { u_char *data = (u_char *)get_ddl_data(st); u_char *end = data + npts; while (data < end){ histogram[(int)((*data++ - min) * scale)]++; } } break; case DDL_INT16: { u_short *data = (u_short *)get_ddl_data(st); u_short *end = data + npts; while (data < end){ histogram[(int)((*data++ - min) * scale)]++; } } break; case DDL_INT32: { int *data = (int *)get_ddl_data(st); int *end = data + npts; while (data < end){ histogram[(int)((*data++ - min) * scale)]++; } } break; case DDL_FLOAT32: { float *data = (float *)get_ddl_data(st); float *end = data + npts; while (data < end){ histogram[(int)((*data++ - min) * scale)]++; } } break; case DDL_FLOAT64: { double *data = (double *)get_ddl_data(st); double *end = data + npts; while (data < end){ histogram[(int)((*data++ - min) * scale)]++; } } break; } }
bool cell::garbage_collectible() const { return !(get_data_type() != type::null || is_merged() || has_comment() || has_formula() || has_style()); }
bool cell::is_date() const { return get_data_type() == type::numeric && get_number_format().is_date_format(); }
void sqlite_source::prepare_data( const std::string & database_name, const std::string & sql) throw( std::logic_error, std::invalid_argument) { check_not_running(); delete_data(); sqlite3_stmt* data = get_stmt(database_name, sql); int column_count = sqlite3_column_count(data); if (column_count == 0) //statement is no SELECT statement { throw std::invalid_argument("Statement is no SQL SELECT statement."); } m_data = data; m_column_count = column_count; m_time_column = sqlite3_bind_parameter_index(m_data, get_duration_string().c_str()); m_database_name = database_name; m_sql = sql; std::vector<column_info> column_infos; sqlite3* db_handle = sqlite3_db_handle(m_data); char const* data_type = NULL; char const* coll_seq = NULL; int not_null = 0; int primary_key = 0; int auto_inc = 0; for (int i = 0; i < m_column_count; ++i) { std::string column_name = sqlite3_column_origin_name(m_data, i); int result_code = sqlite3_table_column_metadata( db_handle, sqlite3_column_database_name(m_data, i), sqlite3_column_table_name(m_data, i), column_name.c_str(), &data_type, &coll_seq, ¬_null, &primary_key, &auto_inc); if (result_code != SQLITE_OK) { //TODO: do something with the error...this error can only be an internal db error } if (i + 1 != m_time_column) { std::string type(data_type); column_info info(column_name, m_source_name, get_data_type(data_type)); column_infos.push_back(info); } } m_stream_schema = stream_schema_ptr(new stream_schema(m_source_name, column_infos)); }