forked from kidanger/vpv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrapplambda.c
More file actions
58 lines (47 loc) · 1.31 KB
/
wrapplambda.c
File metadata and controls
58 lines (47 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <stdio.h>
#include <setjmp.h>
#if __STDC_VERSION__ >= 201112L
_Thread_local
#endif
jmp_buf g_jmpbuf;
#define _FAIL_C
#include <stdarg.h>
static void fail(const char *fmt, ...) __attribute__((noreturn));
static void fail(const char *fmt, ...)
{
va_list argp;
fprintf(stderr, "plambda error: ");
va_start(argp, fmt);
vfprintf(stderr, fmt, argp);
va_end(argp);
fprintf(stderr, "\n");
fflush(NULL);
longjmp(g_jmpbuf, 1);
}
#define HIDE_ALL_MAINS
#include "imscript/plambda.c"
float* execute_plambda(int n, float** x, int* w, int* h, int* pd, char* program, int* opd)
{
if (setjmp(g_jmpbuf)) {
return 0;
}
struct plambda_program p[1];
plambda_compile_program(p, program);
if (n > 0 && p->var->n == 0) {
int maxplen = n*20 + strlen(program) + 100;
char newprogram[maxplen];
add_hidden_variables(newprogram, maxplen, n, program);
plambda_compile_program(p, newprogram);
}
if (n != p->var->n && !(n == 1 && p->var->n == 0))
fail("the program expects %d variables but %d images "
"were given", p->var->n, n);
//print_compiled_program(p);
int pdreal = eval_dim(p, x, pd);
float *out = xmalloc(*w * *h * pdreal * sizeof*out);
*opd = run_program_vectorially(out, pdreal, p, x, w, h, pd);
assert(*opd == pdreal);
collection_of_varnames_end(p->var);
return out;
}
// vim:set foldmethod=marker: