static double get_norm(SEXP obj, const char *typstr) { char typnm[] = {'\0', '\0'}; int *dims = INTEGER(GET_SLOT(obj, Matrix_DimSym)); double *work = (double *) NULL; typnm[0] = norm_type(typstr); if (*typnm == 'I') { work = (double *) R_alloc(dims[0], sizeof(double)); } return F77_CALL(dlantr)(typnm, uplo_P(obj), diag_P(obj), dims, dims+1, REAL(GET_SLOT(obj, Matrix_xSym)), dims, work); }
bool ISNorm::SaveParams(const ssi_char_t *path, Params ¶ms, File::TYPE type) { ssi_char_t string[SSI_MAX_CHAR]; FilePath fp(path); ssi_char_t *path_xml; ssi_char_t *path_data; if (ssi_strcmp(fp.getExtension(), "norm", false)) { path_xml = ssi_strcpy(path); } else { path_xml = ssi_strcat(path, ".norm"); } path_data = ssi_strcat(path_xml, "~"); TiXmlElement norm("norm"); TiXmlElement norm_method("method"); norm_method.InsertEndChild(TiXmlText(METHOD_NAMES[params.method])); norm.InsertEndChild(norm_method); if (params.method == METHOD::SCALE) { TiXmlElement norm_limits("limits"); ssi_sprint(string, "%f %f", params.limits[0], params.limits[1]); norm_limits.InsertEndChild(TiXmlText(string)); norm.InsertEndChild(norm_limits); } TiXmlElement norm_dim("dim"); ssi_sprint(string, "%u", params.n_features); norm_dim.InsertEndChild(TiXmlText(string)); norm.InsertEndChild(norm_dim); TiXmlElement norm_type("type"); norm_type.InsertEndChild(TiXmlText(File::TYPE_NAMES[type])); norm.InsertEndChild(norm_type); TiXmlDocument doc; TiXmlDeclaration head("1.0", "", ""); doc.InsertEndChild(head); doc.InsertEndChild(norm); doc.SaveFile(path_xml); if (params.method != METHOD::NONE) { FILE *fp = fopen(path_data, type == File::BINARY ? "wb" : "w"); if (fp) { switch (params.method) { case METHOD::SCALE: if (type == File::BINARY) { fwrite(params.mins, params.n_features, sizeof(ssi_real_t), fp); fwrite(params.maxs, params.n_features, sizeof(ssi_real_t), fp); } else { ssi_real_t *mins = params.mins; ssi_real_t *maxs = params.maxs; for (ssi_size_t i = 0; i < params.n_features; i++) { ssi_fprint(fp, "%f %f\n", *mins++, *maxs++); } } break; case METHOD::ZSCORE: if (type == File::BINARY) { fwrite(params.mean, params.n_features, sizeof(ssi_real_t), fp); fwrite(params.stdv, params.n_features, sizeof(ssi_real_t), fp); } else { ssi_real_t *mean = params.mean; ssi_real_t *stdv = params.stdv; for (ssi_size_t i = 0; i < params.n_features; i++) { ssi_fprint(fp, "%f %f\n", *mean++, *stdv++); } } break; } } else { ssi_wrn("could not open file '%s'", path_data); return false; } fclose(fp); } delete[] path_data; delete[] path_xml; return true; }