Skip to content

Instantly share code, notes, and snippets.

View mclements's full-sized avatar

mclements

  • Karolinska Institutet
  • Stockholm
View GitHub Profile
@mclements
mclements / Makefile
Last active August 3, 2023 13:21
Example of using Harbour and the new SUMMARIZE command for https://rosettacode.org/wiki/Merge_and_aggregate_datasets
.PHONY: clean
rosetta2: clean rosetta2.prg
hbmk2 -run rosetta2.prg hbnf.hbc
clean:
rm -f rosetta2
rm -f patient.dbf visit.dbf summ1.dbf summ2.dbf summ3.dbf
@mclements
mclements / temp_2.c
Created February 21, 2023 15:18
Using the Rmath standalone library with a user-defined Mersenne Twister RNG
#define MATHLIB_STANDALONE
#include <Rmath.h>
#include <stdio.h>
#include <math.h>
#include <stdint.h>
//copied from src/main/RNG.c:
typedef unsigned int Int32;
static Int32 dummy[625];
@mclements
mclements / Makefile
Last active February 21, 2023 15:15
Error with linking Mercury with a static file
minimal_fails: minimal_fails.m
mmc --make -v -l:libRmath.a -L `pkg-config --variable=libdir libRmath` minimal_fails && ./minimal_fails
minimal_ok: minimal_ok.m
mmc --make -v -l:libRmath.a -L `pkg-config --variable=libdir libRmath` minimal_ok && ./minimal_ok
minimal_fixed: minimal_fixed.m
mmc --make -v -l:libRmath.a -L `pkg-config --variable=libdir libRmath` minimal_fixed && ./minimal_fixed
@mclements
mclements / test_run.m
Created December 26, 2022 09:20
Mercury experiment for speed and memory for summing 1..10000000
:- module test_run.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module ranges, solutions, list, int, string.
main(!IO) :-
@mclements
mclements / Array2ext.sml
Last active July 22, 2020 10:54
Hack to use MLton with BLAS using the underlying data structure for Array2
infix 7 *!
infix 6 +! -!
structure SeqIndex = struct
open Int
val op +! = Int.+
val op -! = Int.-
val op *! = Int.*
local
fun ltu (lhs, rhs) =
case (compare (lhs, 0), compare (rhs, 0)) of
@mclements
mclements / mlton-blas-naive.sml
Created July 21, 2020 16:11
SML / MLton: naive implementation for BLAS-based matrix multiplication
local
val call = _import "cblas_dgemm" public: int * int * int * int * int * int * real * real Vector.vector * int * real Vector.vector * int * real * real Array.array * int -> unit;
datatype cblasTranspose = NoTrans | Trans | ConjTrans | ConjNoTrans
fun cblasOrder Array2.RowMajor = 101
| cblasOrder Array2.ColMajor = 102
fun cblasTranspose NoTrans = 111
| cblasTranspose Trans = 112
| cblasTranspose ConjTrans = 113
| cblasTranspose ConjNoTrans = 114
fun getVector a =
@mclements
mclements / setup-and-test-cim.sh
Created June 20, 2019 18:47
Cim: download, configure, make, install and run an example
git clone git://git.savannah.gnu.org/cim.git
cd cim
autoreconf -i
./configure
make
make check
sudo make install
cat > helloWorld.sim <<EOF
begin
@mclements
mclements / poly_smlnj-lib.patch
Created July 31, 2018 20:57
Revised patch for using MLton's smlnj-lib with Poly/ML
--- smlnj-lib/HTML/html-elements-fn.sml.orig Mon Nov 5 18:02:27 2007
+++ smlnj-lib/HTML/html-elements-fn.sml Mon Nov 5 18:02:44 2007
@@ -144,7 +144,8 @@
* 3) a string literal enclosed in ''
*)
fun scanAttrVal (ctx, attrName, ss) = let
- fun isNameChar (#"." | #"-") = true
+ fun isNameChar #"." = true
+ | isNameChar #"-" = true
| isNameChar c = (Char.isAlphaNum c)
@mclements
mclements / poly_smlnj-lib.sml
Last active July 31, 2018 20:45
Modification of poly_smlnj-lib.sml to allow for Word8Array - does not require patching of mlton, but does exclude the HTML structures
structure Word31 = Word;
structure Int32 = Int;
structure Unsafe = struct
structure CharVector = CharVector
structure Array = Array
structure Vector = Vector
structure Word8Array =
struct
open Word8Array
fun create length = array(length, 0w0)