(self, ctx)
| 213 | class TestGraph: |
| 214 | |
| 215 | def test_add(self, ctx): |
| 216 | n = 256 |
| 217 | ta = lib.ggml_new_tensor_1d(ctx, lib.GGML_TYPE_F32, n) |
| 218 | tb = lib.ggml_new_tensor_1d(ctx, lib.GGML_TYPE_F32, n) |
| 219 | tsum = lib.ggml_add(ctx, ta, tb) |
| 220 | assert tsum.type == lib.GGML_TYPE_F32 |
| 221 | |
| 222 | gf = ffi.new('struct ggml_cgraph*') |
| 223 | lib.ggml_build_forward_expand(gf, tsum) |
| 224 | |
| 225 | a = np.arange(0, n, dtype=np.float32) |
| 226 | b = np.arange(n, 0, -1, dtype=np.float32) |
| 227 | copy(a, ta) |
| 228 | copy(b, tb) |
| 229 | |
| 230 | lib.ggml_graph_compute_with_ctx(ctx, gf, 1) |
| 231 | |
| 232 | assert np.allclose(numpy(tsum, allow_copy=True), a + b) |
| 233 | |
| 234 | class TestQuantization: |
| 235 |
nothing calls this directly
no test coverage detected