tinyblocks-tensor: tensores com gradiente automatico como blocos
Tensores de float (ate 6 eixos) viajam como bloco-handle; cada bloco produtor e dono de um handle e troca o tensor a cada avaliacao. Contas com broadcasting, matmul em lote (GEMM com AVX2 escolhido em execucao e pool de threads), forma, fatias, juncao, indices, reducoes, imagem, bytes de arquivo e .tbt. Autograd por grafo com contagem de referencias; parametros por dono e por grupo, salvar/carregar. Outras libraries usam a tabela TbTensorApi do lib_userdata, sem linkar. test-tensor confere cada gradiente por diferenca finita. O "escreva" passa a usar as classes de valor (tensor aparecia como "resultado"). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3dd132d12d
commit
520cb10f08
11 files changed
+2586
-25
No files matched your search
@@ -8,28 +8,21 @@
|
||||
#include <tinyblocks/tb_json_block.h>
|
||||
#include "tb_appearance.h"
|
||||
|
||||
/* "escreva [rotulo] (valor)": o texto de cada um vem da classe do valor
|
||||
(numero, texto, lista, tensor...). So o rotulo: escreve so ele. */
|
||||
static void eval_print(TinyBlocks_Block* self, TinyBlocks* rt) {
|
||||
TinyBlocks_Value label = tb_block_get_input(self, rt, 0);
|
||||
TinyBlocks_Value value = tb_block_get_input(self, rt, 1);
|
||||
/* o primeiro campo aceita numero encaixado (ex.: "posição x do mouse") */
|
||||
char num[48];
|
||||
const char* lbl = "resultado";
|
||||
if (label.kind == TB_VALUE_TEXT && label.as.text) lbl = label.as.text;
|
||||
else if (label.kind == TB_VALUE_INTEGER) { snprintf(num, sizeof(num), "%lld", (long long)label.as.integer); lbl = num; }
|
||||
else if (label.kind == TB_VALUE_REAL) { snprintf(num, sizeof(num), "%g", label.as.real); lbl = num; }
|
||||
if (value.kind == TB_VALUE_INTEGER)
|
||||
printf("%s = %lld\n", lbl, (long long)value.as.integer);
|
||||
else if (value.kind == TB_VALUE_REAL)
|
||||
printf("%s = %g\n", lbl, value.as.real);
|
||||
else if (value.kind == TB_VALUE_TEXT)
|
||||
printf("%s = %s\n", lbl, value.as.text ? value.as.text : "");
|
||||
else if (value.kind == TB_VALUE_JSON && value.as.json) { /* listas e objetos */
|
||||
char* js = tb_json_stringify(value.as.json);
|
||||
printf("%s = %s\n", lbl, js ? js : "[]");
|
||||
free(js);
|
||||
char* lbl = label.kind == TB_VALUE_NONE ? NULL : tb_value_to_string(label);
|
||||
const char* l = lbl && lbl[0] ? lbl : "resultado";
|
||||
if (value.kind == TB_VALUE_NONE || (value.kind == TB_VALUE_TEXT && (!value.as.text || !value.as.text[0]))) {
|
||||
printf("%s\n", l);
|
||||
} else {
|
||||
char* v = tb_value_to_string(value);
|
||||
printf("%s = %s\n", l, v ? v : "");
|
||||
free(v);
|
||||
}
|
||||
else
|
||||
printf("%s\n", lbl);
|
||||
free(lbl);
|
||||
self->dirty = false;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user