2026-10-26 06:42:44
— part of check-in
[7f8d29abf6]
on branch tip-764_tcl90
— The `examples/matrices/` example is ready, and all 22 checks in its `test.tcl` script pass. During performance measurement, I identified two instances of $M(i,j)$ access that were still slow, so I optimized them; since this involved modifying Tcl source code, the version has been updated to v16i.
The example
`matrices.tcl` defines the following types:
```tcl
type def ligne3 list(3).double
type def {-compact}matrix3 list(3).ligne3
type def {-compact}lot list.matrix3
```
It also provides `mat::init`, `mat::header` (the expected header), and equivalent calculations implemented in Tcl, as well as `mat::rotz` for generating rotations.
`mat_types.h` is generated via `type {c!}export`, and `test.tcl` verifies that it remains consistent with the defined types.
`mat.c` provides the following C commands:
Command Function
`mat::trace`, `mat::det` Read a matrix using `Tcl_AnnotatedGetCells`, or via lists if the data is not stored in cells.
`mat::mul` Returns the product, constructed in cells using `Tcl_AnnotatedCreateCells`.
`mat::identite` Creates an identity matrix.
`mat::lot_det` Reads a batch directly as a `matrix3[n]` array.
`mat::layout` Returns the sizes as perceived by the compiler.
`test.tcl` verifies:
the memory layout;
that Tcl and C produce identical results in both directions;
a batch of 1,002 matrices;
values not stored in cells;
error handling.
`bench.tcl` compares raw Tcl, typed Tcl (with or without cell-based storage), and C.
`README.md` explains how to compile on Linux and MinGW, and how to regenerate the header file.
Valgrind reports no issues with this example. Measurements (µs)
|Operation |Raw Tcl |Typed Tcl (in arrays) |C|
|:---|---:|---:|---:|
|Determinant |1.0 |1.6 |0.22|
|Product |5.6 |23 |1.1|
|10,000 determinants |26,000 |21,000 |350|
The typed Tcl product remains about 4 times slower than the raw version, because it constructs its indices ($A($i.0)) and its result matrix with every call.
The two accelerated read operations (v16i)
For a matrix within a batch—obtained via `foreach` or `lindex`—$M(i.j) is now read directly from the cell. Calculating 10,000 determinants in Tcl now takes 21 ms instead of 176 ms, making it faster than raw Tcl.
For a typed list without `{-compact}` (e.g., `list.list(3).double`), $M(i.j) traverses the lists directly. The time for a single determinant calculation drops from 16.7 µs to 1.8 µs. The outputs are identical to those from v16b, which lacked this shortcut.
Verifications
All 68 tests pass—both with and without the compact form—and every file yields the same output in both cases.
Valgrind reports no issues, aside from the standard warning regarding `executable_pe.tcl`.
`make test` continues to show the same 61 failures.
There is no kernel patch. `mat.so` is not included in the archive; you must compile `mat.c` (or `mat.dll` on Windows) and then run `tclsh test.tcl`. The documentation and schedule have been updated; `typeparse.zip` and `REPRISE.md` are attached.
(user:
Florentis,
size: 2846)
[annotate]
[blame][check-ins using]