SpikePatternsList* runNeurons(pMatrixVector *ts_data, doubleVector *ts_labels, Constants *c, bool saveStat) { indVector *ts_indices = TEMPLATE(createVector,ind)(); for(size_t ti=0; ti< ts_data->size; ti++) { TEMPLATE(insertVector,ind)(ts_indices, ti); } srand(time(NULL)); shuffleIndVector(ts_indices); double t = 0.0; AdExLayer *l = createAdExLayer(c->preproc->N, saveStat); SpikePatternsList *spl = createSpikePatternsList(c->preproc->N); for(size_t ts_i=0; ts_i < ts_indices->size; ts_i++) { doubleVector *ts = doubleVectorFromMatrix(ts_data->array[ ts_indices->array[ts_i] ]); toStartValuesAdExLayer(l, c); size_t j; for(j = 0; j < ts->size; t+= c->preproc->dt, j++) { double I = ts->array[j]; for(size_t ni=0; ni < l->N; ni++) { propagateCurrentAdExLayer(l, &ni, &I); simulateAdExLayerNeuron(l, &ni, c); if(l->fired[ni] == 1) { TEMPLATE(insertVector,double)(spl->sl->list[ni], t); l->fired[ni] = 0; } } } TEMPLATE(insertVector,double)(spl->timeline, t); TEMPLATE(insertVector,double)(spl->pattern_classes, ts_labels->array[ts_indices->array[ts_i] ]); } return(spl); }
SparseMatrix* createSparseMatrix(size_t nr, size_t nc) { SparseMatrix *sm = (SparseMatrix*)malloc(sizeof(SparseMatrix)); sm->values = TEMPLATE(createVector,double)(0); sm->row_ind = TEMPLATE(createVector,ind)(0); sm->col_ptr = TEMPLATE(createVector,ind)(nc); sm->nrow = nr; sm->ncol = nc; return(sm); }
ucharVector* serialize_doubleVector(doubleVector *x) { ucharVector *v = TEMPLATE(createVector,uchar)(); for(size_t i=0; i < x->size; i++) { unsigned char b[100]; // 100 bytes enough for everyone unsigned int nb = pack(b, 'd', x->array[vi]); for(size_t bi=0; bi < nb; bi++) { TEMPLATE(insertVector,uchar)(b[bi]); } } return(v); }
TripleSTDP* init_TripleSTDP(LayerPoisson *l) { TripleSTDP *ls = (TripleSTDP*) malloc( sizeof(TripleSTDP) ); ls->base.l = l; if(l->stat->statLevel>0) { ls->stat_o_one = (doubleVector**) malloc( l->N*sizeof(doubleVector*)); ls->stat_o_two = (doubleVector**) malloc( l->N*sizeof(doubleVector*)); ls->stat_a_minus = (doubleVector**) malloc( l->N*sizeof(doubleVector*)); ls->stat_pacc = (doubleVector**) malloc( l->N*sizeof(doubleVector*)); ls->stat_r = (doubleVector***) malloc( l->N*sizeof(doubleVector**)); } ls->learn_syn_ids = (indLList**) malloc( l->N*sizeof(indLList*)); ls->o_one = (double*)malloc( l->N*sizeof(double)); ls->o_two = (double*)malloc( l->N*sizeof(double)); ls->r = (double**)malloc( l->N*sizeof(double*)); ls->pacc = (double*)malloc( l->N*sizeof(double)); for(size_t ni=0; ni<l->N; ni++) { ls->learn_syn_ids[ni] = TEMPLATE(createLList,ind)(); ls->r[ni] = (double*) malloc(l->nconn[ni]*sizeof(double)); if(l->stat->statLevel>0) { ls->stat_o_one[ni] = TEMPLATE(createVector,double)(); ls->stat_o_two[ni] = TEMPLATE(createVector,double)(); ls->stat_a_minus[ni] = TEMPLATE(createVector,double)(); ls->stat_pacc[ni] = TEMPLATE(createVector,double)(); ls->stat_r[ni] = (doubleVector**) malloc( l->nconn[ni]*sizeof(doubleVector*)); for(size_t con_i=0; con_i < l->nconn[ni]; con_i++) { ls->stat_r[ni][con_i] = TEMPLATE(createVector,double)(); } } }
OptimalSTDP* init_OptimalSTDP(LayerPoisson *l) { OptimalSTDP *ls = (OptimalSTDP*) malloc( sizeof(OptimalSTDP)); ls->base.l = l; ls->learn_syn_ids = (indLList**) malloc( l->N*sizeof(indLList*)); ls->B = (double*)malloc( l->N*sizeof(double)); ls->C = (double**)malloc( l->N*sizeof(double*)); ls->pacc = (double*)malloc( l->N*sizeof(double)); if(l->stat->statLevel>1) { ls->stat_B = (doubleVector**) malloc( l->N*sizeof(doubleVector*)); ls->stat_C = (doubleVector***) malloc( l->N*sizeof(doubleVector**)); } ls->eligibility_trace = (double*) malloc( l->N*sizeof(double)); for(size_t ni=0; ni<l->N; ni++) { ls->learn_syn_ids[ni] = TEMPLATE(createLList,ind)(); ls->C[ni] = (double*) malloc(l->nconn[ni]*sizeof(double)); ls->pacc[ni] = 0; ls->eligibility_trace[ni] = 0; if(l->stat->statLevel>1) { ls->stat_B[ni] = TEMPLATE(createVector,double)(); ls->stat_C[ni] = (doubleVector**) malloc( l->nconn[ni]*sizeof(doubleVector*)); for(size_t con_i=0; con_i < l->nconn[ni]; con_i++) { ls->stat_C[ni][con_i] = TEMPLATE(createVector,double)(); } } }
/* This file is part of RIBS2.0 (Robust Infrastructure for Backend Systems). RIBS is an infrastructure for building great SaaS applications (but not limited to). Copyright (C) 2012,2013 Adap.tv, Inc. RIBS is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, version 2.1 of the License. RIBS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with RIBS. If not, see <http://www.gnu.org/licenses/>. */ _RIBS_INLINE_ int TEMPLATE(VMBUF_T,init)(struct VMBUF_T *vmb, size_t initial_size) { if (NULL == vmb->buf) { if (initial_size < 4096) initial_size = 4096; initial_size = RIBS_VM_ALIGN(initial_size); vmb->buf = (char *)mmap(NULL, initial_size, PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0); if (MAP_FAILED == vmb->buf) { perror("mmap, vmbuf_init"); vmb->buf = NULL; return -1; } vmb->capacity = initial_size; } else if (vmb->capacity < initial_size) TEMPLATE(VMBUF_T,resize_to)(vmb, initial_size); TEMPLATE(VMBUF_T,reset)(vmb); return 0; }
void setSparseMatrixCol(SparseMatrix *sm, size_t j, doubleVector *vals) { assert(j < sm->ncol); assert(sm->col_ptr->array[j] == 0); for(size_t m=0; m < sm->nrow; m++) { if(val[m] != 0) { TEMPLATE(insertVector,ind)(sm->row_ind, m); TEMPLATE(insertVector,double)(sm->values, val[m]); sm->col_ptr->array[j] = sm->col_ptr->array[j] + 1; } } }
SRMLayer* createSRMLayer(size_t N, size_t *glob_idx, unsigned char statLevel) { SRMLayer *l = (SRMLayer*)malloc(sizeof(SRMLayer)); l->N = N; l->ids = (size_t*)malloc( l->N*sizeof(size_t)); l->nt = (nspec_t*)malloc( l->N*sizeof(nspec_t)); for(size_t ni=0; ni<l->N; ni++) { l->ids[ni] = (*glob_idx)++; } l->W = (double**)malloc( l->N*sizeof(double*)); l->syn = (double**)malloc( l->N*sizeof(double*)); l->syn_spec = (double**)malloc( l->N*sizeof(double*)); l->id_conns = (size_t**)malloc( l->N*sizeof(size_t*)); l->nconn = (int*)malloc( l->N*sizeof(int)); for(size_t ni=0; ni<l->N; ni++) { l->nconn[ni] = 0; } l->active_syn_ids = (indLList**) malloc( l->N*sizeof(indLList*)); for(size_t ni=0; ni<l->N; ni++) { l->active_syn_ids[ni] = TEMPLATE(createLList,ind)(); } l->a = (double*)malloc( l->N*sizeof(double)); l->gr = (double*)malloc( l->N*sizeof(double)); l->ga = (double*)malloc( l->N*sizeof(double)); l->gb = (double*)malloc( l->N*sizeof(double)); l->axon_del = (double*)malloc( l->N*sizeof(double)); l->syn_del = (double**)malloc( l->N*sizeof(double)); l->fired = (unsigned char*)malloc( l->N*sizeof(unsigned char)); l->pacc = (double*)malloc( l->N*sizeof(double)); l->syn_fired = (unsigned char**)malloc( l->N*sizeof(unsigned char*)); l->statLevel = statLevel; if(l->statLevel > 0) { l->stat_p = (doubleVector**) malloc( l->N*sizeof(doubleVector*)); l->stat_fired = (doubleVector**) malloc( l->N*sizeof(doubleVector*)); for(size_t ni=0; ni<l->N; ni++) { l->stat_p[ni] = TEMPLATE(createVector,double)(); l->stat_fired[ni] = TEMPLATE(createVector,double)(); } if(l->statLevel > 1) { l->stat_u = (doubleVector**) malloc( l->N*sizeof(doubleVector*)); l->stat_W = (doubleVector***) malloc( l->N*sizeof(doubleVector**)); l->stat_syn = (doubleVector***) malloc( l->N*sizeof(doubleVector**)); for(size_t ni=0; ni<l->N; ni++) { l->stat_u[ni] = TEMPLATE(createVector,double)(); } }
int main(int argc, char **argv) { srand(time(NULL)); ArgOptionsFilt a = parseFiltOptions(argc, argv); pMatrixVector* ts_data = readMatrixListFromFile(a.input_file); pMatrixVector* target_data = readMatrixListFromFile(a.target_values_file); assert(ts_data->size > 0); assert(target_data->size > 0); Matrix *spike_data = ts_data->array[0]; doubleVector *target = doubleVectorFromMatrix(target_data->array[0]); assert(spike_data->ncol == target->size); Matrix *w_opt = runLbfgsOptim(spike_data, target, a.filter_size, a.jobs, a.epsilon); pMatrixVector *out = TEMPLATE(createVector,pMatrix)(); TEMPLATE(insertVector,pMatrix)(out, w_opt); saveMatrixListToFile(a.output_file, out); TEMPLATE(deleteVector,pMatrix)(ts_data); TEMPLATE(deleteVector,pMatrix)(out); return 0; }
pMatrixVector* processTimeSeriesSet(pMatrixVector *v, const Constants *c) { double area_max = DBL_MIN; double area_min = DBL_MAX; for(size_t i=0; i < v->size; i++) { Matrix *ts = v->array[i]; for(size_t ts_i=0; ts_i < ts->nrow; ts_i++) { for(size_t vi=0; vi < ts->ncol; vi++) { double val = getMatrixElement(ts, ts_i, vi); if(val > area_max) area_max = val; if(val < area_min) area_min = val; } } } double centers[c->M]; for(size_t ni=0; ni<c->M; ni++) { centers[ni] = area_min + (ni+0.5)*(area_max-area_min)/c->M; } pMatrixVector *out = TEMPLATE(createVector,pMatrix)(); for(size_t i=0; i<v->size; i++) { TEMPLATE(insertVector,pMatrix)(out, processThroughReceptiveFields(v->array[i], centers, c)); } return(out); }
=============================================================================*/ /****************************************************************************** Copyright (C) 2010 William Hart Copyright (C) 2013 Mike Hansen ******************************************************************************/ #ifdef T #include "templates.h" void TEMPLATE(T, mat_init) (TEMPLATE(T, mat_t) mat, slong rows, slong cols, const TEMPLATE(T, ctx_t) ctx) { if ((rows) && (cols)) /* Allocate space for r*c small entries */ { slong i, j; mat->entries = flint_malloc(rows * cols * sizeof(TEMPLATE(T, struct))); mat->rows = flint_malloc(rows * sizeof(TEMPLATE(T, struct) *)); /* Initialise rows */ for (i = 0; i < rows; i++) { mat->rows[i] = mat->entries + i * cols; for (j = 0; j < cols; j++) { TEMPLATE(T, init) (mat->rows[i] + j, ctx); }
Copyright (C) 2007 David Howden Copyright (C) 2007, 2008, 2009, 2010 William Hart Copyright (C) 2008 Richard Howell-Peak Copyright (C) 2011 Fredrik Johansson Copyright (C) 2012 Lina Kulakova Copyright (C) 2013 Mike Hansen ******************************************************************************/ #ifdef T #include "templates.h" void TEMPLATE(T, poly_factor_cantor_zassenhaus) (TEMPLATE(T, poly_factor_t) res, const TEMPLATE(T, poly_t) f, const TEMPLATE(T, ctx_t) ctx) { TEMPLATE(T, poly_t) h, v, g, x; fmpz_t q; slong i, j, num; fmpz_init(q); TEMPLATE(T, ctx_order) (q, ctx); TEMPLATE(T, poly_init) (h, ctx); TEMPLATE(T, poly_init) (g, ctx); TEMPLATE(T, poly_init) (v, ctx); TEMPLATE(T, poly_init) (x, ctx);
void RegistrationHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) { response.setChunkedTransferEncoding(true); response.setContentType("text/html"); #line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" SESSION std::ostream& responseStream = response.send(); responseStream << ""; responseStream << "\n"; responseStream << ""; responseStream << "\n"; responseStream << ""; responseStream << "\n"; responseStream << ""; responseStream << "\n"; responseStream << "\n"; responseStream << "\t"; responseStream << "\n"; responseStream << "\n"; responseStream << "\t"; #line 8 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_BEGIN("head") responseStream << ""; // begin include src/view/tile/head.html responseStream << "\n"; responseStream << "\t<meta charset=\"utf-8\">\n"; responseStream << "\t<meta http-equiv=\"X-UA-Compatible\" content=\"IE=9\" />\n"; responseStream << "\t<script type=\"text/javascript\">window.suggestmeyes_loaded = true;</script>\n"; responseStream << "\t<title>Main Page</title>\n"; responseStream << "\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/style.css\">\n"; responseStream << "\t<!--<meta http-equiv=\"refresh\" content=\"1\">-->\n"; responseStream << ""; // end include src/view/tile/head.html responseStream << ""; #line 8 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_END responseStream << "\n"; responseStream << "\t"; #line 9 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_BEGIN("topbar") responseStream << ""; // begin include src/view/tile/topbar.html responseStream << "\n"; responseStream << "\t"; #line 2 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" IF(user) responseStream << "\n"; responseStream << "\t\t<div id=\"session\">\n"; responseStream << "\t\t\t<span class=\"topbar\">\n"; responseStream << "\t\t\t\t<a class=\"topbar\" href=\"/User\"><span class=\"topbar\">\n"; responseStream << "\t\t\t\t\t"; #line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" IF(user.group() == user.ADMIN) responseStream << "#"; #line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" responseStream << (user.username()); responseStream << "#"; #line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" ELSE responseStream << "["; #line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" responseStream << (user.username()); responseStream << "]"; #line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" ENDIF responseStream << "\n"; responseStream << "\t\t\t\t</span></a>\n"; responseStream << "\t\t\t\t<a class=\"topbar\" href=\"/*logout\">Sign out</a>\n"; responseStream << "\t\t\t</span>\n"; responseStream << "\t\t</div>\n"; responseStream << "\t"; #line 11 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" ELSE responseStream << "\n"; responseStream << "\t\t<script type=\"text/javascript\"> function submitSigninForm() { document.forms[\"signinForm\"].submit(); } </script>\n"; responseStream << "\t\t<form id=\"signinForm\" class=\"ignore\" method=\"POST\" action=\"*login\">"; #line 13 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" responseStream << (CSRF); responseStream << "\n"; responseStream << "\t\t\t<div id=\"session\">\n"; responseStream << "\t\t\t\t<span class=\"topbar\">\n"; responseStream << "\t\t\t\t\t<input class=\"topbar\" type=\"text\" "; #line 16 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" responseStream << (NAME(username)); responseStream << " placeholder=\"Username...\" style=\"width: 100px;\" onkeypress=\"if(event.keyCode==13) submitSigninForm();\">\n"; responseStream << "\t\t\t\t\t<input class=\"topbar\" type=\"password\" "; #line 17 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" responseStream << (NAME(password)); responseStream << " placeholder=\"Password...\" style=\"width: 100px;\" onkeypress=\"if(event.keyCode==13) submitSigninForm();\">\n"; responseStream << "\t\t\t\t\t<!--<a class=\"topbar\" href=\"/Login\">Sign In</a>-->\n"; responseStream << "\t\t\t\t\t<a class=\"topbar\" href=\"javascript:submitSigninForm()\">Log in</a>\n"; responseStream << "\t\t\t\t\t<a class=\"topbar\" href=\"/Registration\">Sign up</a>\n"; responseStream << "\t\t\t\t</span>\n"; responseStream << "\t\t\t</div>\n"; responseStream << "\t\t</form>\n"; responseStream << "\t"; #line 24 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/topbar.html" ENDIF responseStream << "\n"; responseStream << ""; // end include src/view/tile/topbar.html responseStream << ""; #line 9 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_END responseStream << "\n"; responseStream << "\t"; #line 10 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_BEGIN("header") responseStream << ""; // begin include src/view/tile/header.html responseStream << "\n"; responseStream << "\t<a id=\"logo\" href=\"/\">\n"; responseStream << "\t\t<img src=\"/images/logo.png\" alt=\"Stack Overflow\" />\n"; responseStream << "\t</a>\n"; responseStream << "\t<script type=\"text/javascript\"> function submitSearchForm() { document.forms[\"searchForm\"].submit(); } </script>\n"; responseStream << "\t<form id=\"searchForm\" class=\"ignore\" method=\"GET\" action=\"*search\">\n"; responseStream << "\t\t<div id=\"search\">\n"; responseStream << "\t\t\t<span class=\"toolbar\">\n"; responseStream << "\t\t\t\t<input class=\"search\" type=\"text\" "; #line 9 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/header.html" responseStream << (NAME(query)); responseStream << " placeholder=\"Search...\" style=\"width: 170px;\" onkeypress=\"if(event.keyCode==13) submitSearchForm();\">\n"; responseStream << "\t\t\t\t<a class=\"toolbar\" href=\"javascript:submitSearchForm()\">Find</a>\n"; responseStream << "\t\t\t</span>\n"; responseStream << "\t\t</div>\n"; responseStream << "\t</form>\t\n"; responseStream << ""; // end include src/view/tile/header.html responseStream << ""; #line 10 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_END responseStream << "\n"; responseStream << "\t"; #line 11 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_BEGIN("menu") responseStream << ""; // begin include src/view/tile/menu.html responseStream << "\n"; responseStream << "\t<ul id=\"menu\">\n"; responseStream << "\t\t"; #line 3 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/menu.html" FOREACH(entry, me.menu()) responseStream << "\n"; responseStream << "\t\t\t<li><a href=\""; #line 4 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/menu.html" responseStream << (entry.url); responseStream << "\" "; #line 4 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/menu.html" responseStream << (me.checkPath(entry.url) ? "class='active'" : ""); responseStream << "><span>"; #line 4 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/menu.html" responseStream << (entry.title); responseStream << "</span></a></li>\n"; responseStream << "\t\t"; #line 5 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/menu.html" ENDFOR responseStream << "\n"; responseStream << "\t</ul>\n"; responseStream << ""; // end include src/view/tile/menu.html responseStream << ""; #line 11 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_END responseStream << "\n"; responseStream << "\n"; responseStream << "\t"; #line 13 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_BEGIN("content") responseStream << "\n"; responseStream << "\t\t"; #line 14 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" IF(me["mode"] == "activated") responseStream << "\n"; responseStream << "\t\t\t<h1>Activation Successful!</h1>\n"; responseStream << "\t\t\tThe account for "; #line 16 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (me.newUser->username()); responseStream << " has been successfully activated!\n"; responseStream << "\t\t"; #line 17 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" ELIF(me["mode"] == "inactive" && me.newUser && me.newUser->group() == me.newUser->INACTIVE) responseStream << "\n"; responseStream << "\t\t\t<h1>Registration Successful!</h1>\n"; responseStream << "\t\t\tThank you for registering! A confirmation email has been sent to "; #line 19 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (me.newUser->email()); responseStream << ". Please click on the Activation Link to Activate your account.\n"; responseStream << "\t\t\t<a href=\"/*resendActivationEmail\">Resend confirmation email?</a>\n"; responseStream << "\t\t"; #line 21 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" ELIF(!user) responseStream << "\n"; responseStream << "\t\t\t<h1>Registration:</h1>\n"; responseStream << "\t\t\t"; #line 23 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (me.captcha.htmlUse()); responseStream << "\n"; responseStream << "\t\t\t<form method=\"POST\" action=\"*signin\" id=\"userForm\">"; #line 24 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (CSRF); responseStream << "\n"; responseStream << "\t\t\t\t<div class=\"userCol1\">Username:</div><div class=\"userCol2\"><input type=\"text\" "; #line 25 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (NAME(username)); responseStream << "></div>\n"; responseStream << "\t\t\t\t<div class=\"userCol1\">Email Address:</div><div class=\"userCol2\"><input type=\"text\" "; #line 26 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (NAME(email)); responseStream << "></div>\n"; responseStream << "\t\t\t\t<div class=\"userCol1\">Password:</div><div class=\"userCol2\"><input type=\"password\" "; #line 27 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (NAME(password)); responseStream << "></div>\n"; responseStream << "\t\t\t\t<div class=\"userCol1\">Confirm Password:</div><div class=\"userCol2\"><input type=\"password\" "; #line 28 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (NAME(password2)); responseStream << "></div>\n"; responseStream << "\t\t\t\t<div class=\"userCol1\">"; #line 29 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (me.captcha.htmlQuestion()); responseStream << "</div><div class=\"userCol2\">"; #line 29 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (me.captcha.htmlAnswer()); responseStream << "</div>\n"; responseStream << "\t\t\t\t<div class=\"userCol1\"></div><div class=\"userCol2\"><input type=\"submit\" value=\"Register\"></div>\n"; responseStream << "\t\t\t\t<div class=\"userStatus\"><span class=\"userError\">"; #line 31 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" responseStream << (me["status"]); responseStream << "</span></div>\n"; responseStream << "\t\t\t</form><!--Forgot your password?-->\n"; responseStream << "\t\t"; #line 33 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" ELSE responseStream << "\n"; responseStream << "\t\t\t<h1>You are already registered.</h1>\n"; responseStream << "\t\t"; #line 35 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" ENDIF responseStream << "\n"; responseStream << "\t"; #line 36 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_END responseStream << "\n"; responseStream << "\n"; responseStream << "\t"; #line 38 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_BEGIN("navigation") responseStream << ""; // begin include src/view/tile/navigation.html responseStream << "\n"; responseStream << "\t<div id=\"toolbar\">\n"; responseStream << "\t</div>\n"; responseStream << "\t<ul id=\"list\">\n"; responseStream << "\t\t"; #line 5 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/navigation.html" FOREACH(entry, me.sidebar()) responseStream << "\n"; responseStream << "\t\t\t<li><a href=\""; #line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/navigation.html" responseStream << (entry.url); responseStream << "\" "; #line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/navigation.html" responseStream << (me.checkPath(entry.url) ? "class='active'" : ""); responseStream << "><span>"; #line 6 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/navigation.html" responseStream << (entry.title); responseStream << "</span></a></li>\n"; responseStream << "\t\t"; #line 7 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/tile/navigation.html" ENDFOR responseStream << "\n"; responseStream << "\t</ul>\n"; responseStream << ""; // end include src/view/tile/navigation.html responseStream << ""; #line 38 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_END responseStream << "\n"; responseStream << "\t"; #line 39 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_BEGIN("footer") responseStream << ""; // begin include src/view/tile/footer.html responseStream << "\t\n"; responseStream << "\t<span>Copyright © 2015 [There could be your company].</span>\n"; responseStream << ""; // end include src/view/tile/footer.html responseStream << ""; #line 39 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TILE_END responseStream << "\n"; responseStream << "\n"; responseStream << "\t"; #line 41 "/media/DATA_1/_/Data/Core/Developing/WebServer/PocoBlog/src/view/Registration.c" TEMPLATE("html/template.html") responseStream << "\n"; responseStream << ""; }
int main(int argc, char** argv) { double s[nalgs]; int c, n, lenf, leng, len, ext, reps = 0; fmpz_t p, temp; TEMPLATE(T, poly_t) f, g, h; TEMPLATE(T, ctx_t) ctx; FLINT_TEST_INIT(state); fmpz_init(p); fmpz_set_str(p, argv[1], 10); fmpz_init(temp); fmpz_set_str(temp, argv[2], 10); ext = fmpz_get_si(temp); lenf = atol(argv[3]); leng = atol(argv[4]); len = atol(argv[5]); TEMPLATE(T, ctx_init)(ctx, p, ext, "a"); TEMPLATE(T, poly_init)(f, ctx); TEMPLATE(T, poly_init)(g, ctx); TEMPLATE(T, poly_init)(h, ctx); for (c = 0; c < nalgs; c++) { s[c] = 0.0; } for (n = 0; n < ncases; n++) { double t[nalgs]; int l, loops = 1; /* Construct random elements of fq */ { TEMPLATE(T, poly_randtest_monic)(f, state, lenf, ctx); TEMPLATE(T, poly_randtest_monic)(g, state, leng, ctx); } loop: t[0] = 0.0; init_clock(0); prof_start(); for (l = 0; l < loops; l++) { TEMPLATE(T, poly_mullow_classical)(h, f, g, len, ctx); } prof_stop(); t[0] += get_clock(0); t[1] = 0.0; init_clock(0); prof_start(); for (l = 0; l < loops; l++) { TEMPLATE(T, poly_mullow_KS)(h, f, g, len, ctx); } prof_stop(); t[1] += get_clock(0); for (c = 0; c < nalgs; c++) if (t[c] * FLINT_CLOCK_SCALE_FACTOR <= cpumin) { loops *= 10; goto loop; } for (c = 0; c < nalgs; c++) s[c] += t[c]; reps += loops; } for (c = 0; c < nalgs; c++) { flint_printf("%20f ", s[c] / (double) reps); fflush(stdout); } printf("\n"); TEMPLATE(T, poly_clear)(h, ctx); TEMPLATE(T, poly_clear)(f, ctx); TEMPLATE(T, poly_clear)(g, ctx); TEMPLATE(T, ctx_clear)(ctx); fmpz_clear(p); fmpz_clear(temp); FLINT_TEST_CLEANUP(state); return 0; }
=============================================================================*/ /****************************************************************************** Copyright (C) 2008, 2009 William Hart Copyright (C) 2012 Andres Goens Copyright (C) 2013 Mike Hansen ******************************************************************************/ #ifdef T #include "templates.h" void TEMPLATE(T, poly_realloc) (TEMPLATE(T, poly_t) poly, slong alloc, const TEMPLATE(T, ctx_t) ctx) { slong i; if (alloc == 0) /* Clear up, reinitialise */ { TEMPLATE(T, poly_clear) (poly, ctx); TEMPLATE(T, poly_init) (poly, ctx); } else if (poly->alloc) /* Realloc */ { for (i = alloc; i < poly->alloc; i++) TEMPLATE(T, clear) (poly->coeffs + i, ctx); poly->coeffs =
int main(void) { slong i; FLINT_TEST_INIT(state); printf("submul...."); fflush(stdout); for (i = 0; i < 2 * flint_test_multiplier(); i++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, mat_t) A, B, C, D, T, E; slong m, k, n; TEMPLATE(T, ctx_randtest) (ctx, state); m = n_randint(state, 50); k = n_randint(state, 50); n = n_randint(state, 50); TEMPLATE(T, mat_init) (A, m, k, ctx); TEMPLATE(T, mat_init) (B, k, n, ctx); TEMPLATE(T, mat_init) (C, m, n, ctx); TEMPLATE(T, mat_init) (D, m, n, ctx); TEMPLATE(T, mat_init) (T, m, n, ctx); TEMPLATE(T, mat_init) (E, m, n, ctx); TEMPLATE(T, mat_randtest) (A, state, ctx); TEMPLATE(T, mat_randtest) (B, state, ctx); TEMPLATE(T, mat_randtest) (C, state, ctx); TEMPLATE(T, mat_submul) (D, C, A, B, ctx); TEMPLATE(T, mat_mul) (T, A, B, ctx); TEMPLATE(T, mat_sub) (E, C, T, ctx); if (!TEMPLATE(T, mat_equal) (D, E, ctx)) { printf("FAIL: results not equal\n"); TEMPLATE(T, mat_print_pretty) (A, ctx); TEMPLATE(T, mat_print_pretty) (B, ctx); TEMPLATE(T, mat_print_pretty) (C, ctx); TEMPLATE(T, mat_print_pretty) (D, ctx); TEMPLATE(T, mat_print_pretty) (E, ctx); abort(); } /* Check aliasing */ TEMPLATE(T, mat_submul) (C, C, A, B, ctx); if (!TEMPLATE(T, mat_equal) (C, E, ctx)) { printf("FAIL: results not equal (aliasing)\n"); TEMPLATE(T, mat_print_pretty) (A, ctx); TEMPLATE(T, mat_print_pretty) (B, ctx); TEMPLATE(T, mat_print_pretty) (C, ctx); TEMPLATE(T, mat_print_pretty) (D, ctx); TEMPLATE(T, mat_print_pretty) (E, ctx); abort(); } TEMPLATE(T, mat_clear) (A, ctx); TEMPLATE(T, mat_clear) (B, ctx); TEMPLATE(T, mat_clear) (C, ctx); TEMPLATE(T, mat_clear) (D, ctx); TEMPLATE(T, mat_clear) (E, ctx); TEMPLATE(T, mat_clear) (T, ctx); TEMPLATE(T, ctx_clear) (ctx); } FLINT_TEST_CLEANUP(state); printf("PASS\n"); return 0; }
int main(void) { slong i; FLINT_TEST_INIT(state); printf("solve_tril_classical...."); fflush(stdout); for (i = 0; i < 5 * flint_test_multiplier(); i++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, mat_t) A, X, B, Y; slong rows, cols; int unit; TEMPLATE(T, ctx_randtest) (ctx, state); rows = n_randint(state, 50); cols = n_randint(state, 50); unit = n_randint(state, 2); TEMPLATE(T, mat_init) (A, rows, rows, ctx); TEMPLATE(T, mat_init) (B, rows, cols, ctx); TEMPLATE(T, mat_init) (X, rows, cols, ctx); TEMPLATE(T, mat_init) (Y, rows, cols, ctx); TEMPLATE(T, mat_randtril) (A, state, unit, ctx); TEMPLATE(T, mat_randtest) (X, state, ctx); TEMPLATE(T, mat_mul) (B, A, X, ctx); /* Check Y = A^(-1) * (A * X) = X */ TEMPLATE(T, mat_solve_tril_classical) (Y, A, B, unit, ctx); if (!TEMPLATE(T, mat_equal) (Y, X, ctx)) { printf("FAIL!\n"); printf("A:\n"); TEMPLATE(T, mat_print_pretty) (A, ctx); printf("X:\n"); TEMPLATE(T, mat_print_pretty) (X, ctx); printf("B:\n"); TEMPLATE(T, mat_print_pretty) (B, ctx); printf("Y:\n"); TEMPLATE(T, mat_print_pretty) (Y, ctx); abort(); } /* Check aliasing */ TEMPLATE(T, mat_solve_tril_classical) (B, A, B, unit, ctx); if (!TEMPLATE(T, mat_equal) (B, X, ctx)) { printf("FAIL!\n"); printf("aliasing test failed"); printf("A:\n"); TEMPLATE(T, mat_print_pretty) (A, ctx); printf("B:\n"); TEMPLATE(T, mat_print_pretty) (B, ctx); abort(); } TEMPLATE(T, mat_clear) (A, ctx); TEMPLATE(T, mat_clear) (B, ctx); TEMPLATE(T, mat_clear) (X, ctx); TEMPLATE(T, mat_clear) (Y, ctx); TEMPLATE(T, ctx_clear) (ctx); } FLINT_TEST_CLEANUP(state); printf("PASS\n"); return 0; }
int main(int argc, char **argv) { ArgOptionsPrep a = parsePrepOptions(argc, argv); Constants *c = createConstants(a.const_filename); bool saveStat = false; if(a.stat_file) { saveStat = true; } pMatrixVector* ts_data = readMatrixListFromFile(a.input_file); pMatrixVector* ts_labels = readMatrixListFromFile(a.input_labels_file); assert(ts_labels->size == 1); assert(ts_labels->array[0]->nrow == ts_data->size); pMatrixVector *out_data = TEMPLATE(createVector,pMatrix)(); assert(ts_data->size > 0); pMatrixVector *ts_data_pr = processTimeSeriesSet(ts_data, c); indVector *ts_indices = TEMPLATE(createVector,ind)(); for(size_t ti=0; ti< ts_data_pr->size; ti++) { TEMPLATE(insertVector,ind)(ts_indices, ti); } srand(time(NULL)); shuffleIndVector(ts_indices); SpikesList *net = createSpikesList(c->M); doubleVector *ts_labels_current = TEMPLATE(createVector,double)(); double t = 0; doubleVector *timeline = TEMPLATE(createVector,double)(); AdExLayer *l = createAdExLayer(c->M, saveStat); for(size_t ts_i=0; ts_i < ts_indices->size; ts_i++) { Matrix *ts = ts_data_pr->array[ ts_indices->array[ts_i] ]; size_t nsamples = ts->ncol; toStartValuesAdExLayer(l, c); size_t j; for(j = 0; j < nsamples; t+= c->preproc->dt, j++) { for(size_t ni=0; ni < l->N; ni++) { double I = getMatrixElement(ts, ni, j); propagateCurrentAdExLayer(l, &ni, &I); simulateAdExLayerNeuron(l, &ni, c); if(l->fired[ni] == 1) { TEMPLATE(insertVector,double)(net->list[ni], c->preproc->mult*t); l->fired[ni] = 0; } } } t += 250/c->preproc->mult; TEMPLATE(insertVector,double)(timeline, c->preproc->mult*t); TEMPLATE(insertVector,double)(ts_labels_current, getMatrixElement(ts_labels->array[0], ts_indices->array[ts_i], 0) ); } Matrix *spikes = vectorArrayToMatrix(net->list, net->size); TEMPLATE(insertVector,pMatrix)(out_data, spikes); Matrix *timeline_m = vectorArrayToMatrix(&timeline, 1); transposeMatrix(timeline_m); TEMPLATE(insertVector,pMatrix)(out_data, timeline_m); Matrix *classes = vectorArrayToMatrix(&ts_labels_current, 1); transposeMatrix(classes); TEMPLATE(insertVector,pMatrix)(out_data, classes); saveMatrixListToFile(a.output_file, out_data); if(l->saveStat) { pMatrixVector *stat_data = TEMPLATE(createVector,pMatrix)(); for(size_t i=0; i<ts_data_pr->size; i++) { TEMPLATE(insertVector,pMatrix)(stat_data, copyMatrix(ts_data_pr->array[i])); } Matrix *Vs = vectorArrayToMatrix(l->stat_V, l->N); TEMPLATE(insertVector,pMatrix)(stat_data, Vs); Matrix *ws = vectorArrayToMatrix(l->stat_w, l->N); TEMPLATE(insertVector,pMatrix)(stat_data, ws); saveMatrixListToFile(a.stat_file, stat_data); TEMPLATE(deleteVector,pMatrix)(stat_data); } TEMPLATE(deleteVector,double)(timeline); deleteAdExLayer(l); deleteSpikesList(net); deleteConstants(c); TEMPLATE(deleteVector,pMatrix)(out_data); TEMPLATE(deleteVector,pMatrix)(ts_data_pr); TEMPLATE(deleteVector,pMatrix)(ts_data); return(0); }
int main(void) { int i, result; FLINT_TEST_INIT(state); flint_printf("mullow_classical... "); fflush(stdout); /* Compare with truncated product of a and b */ for (i = 0; i < 2000; i++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, poly_t) a, b, c, d; slong n; TEMPLATE(T, ctx_randtest) (ctx, state); TEMPLATE(T, poly_init) (a, ctx); TEMPLATE(T, poly_init) (b, ctx); TEMPLATE(T, poly_init) (c, ctx); TEMPLATE(T, poly_init) (d, ctx); TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 50), ctx); TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 50), ctx); n = n_randint(state, 50); TEMPLATE(T, poly_mullow_classical) (c, a, b, n, ctx); TEMPLATE(T, poly_mul) (d, a, b, ctx); TEMPLATE(T, poly_truncate) (d, n, ctx); result = (TEMPLATE(T, poly_equal) (c, d, ctx)); if (!result) { flint_printf("FAIL:\n\n"); flint_printf("a = "), TEMPLATE(T, poly_print_pretty) (a, "X", ctx), flint_printf("\n"); flint_printf("b = "), TEMPLATE(T, poly_print_pretty) (b, "X", ctx), flint_printf("\n"); flint_printf("c = "), TEMPLATE(T, poly_print_pretty) (c, "X", ctx), flint_printf("\n"); flint_printf("d = "), TEMPLATE(T, poly_print_pretty) (d, "X", ctx), flint_printf("\n"); abort(); } TEMPLATE(T, poly_clear) (a, ctx); TEMPLATE(T, poly_clear) (b, ctx); TEMPLATE(T, poly_clear) (c, ctx); TEMPLATE(T, poly_clear) (d, ctx); TEMPLATE(T, ctx_clear) (ctx); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return EXIT_SUCCESS; }
int main(void) { int i; FLINT_TEST_INIT(state); flint_printf("compose_mod...."); fflush(stdout); for (i = 0; i < 20 * flint_test_multiplier(); i++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, poly_t) a, b, c, d, e; TEMPLATE(T, ctx_randtest) (ctx, state); TEMPLATE(T, poly_init) (a, ctx); TEMPLATE(T, poly_init) (b, ctx); TEMPLATE(T, poly_init) (c, ctx); TEMPLATE(T, poly_init) (d, ctx); TEMPLATE(T, poly_init) (e, ctx); TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_randtest_not_zero) (c, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_compose_mod) (d, a, b, c, ctx); TEMPLATE(T, poly_compose) (e, a, b, ctx); TEMPLATE(T, poly_rem) (e, e, c, ctx); if (!TEMPLATE(T, poly_equal) (d, e, ctx)) { flint_printf("FAIL (composition):\n"); flint_printf("a:\n"); TEMPLATE(T, poly_print) (a, ctx); flint_printf("\n"); flint_printf("b:\n"); TEMPLATE(T, poly_print) (b, ctx); flint_printf("\n"); flint_printf("c:\n"); TEMPLATE(T, poly_print) (c, ctx); flint_printf("\n"); flint_printf("d:\n"); TEMPLATE(T, poly_print) (d, ctx); flint_printf("\n"); flint_printf("e:\n"); TEMPLATE(T, poly_print) (e, ctx); flint_printf("\n"); abort(); } TEMPLATE(T, poly_clear) (a, ctx); TEMPLATE(T, poly_clear) (b, ctx); TEMPLATE(T, poly_clear) (c, ctx); TEMPLATE(T, poly_clear) (d, ctx); TEMPLATE(T, poly_clear) (e, ctx); TEMPLATE(T, ctx_clear) (ctx); } /* Test aliasing of res and a */ for (i = 0; i < 20 * flint_test_multiplier(); i++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, poly_t) a, b, c, d; TEMPLATE(T, ctx_randtest) (ctx, state); TEMPLATE(T, poly_init) (a, ctx); TEMPLATE(T, poly_init) (b, ctx); TEMPLATE(T, poly_init) (c, ctx); TEMPLATE(T, poly_init) (d, ctx); TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_randtest_not_zero) (c, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_compose_mod) (d, a, b, c, ctx); TEMPLATE(T, poly_compose_mod) (a, a, b, c, ctx); if (!TEMPLATE(T, poly_equal) (d, a, ctx)) { flint_printf("FAIL (aliasing a):\n"); flint_printf("a:\n"); TEMPLATE(T, poly_print) (a, ctx); flint_printf("\n"); flint_printf("b:\n"); TEMPLATE(T, poly_print) (b, ctx); flint_printf("\n"); flint_printf("c:\n"); TEMPLATE(T, poly_print) (c, ctx); flint_printf("\n"); flint_printf("d:\n"); TEMPLATE(T, poly_print) (d, ctx); flint_printf("\n"); abort(); } TEMPLATE(T, poly_clear) (a, ctx); TEMPLATE(T, poly_clear) (b, ctx); TEMPLATE(T, poly_clear) (c, ctx); TEMPLATE(T, poly_clear) (d, ctx); TEMPLATE(T, ctx_clear) (ctx); } /* Test aliasing of res and b */ for (i = 0; i < 20 * flint_test_multiplier(); i++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, poly_t) a, b, c, d; TEMPLATE(T, ctx_randtest) (ctx, state); TEMPLATE(T, poly_init) (a, ctx); TEMPLATE(T, poly_init) (b, ctx); TEMPLATE(T, poly_init) (c, ctx); TEMPLATE(T, poly_init) (d, ctx); TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_randtest_not_zero) (c, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_compose_mod) (d, a, b, c, ctx); TEMPLATE(T, poly_compose_mod) (b, a, b, c, ctx); if (!TEMPLATE(T, poly_equal) (d, b, ctx)) { flint_printf("FAIL (aliasing b)\n"); flint_printf("a:\n"); TEMPLATE(T, poly_print) (a, ctx); flint_printf("\n"); flint_printf("b:\n"); TEMPLATE(T, poly_print) (b, ctx); flint_printf("\n"); flint_printf("c:\n"); TEMPLATE(T, poly_print) (c, ctx); flint_printf("\n"); flint_printf("d:\n"); TEMPLATE(T, poly_print) (d, ctx); flint_printf("\n"); abort(); } TEMPLATE(T, poly_clear) (a, ctx); TEMPLATE(T, poly_clear) (b, ctx); TEMPLATE(T, poly_clear) (c, ctx); TEMPLATE(T, poly_clear) (d, ctx); TEMPLATE(T, ctx_clear) (ctx); } /* Test aliasing of res and c */ for (i = 0; i < 20 * flint_test_multiplier(); i++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, poly_t) a, b, c, d; TEMPLATE(T, ctx_randtest) (ctx, state); TEMPLATE(T, poly_init) (a, ctx); TEMPLATE(T, poly_init) (b, ctx); TEMPLATE(T, poly_init) (c, ctx); TEMPLATE(T, poly_init) (d, ctx); TEMPLATE(T, poly_randtest) (a, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_randtest) (b, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_randtest_not_zero) (c, state, n_randint(state, 20) + 1, ctx); TEMPLATE(T, poly_compose_mod) (d, a, b, c, ctx); TEMPLATE(T, poly_compose_mod) (c, a, b, c, ctx); if (!TEMPLATE(T, poly_equal) (d, c, ctx)) { flint_printf("FAIL (aliasing c)\n"); flint_printf("a:\n"); TEMPLATE(T, poly_print) (a, ctx); flint_printf("\n"); flint_printf("b:\n"); TEMPLATE(T, poly_print) (b, ctx); flint_printf("\n"); flint_printf("c:\n"); TEMPLATE(T, poly_print) (c, ctx); flint_printf("\n"); flint_printf("d:\n"); TEMPLATE(T, poly_print) (d, ctx); flint_printf("\n"); abort(); } TEMPLATE(T, poly_clear) (a, ctx); TEMPLATE(T, poly_clear) (b, ctx); TEMPLATE(T, poly_clear) (c, ctx); TEMPLATE(T, poly_clear) (d, ctx); TEMPLATE(T, ctx_clear) (ctx); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
int main(int argc, char **argv) { FILE *infile, *strfile, *reconfile; long input_file_size; yuv_frame_t orig,ref[MAX_REF_FRAMES]; yuv_frame_t rec[MAX_REORDER_BUFFER+1]; // Last one is for temp use int rec_available[MAX_REORDER_BUFFER] = {0}; int last_frame_output=-1; int num_encoded_frames,num_bits,start_bits,end_bits; int sub_gop=1; int rec_buffer_idx; int k,frame_num,frame_num0,r; int frame_offset; int ysize,csize; long frame_size; int width,height; int min_interp_depth; int last_intra_frame_num = 0; uint32_t acc_num_bits; snrvals psnr; snrvals accsnr; double bit_rate_in_kbps; enc_params *params; encoder_info_t encoder_info; int y4m_output; // Keep track of last P frame for using the right references for the tail of a sequence in re-ordered modes int last_PorI_frame; init_use_simd(); /* Read commands from command line and from configuration file(s) */ if (argc < 3) { fprintf(stdout,"usage: %s <parameters>\n",argv[0]); fatalerror(""); } params = parse_config_params(argc, argv); if (params == NULL) { fatalerror("Error while reading encoder paramaters."); } check_parameters(params); /* Open files */ if (!(infile = fopen(params->infilestr,"rb"))) { fatalerror("Could not open in-file for reading."); } if (!(strfile = fopen(params->outfilestr,"wb"))) { fatalerror("Could not open out-file for writing."); } reconfile = NULL; y4m_output = 0; if (params->reconfilestr) { char *p; if (!(reconfile = fopen(params->reconfilestr,"wb"))) { fatalerror("Could not open recon-file for reading."); } p = strrchr(params->reconfilestr,'.'); y4m_output = p != NULL && strcmp(p,".y4m") == 0; } fseek(infile, 0, SEEK_END); input_file_size = ftell(infile); fseek(infile, 0, SEEK_SET); if (y4m_output) { fprintf(reconfile, "YUV4MPEG2 W%d H%d F%d:1 Ip A%d:%d C%d", params->width, params->height, (int)params->frame_rate, params->aspectnum, params->aspectden, params->subsample); if (params->input_bitdepth > 8) fprintf(reconfile, "p%d XYSCSS=%dp%d", params->input_bitdepth, params->subsample, params->input_bitdepth); fprintf(reconfile, "\x0a"); } accsnr.y = 0; accsnr.u = 0; accsnr.v = 0; acc_num_bits = 0; height = params->height; width = params->width; ysize = height * width; csize = ysize >> 2*(params->subsample == 420); frame_size = (ysize + 2*csize) * (1 + (params->input_bitdepth > 8)); encoder_info.params = params; /* Create frames*/ TEMPLATE(create_yuv_frame)(&orig,width,height,params->subsample == 420,0,0,params->bitdepth,params->input_bitdepth); for (r=0;r<MAX_REORDER_BUFFER+1;r++){ TEMPLATE(create_yuv_frame)(&rec[r],width,height,params->subsample == 420,0,0,params->bitdepth,params->input_bitdepth); } for (r=0;r<MAX_REF_FRAMES;r++){ //TODO: Use Long-term frame instead of a large sliding window TEMPLATE(create_yuv_frame)(&ref[r],width,height,params->subsample == 420,PADDING_Y,PADDING_Y,params->bitdepth,params->input_bitdepth); } if (params->interp_ref) { for (r=0;r<MAX_SKIP_FRAMES;r++){ encoder_info.interp_frames[r] = malloc(sizeof(yuv_frame_t)); TEMPLATE(create_yuv_frame)(encoder_info.interp_frames[r],width,height,params->subsample == 420,PADDING_Y,PADDING_Y,params->bitdepth,params->input_bitdepth); } } /* Initialize main bit stream */ stream_t stream; stream.bitstream = (uint8_t *)malloc(MAX_BUFFER_SIZE * sizeof(uint8_t)); stream.bitbuf = 0; stream.bitrest = 32; stream.bytepos = 0; stream.bytesize = MAX_BUFFER_SIZE; /* Configure encoder */ encoder_info.orig = &orig; for (r=0;r<MAX_REF_FRAMES;r++){ encoder_info.ref[r] = &ref[r]; } encoder_info.stream = &stream; encoder_info.width = width; encoder_info.height = height; encoder_info.frame_info.max_clpf_strength = encoder_info.params->max_clpf_strength; encoder_info.deblock_data = (deblock_data_t *)malloc((height/MIN_PB_SIZE) * (width/MIN_PB_SIZE) * sizeof(deblock_data_t)); alloc_wmatrices(encoder_info.wmatrix, 0); alloc_wmatrices(encoder_info.iwmatrix, 1); /* Write sequence header */ //TODO: Separate function for sequence header start_bits = get_bit_pos(&stream); write_sequence_header(&stream, params); end_bits = get_bit_pos(&stream); num_bits = end_bits-start_bits; acc_num_bits += num_bits; printf("SH: %4d bits\n",num_bits); /* Start encoding sequence */ num_encoded_frames = 0; sub_gop = max(1,params->num_reorder_pics+1); min_interp_depth = log2i(params->num_reorder_pics+1)-3; if (params->frame_rate > 30) min_interp_depth--; last_PorI_frame = -1; rate_control_t rc; encoder_info.rc = &rc; if (params->bitrate > 0) { int target_bits = (int)(params->bitrate / params->frame_rate); int sb_size = 1 << params->log2_sb_size; int num_sb = ((width + sb_size - 1) / sb_size) * ((height + sb_size - 1) / sb_size); init_rate_control_per_sequence(&rc, target_bits, num_sb); } for (frame_num0 = params->skip; frame_num0 < (params->skip + params->num_frames) && (frame_num0+1)*frame_size <= input_file_size; frame_num0+=sub_gop) { for (k=0; k<sub_gop; k++) { int r,r1,r2,r3; /* Initialize frame info */ frame_offset = reorder_frame_offset(k,sub_gop,params->dyadic_coding); frame_num = frame_num0 + frame_offset; // If there is an initial I frame and reordering need to jump to the next P frame if (frame_num<params->skip) continue; encoder_info.frame_info.frame_num = frame_num - params->skip; rec_buffer_idx = encoder_info.frame_info.frame_num%MAX_REORDER_BUFFER; encoder_info.rec = &rec[rec_buffer_idx]; encoder_info.tmp = &rec[MAX_REORDER_BUFFER]; encoder_info.rec->frame_num = encoder_info.frame_info.frame_num; if (params->num_reorder_pics==0) { if (params->intra_period > 0) encoder_info.frame_info.frame_type = ((num_encoded_frames%params->intra_period) == 0 ? I_FRAME : P_FRAME); else encoder_info.frame_info.frame_type = (num_encoded_frames == 0 ? I_FRAME : P_FRAME); } else { if (params->intra_period > 0) encoder_info.frame_info.frame_type = ((encoder_info.frame_info.frame_num%params->intra_period) == 0 ? I_FRAME : ((encoder_info.frame_info.frame_num%sub_gop)==0 ? P_FRAME : B_FRAME)); else encoder_info.frame_info.frame_type = (encoder_info.frame_info.frame_num == 0 ? I_FRAME : ((encoder_info.frame_info.frame_num%sub_gop)==0 ? P_FRAME : B_FRAME)); } int coded_phase = (num_encoded_frames + sub_gop - 2) % sub_gop + 1; int b_level = log2i(coded_phase); encoder_info.frame_info.b_level = b_level; encoder_info.frame_info.phase = encoder_info.frame_info.frame_num % (encoder_info.params->num_reorder_pics + 1); if (encoder_info.frame_info.frame_type == I_FRAME){ encoder_info.frame_info.qp = params->qp + params->dqpI; last_intra_frame_num = encoder_info.frame_info.frame_num; } else if (params->num_reorder_pics==0) { if (num_encoded_frames % params->HQperiod) encoder_info.frame_info.qp = (int)(params->mqpP*(float)params->qp) + params->dqpP; else encoder_info.frame_info.qp = params->qp; } else { if (encoder_info.frame_info.frame_num % sub_gop) { if (params->dyadic_coding){ if (b_level == 0) encoder_info.frame_info.qp = (int)(params->mqpB0*(float)params->qp) + params->dqpB0; else if (b_level == 1) encoder_info.frame_info.qp = (int)(params->mqpB1*(float)params->qp) + params->dqpB1; else if (b_level == 2) encoder_info.frame_info.qp = (int)(params->mqpB2*(float)params->qp) + params->dqpB2; else if (b_level == 3) encoder_info.frame_info.qp = (int)(params->mqpB3*(float)params->qp) + params->dqpB3; else encoder_info.frame_info.qp = (int)(params->mqpB*(float)params->qp) + params->dqpB; } else { encoder_info.frame_info.qp = (int)(params->mqpB*(float)params->qp) + params->dqpB; } } else { if (encoder_info.frame_info.frame_num % params->HQperiod) { encoder_info.frame_info.qp = (int)(params->mqpP*(float)params->qp) + params->dqpP; } else encoder_info.frame_info.qp = params->qp; } } encoder_info.frame_info.qp = clip(encoder_info.frame_info.qp, 0, MAX_QP); encoder_info.frame_info.num_ref = encoder_info.frame_info.frame_type == I_FRAME ? 0 : min(num_encoded_frames,params->max_num_ref); encoder_info.frame_info.interp_ref = 0; if (encoder_info.frame_info.num_ref > 0) { if (params->num_reorder_pics > 0) { if (params->dyadic_coding) { /* if we have a P frame then use the previous P frame as a reference */ if ((num_encoded_frames-1) % sub_gop == 0) { if (num_encoded_frames==1) encoder_info.frame_info.ref_array[0] = 0; else encoder_info.frame_info.ref_array[0] = sub_gop-1; if (encoder_info.frame_info.num_ref>1 ) encoder_info.frame_info.ref_array[1] = min(MAX_REF_FRAMES-1,min(num_encoded_frames-1,2*sub_gop-1)); for (r=2;r<encoder_info.frame_info.num_ref;r++){ encoder_info.frame_info.ref_array[r] = r-2; } } else if (encoder_info.frame_info.num_ref>0){ int display_phase = (encoder_info.frame_info.frame_num-1) % sub_gop; int ref_offset=sub_gop>>(b_level+1); if (b_level >= min_interp_depth && params->interp_ref == 1) { // Need to add another reference if we are at the beginning if (encoder_info.frame_info.num_ref==2) encoder_info.frame_info.num_ref++; encoder_info.frame_info.interp_ref = params->interp_ref; encoder_info.frame_info.ref_array[1]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase-ref_offset+1]-1); encoder_info.frame_info.ref_array[2]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase+ref_offset+1]-1); // Interpolate these two reference frames to make a new frame encoder_info.frame_info.ref_array[0]=-1; // Add this interpolated frame to the reference buffer and use it as the first reference yuv_frame_t* ref1=encoder_info.ref[encoder_info.frame_info.ref_array[1]]; yuv_frame_t* ref2=encoder_info.ref[encoder_info.frame_info.ref_array[2]]; TEMPLATE(interpolate_frames)(encoder_info.interp_frames[0], ref1, ref2, 2, 1); TEMPLATE(pad_yuv_frame)(encoder_info.interp_frames[0]); encoder_info.interp_frames[0]->frame_num = encoder_info.frame_info.frame_num; /* use most recent frames for the last ref(s)*/ for (r=3;r<encoder_info.frame_info.num_ref;r++){ encoder_info.frame_info.ref_array[r] = r-3; } } else { encoder_info.frame_info.ref_array[0]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase-ref_offset+1]-1); encoder_info.frame_info.ref_array[1]=min(num_encoded_frames-1,coded_phase-dyadic_reorder_display_to_code[log2i(sub_gop)][display_phase+ref_offset+1]-1); /* use most recent frames for the last ref(s)*/ for (r=2;r<encoder_info.frame_info.num_ref;r++){ encoder_info.frame_info.ref_array[r] = r-2; } } } } else { /* if we have a P frame then use the previous P frame as a reference */ if ((num_encoded_frames-1) % sub_gop == 0) { if (num_encoded_frames==1) encoder_info.frame_info.ref_array[0] = 0; else encoder_info.frame_info.ref_array[0] = sub_gop-1; if (encoder_info.frame_info.num_ref>1 ) encoder_info.frame_info.ref_array[1] = min(MAX_REF_FRAMES-1,min(num_encoded_frames-1,2*sub_gop-1)); for (r=2;r<encoder_info.frame_info.num_ref;r++){ encoder_info.frame_info.ref_array[r] = r-1; } } else { if (params->interp_ref > 0 && params->interp_ref == 1) { // Need to add another reference if we are at the beginning if (encoder_info.frame_info.num_ref==2) encoder_info.frame_info.num_ref++; encoder_info.frame_info.interp_ref = params->interp_ref; // Use the last encoded frame as the first true ref if (encoder_info.frame_info.num_ref>0) { encoder_info.frame_info.ref_array[1] = 0; } /* Use the subsequent P frame as the 2nd ref */ int phase = (num_encoded_frames + sub_gop - 2) % sub_gop; if (encoder_info.frame_info.num_ref>1) { if (phase==0) encoder_info.frame_info.ref_array[2] = min(sub_gop, num_encoded_frames-1); else encoder_info.frame_info.ref_array[2] = min(phase, num_encoded_frames-1); } // Interpolate these two reference frames to make a new frame encoder_info.frame_info.ref_array[0]=-1; // Add this interpolated frame to the reference buffer and use it as the first reference yuv_frame_t* ref1=encoder_info.ref[encoder_info.frame_info.ref_array[1]]; yuv_frame_t* ref2=encoder_info.ref[encoder_info.frame_info.ref_array[2]]; TEMPLATE(interpolate_frames)(encoder_info.interp_frames[0], ref1, ref2, sub_gop-phase,phase!=0 ? 1 : sub_gop-phase-1); TEMPLATE(pad_yuv_frame)(encoder_info.interp_frames[0]); encoder_info.interp_frames[0]->frame_num = encoder_info.frame_info.frame_num; /* Use the prior P frame as the 4th ref */ if (encoder_info.frame_info.num_ref>2) { encoder_info.frame_info.ref_array[3] = min(phase ? phase + sub_gop : 2*sub_gop, num_encoded_frames-1); } /* use most recent frames for the last ref(s)*/ for (r=4;r<encoder_info.frame_info.num_ref;r++){ encoder_info.frame_info.ref_array[r] = r-4+1; } } else { // Use the last encoded frame as the first ref if (encoder_info.frame_info.num_ref>0) { encoder_info.frame_info.ref_array[0] = 0; } /* Use the subsequent P frame as the 2nd ref */ int phase = (num_encoded_frames + sub_gop - 2) % sub_gop; if (encoder_info.frame_info.num_ref>1) { if (phase==0) encoder_info.frame_info.ref_array[1] = min(sub_gop, num_encoded_frames-1); else encoder_info.frame_info.ref_array[1] = min(phase, num_encoded_frames-1); } /* Use the prior P frame as the 3rd ref */ if (encoder_info.frame_info.num_ref>2) { encoder_info.frame_info.ref_array[2] = min(phase ? phase + sub_gop : 2*sub_gop, num_encoded_frames-1); } /* use most recent frames for the last ref(s)*/ for (r=3;r<encoder_info.frame_info.num_ref;r++){ encoder_info.frame_info.ref_array[r] = r-3+1; } } } } if (encoder_info.params->num_reorder_pics == 2 && encoder_info.frame_info.frame_type == B_FRAME && b_level == 0) { int off = encoder_info.params->interp_ref == 1 ? 1 : 0; int tmp = encoder_info.frame_info.ref_array[0 + off]; encoder_info.frame_info.ref_array[0 + off] = encoder_info.frame_info.ref_array[1 + off]; encoder_info.frame_info.ref_array[1 + off] = tmp; } } else { if (encoder_info.frame_info.num_ref>=1){ /* If num_ref==1 always use most recent frame */ encoder_info.frame_info.ref_array[0] = last_PorI_frame; } if (encoder_info.frame_info.num_ref==2){ /* If num_ref==2 use most recent LQ frame and most recent HQ frame */ r1 = ((num_encoded_frames + params->HQperiod - 2) % params->HQperiod) + 1; encoder_info.frame_info.ref_array[1] = r1; } else if (encoder_info.frame_info.num_ref==3){ r1 = ((num_encoded_frames + params->HQperiod - 2) % params->HQperiod) + 1; r2 = r1==1 ? 2 : 1; encoder_info.frame_info.ref_array[1] = r1; encoder_info.frame_info.ref_array[2] = r2; } else if (encoder_info.frame_info.num_ref==4){ r1 = ((num_encoded_frames + params->HQperiod - 2) % params->HQperiod) + 1; r2 = r1==1 ? 2 : 1; r3 = r2+1; if (r3==r1) r3 += 1; encoder_info.frame_info.ref_array[1] = r1; encoder_info.frame_info.ref_array[2] = r2; encoder_info.frame_info.ref_array[3] = r3; } else{ for (r=1;r<encoder_info.frame_info.num_ref;r++){ encoder_info.frame_info.ref_array[r] = r; } } } }
void deleteSparseMatrix(SparseMatrix *sm) { TEMPLATE(deleteVector,ind)(sm->row_ind); TEMPLATE(deleteVector,ind)(sm->col_ptr); TEMPLATE(deleteVector,double)(sm->values); }
static void TEMPLATE (simplicial_solver) ( int sys, /* system to solve */ cholmod_factor *L, /* factor to use, a simplicial LL' or LDL' */ cholmod_dense *Y, /* right-hand-side on input, solution on output */ Int *Yseti, Int ysetlen ) { if (L->is_ll) { /* The factorization is LL' */ if (sys == CHOLMOD_A || sys == CHOLMOD_LDLt) { /* Solve Ax=b or LL'x=b */ TEMPLATE (ll_lsolve_k) (L, Y, Yseti, ysetlen) ; TEMPLATE (ll_ltsolve_k) (L, Y, Yseti, ysetlen) ; } else if (sys == CHOLMOD_L || sys == CHOLMOD_LD) { /* Solve Lx=b */ TEMPLATE (ll_lsolve_k) (L, Y, Yseti, ysetlen) ; } else if (sys == CHOLMOD_Lt || sys == CHOLMOD_DLt) { /* Solve L'x=b */ TEMPLATE (ll_ltsolve_k) (L, Y, Yseti, ysetlen) ; } } else { /* The factorization is LDL' */ if (sys == CHOLMOD_A || sys == CHOLMOD_LDLt) { /* Solve Ax=b or LDL'x=b */ TEMPLATE (ldl_lsolve_k) (L, Y, Yseti, ysetlen) ; TEMPLATE (ldl_dltsolve_k) (L, Y, Yseti, ysetlen) ; } else if (sys == CHOLMOD_LD) { /* Solve LDx=b */ TEMPLATE (ldl_ldsolve_k) (L, Y, Yseti, ysetlen) ; } else if (sys == CHOLMOD_L) { /* Solve Lx=b */ TEMPLATE (ldl_lsolve_k) (L, Y, Yseti, ysetlen) ; } else if (sys == CHOLMOD_Lt) { /* Solve L'x=b */ TEMPLATE (ldl_ltsolve_k) (L, Y, Yseti, ysetlen) ; } else if (sys == CHOLMOD_DLt) { /* Solve DL'x=b */ TEMPLATE (ldl_dltsolve_k) (L, Y, Yseti, ysetlen) ; } else if (sys == CHOLMOD_D) { /* Solve Dx=b */ TEMPLATE (ldl_dsolve) (L, Y, Yseti, ysetlen) ; } } }
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =============================================================================*/ /****************************************************************************** Copyright (C) 2013 Mike Hansen ******************************************************************************/ #ifdef T #include "templates.h" void TEMPLATE(T, poly_iterated_frobenius_preinv) (TEMPLATE(T, poly_t) * rop, slong n, const TEMPLATE(T, poly_t) v, const TEMPLATE(T, poly_t) vinv, const TEMPLATE(T, ctx_t) ctx) { slong i; fmpz_t q; TEMPLATE(T, mat_t) HH; fmpz_init(q); TEMPLATE(T, ctx_order) (q, ctx); TEMPLATE(T, poly_gen) (rop[0], ctx); if (TEMPLATE(CAP_T, POLY_ITERATED_FROBENIUS_CUTOFF) (ctx, v->length))
=============================================================================*/ /****************************************************************************** Copyright (C) 2011 Fredrik Johansson Copyright (C) 2013 Mike Hansen ******************************************************************************/ #ifdef T #include "templates.h" void TEMPLATE(T, mat_sub) (TEMPLATE(T, mat_t) res, const TEMPLATE(T, mat_t) mat1, const TEMPLATE(T, mat_t) mat2, const TEMPLATE(T, ctx_t) ctx) { slong i; if (res->c < 1) return; for (i = 0; i < res->r; i++) _TEMPLATE(T, vec_sub) (res->rows[i], mat1->rows[i], mat2->rows[i], res->c, ctx); }
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA =============================================================================*/ /****************************************************************************** Copyright (C) 2013 Mike Hansen ******************************************************************************/ #ifdef T #include "templates.h" void _TEMPLATE(T, vec_dot) (TEMPLATE(T, t) res, const TEMPLATE(T, struct) * vec1, const TEMPLATE(T, struct) * vec2, slong len2, const TEMPLATE(T, ctx_t) ctx) { slong i; TEMPLATE(T, t) x; TEMPLATE(T, init) (x, ctx); TEMPLATE(T, zero) (res, ctx); for (i = 0; i < len2; i++) { TEMPLATE(T, mul) (x, vec1 + i, vec2 + i, ctx); TEMPLATE(T, add) (res, res, x, ctx); }
int main(void) { int iter; FLINT_TEST_INIT(state); flint_printf("factor_distinct_deg...."); fflush(stdout); for (iter = 0; iter < 200; iter++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, poly_t) poly1, poly, q, r, product; TEMPLATE(T, poly_factor_t) res; slong i, length, num; slong *degs; TEMPLATE(T, ctx_randtest) (ctx, state); TEMPLATE(T, poly_init) (poly1, ctx); TEMPLATE(T, poly_init) (poly, ctx); TEMPLATE(T, poly_init) (q, ctx); TEMPLATE(T, poly_init) (r, ctx); TEMPLATE(T, poly_zero) (poly1, ctx); TEMPLATE(T, poly_one) (poly1, ctx); length = n_randint(state, 7) + 2; do { TEMPLATE(T, poly_randtest) (poly, state, length, ctx); if (poly->length) TEMPLATE(T, poly_make_monic) (poly, poly, ctx); } while ((poly->length < 2) || (!TEMPLATE(T, poly_is_irreducible) (poly, ctx))); TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx); num = n_randint(state, 5) + 1; for (i = 1; i < num; i++) { do { length = n_randint(state, 7) + 2; TEMPLATE(T, poly_randtest) (poly, state, length, ctx); if (poly->length) { TEMPLATE(T, poly_make_monic) (poly, poly, ctx); TEMPLATE(T, poly_divrem) (q, r, poly1, poly, ctx); } } while ((poly->length < 2) || (!TEMPLATE(T, poly_is_irreducible) (poly, ctx)) || (r->length == 0)); TEMPLATE(T, poly_mul) (poly1, poly1, poly, ctx); } if (!(degs = flint_malloc((poly1->length - 1) * sizeof(slong)))) { flint_printf("Fatal error: not enough memory."); abort(); } TEMPLATE(T, poly_factor_init) (res, ctx); TEMPLATE(T, poly_factor_distinct_deg) (res, poly1, °s, ctx); TEMPLATE(T, poly_init) (product, ctx); TEMPLATE(T, poly_one) (product, ctx); for (i = 0; i < res->num; i++) TEMPLATE(T, poly_mul) (product, product, res->poly + i, ctx); TEMPLATE(T, TEMPLATE(poly_scalar_mul, T)) (product, product, poly1->coeffs + (poly1->length - 1), ctx); if (!TEMPLATE(T, poly_equal) (poly1, product, ctx)) { flint_printf ("Error: product of factors does not equal to the original polynomial\n"); flint_printf("poly:\n"); TEMPLATE(T, poly_print) (poly1, ctx); flint_printf("\n"); flint_printf("product:\n"); TEMPLATE(T, poly_print) (product, ctx); flint_printf("\n"); abort(); } flint_free(degs); TEMPLATE(T, poly_clear) (product, ctx); TEMPLATE(T, poly_clear) (q, ctx); TEMPLATE(T, poly_clear) (r, ctx); TEMPLATE(T, poly_clear) (poly1, ctx); TEMPLATE(T, poly_clear) (poly, ctx); TEMPLATE(T, poly_factor_clear) (res, ctx); TEMPLATE(T, ctx_clear) (ctx); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return 0; }
=============================================================================*/ /****************************************************************************** Copyright (C) 2010,2011 Fredrik Johansson Copyright (C) 2013 Mike Hansen ******************************************************************************/ #ifdef T #include "templates.h" void TEMPLATE(T, mat_solve_triu) (TEMPLATE(T, mat_t) X, const TEMPLATE(T, mat_t) U, const TEMPLATE(T, mat_t) B, int unit, const TEMPLATE(T, ctx_t) ctx) { if (B->r < TEMPLATE(CAP_T, MAT_SOLVE_TRI_ROWS_CUTOFF) || B->c < TEMPLATE(CAP_T, MAT_SOLVE_TRI_COLS_CUTOFF)) { TEMPLATE(T, mat_solve_triu_classical) (X, U, B, unit, ctx); } else { TEMPLATE(T, mat_solve_triu_recursive) (X, U, B, unit, ctx); } }
Copyright (C) 2012 Lina Kulakova Copyright (C) 2013 Martin Lee Copyright (C) 2013 Mike Hansen ******************************************************************************/ #ifdef T #include "templates.h" #include <math.h> void TEMPLATE(T, poly_factor_distinct_deg) (TEMPLATE(T, poly_factor_t) res, const TEMPLATE(T, poly_t) poly, slong * const *degs, const TEMPLATE(T, ctx_t) ctx) { TEMPLATE(T, poly_t) f, g, s, reducedH0, v, vinv, tmp; TEMPLATE(T, poly_t) * h, *H, *I; fmpz_t q; slong i, j, l, m, n, index, d; double beta; TEMPLATE(T, mat_t) HH, HHH; TEMPLATE(T, poly_init) (v, ctx); TEMPLATE(T, poly_make_monic) (v, poly, ctx); n = TEMPLATE(T, poly_degree) (poly, ctx);
int main(void) { int i, result; FLINT_TEST_INIT(state); flint_printf("inv... "); fflush(stdout); /* Check aliasing: a = ~a */ for (i = 0; i < 2000; i++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, t) a, b, c; TEMPLATE(T, ctx_randtest)(ctx, state); TEMPLATE(T, init)(a, ctx); TEMPLATE(T, init)(b, ctx); TEMPLATE(T, init)(c, ctx); TEMPLATE(T, randtest_not_zero)(a, state, ctx); TEMPLATE(T, set)(b, a, ctx); TEMPLATE(T, inv)(c, b, ctx); TEMPLATE(T, inv)(b, b, ctx); result = (TEMPLATE(T, equal)(b, c, ctx)); if (!result) { flint_printf("FAIL (aliasing):\n\n"); flint_printf("a = "), TEMPLATE(T, print_pretty)(a, ctx), flint_printf("\n"); flint_printf("b = "), TEMPLATE(T, print_pretty)(b, ctx), flint_printf("\n"); flint_printf("c = "), TEMPLATE(T, print_pretty)(c, ctx), flint_printf("\n"); TEMPLATE(T, ctx_print)(ctx); abort(); } TEMPLATE(T, clear)(a, ctx); TEMPLATE(T, clear)(b, ctx); TEMPLATE(T, clear)(c, ctx); TEMPLATE(T, ctx_clear)(ctx); } /* Check a * ~a == 1 for units*/ for (i = 0; i < 2000; i++) { TEMPLATE(T, ctx_t) ctx; TEMPLATE(T, t) a, b, c; TEMPLATE(T, ctx_randtest)(ctx, state); TEMPLATE(T, init)(a, ctx); TEMPLATE(T, init)(b, ctx); TEMPLATE(T, init)(c, ctx); TEMPLATE(T, randtest_not_zero)(a, state, ctx); TEMPLATE(T, inv)(b, a, ctx); TEMPLATE(T, mul)(c, a, b, ctx); result = (TEMPLATE(T, is_one)(c, ctx)); if (!result) { flint_printf("FAIL (a * (~a) == 1):\n\n"); flint_printf("a = "), TEMPLATE(T, print_pretty)(a, ctx), flint_printf("\n"); flint_printf("b = "), TEMPLATE(T, print_pretty)(b, ctx), flint_printf("\n"); flint_printf("c = "), TEMPLATE(T, print_pretty)(c, ctx), flint_printf("\n"); abort(); } TEMPLATE(T, clear)(a, ctx); TEMPLATE(T, clear)(b, ctx); TEMPLATE(T, clear)(c, ctx); TEMPLATE(T, ctx_clear)(ctx); } FLINT_TEST_CLEANUP(state); flint_printf("PASS\n"); return EXIT_SUCCESS; }