Abstract. We present a relational algebra based framework for compiling e cient sparse matrix code from dense DO-ANY loops and a speci cation of the representation of the sparse matrix. We present experimental data that demonstrates that the code generated by our compiler achieves performance competitive with that of hand-written codes for important computational kernels.