text:
# Copyright (c) 2018-2021, Carnegie Mellon University
# See LICENSE for details

Declare(_StandardMeasureVerify);

SetMakeOptsPThreads:=function(opts)
   opts.profile.makeopts.LDFLAGS:=Concat(When(IsBound(opts.profile.makeopts.LDFLAGS),opts.profile.makeopts.LDFLAGS,"")," -lpthread -L/lib/tls -lm");
   opts.profile.makeopts.ADDSRC:=Concat("../../../lib/smp2.c ",When(IsBound(opts.profile.makeopts.ADDSRC),opts.profile.makeopts.ADDSRC,""));
   opts.profile.makeopts.TIMER:="../common/time_threads.c";
   opts.profile.makeopts.TIMER_OPTS:="";
end;

SetMakeOptsSSE:=function(opts)
   opts.profile.makeopts.CFLAGS:=Concat(opts.profile.makeopts.CFLAGS," -msse3 -vec-report=0");
end;

SetMakeOptsOpenMP:=function(opts)
   opts.profile.makeopts.CFLAGS:=Concat(opts.profile.makeopts.CFLAGS," -openmp -openmp-report0");
end;

SetMakeOptsAffinity:=function(opts)
   opts.profile.makeopts.CFLAGS:=Concat(opts.profile.makeopts.CFLAGS," -DUSE_SCHED_AFFINITY");
end;

SetMakeOptsLibgen:=function(opts)
   opts.profile.makeopts.CFLAGS:=Concat(opts.profile.makeopts.CFLAGS," -fno-alias -fno-fnalias -fno-inline-functions");
end;

SetMakeOptsAssembly:=function(opts)
   opts.profile.makeopts.CFLAGS:=Concat(opts.profile.makeopts.CFLAGS," -save-temps");
end;

_default_makeopts := rec(
    GAP := "gap.c",
    STUB := "stub.h",
);

#
## default options for sim-outorder
#
# simple scalar uses a parametrized architecture. these params
# were inferred from details in the following paper:
#
# "Efficient Resource Sharing in Concurrent Error Detecting
# Superscalar Microarchitectures"
#
# Jared C. Smolens, Jangwoo Kim, James C. Hoe, and Babak Falsafi
#
# 37th Annual IEEE/ACM International Symposium on Microarchitecture
#

default_profiles := rec(
    no_compile := rec(
        name := "no-compile",
        meas := (a,b) -> 1000,
        verify := (a,b) -> false,
        makeopts := rec( CFLAGS := "" )
    ),

    # LINUX profiles
    ###############

    linux_power_gcc:=
    rec(
        name := "linux-power-gcc",
        makeopts := rec(
            CFLAGS := "",
            CC := "gcc" ),
        outdir := "/tmp/spiral/power",
        meas := (a, b) -> _StandardMeasureVerify(a, b, ""),
        verify := (a, b) -> _StandardMeasureVerify(a, b, "verify") ),

    arm_icount := rec(
        name := "arm-icount",
        makeopts := rec(
            CFLAGS := "-O2 -std=c99 -fomit-frame-pointer",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_arm := rec(
        name := "linux-arm",
        makeopts := rec(
            CFLAGS := "-O2 -std=c99 -fomit-frame-pointer",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_x86_icc := rec(
        name := "linux-x86",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-O3 -w -std=c99 -fomit-frame-pointer -vec-report0",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_avx_icc := rec(
        name := "linux-x86",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-O3 -w -mavx -std=c99 -fomit-frame-pointer -vec-report0",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_arm_pthread := rec(
        name := "linux-arm",
        makeopts := rec(
            CFLAGS := "-O3 -std=c99 -fomit-frame-pointer",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, "pthread"),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verifyPThread")
    ),

    linux_x86_icc_openmp := rec(
        name := "linux-x86",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-O -openmp -w -std=c99 -fomit-frame-pointer",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_x86_gcc := rec(
        name := "linux-x86",
        makeopts := rec(
            CC := "gcc",
            CFLAGS := "-O2 -Wall -fomit-frame-pointer -march=native -std=c99",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_x86_cuda := rec(
        name := "linux-cuda",
        makeopts := rec(
            CC := "nvcc",
            CFLAGS := "-O2 ",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_x86_threads := rec(
        name := "linux-x86",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-O -Wall -w -std=c99 -msse2",
            LDFLAGS := "-lpthread -L/lib/tls -lm",
            ADDSRC := "../../../lib/smp2.c",
            TIMER := "../common/time_threads.c",
            TIMER_OPTS := ""
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_x86_icc_threads := rec(
        name := "linux-x86",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-O -Wall -std=c99 -openmp",
            LDFLAGS := "-lguide -lpthread -L/lib/tls -lm",
            ADDSRC := "../../../lib/smp2.c",
            TIMER := "../common/time_threads.c",
            TIMER_OPTS := ""
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_x86_perfmon2 := rec(
        name := "linux-x86-perfmon2",
        makeopts := rec(
            CC := "gcc",
            CFLAGS := "-O3 -fomit-frame-pointer -std=c99",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_x86_newtimer := rec(
        name := "linux-x86-newtimer",
        makeopts := rec(
            CC := "gcc",
            CFLAGS := "-O3 -fomit-frame-pointer -std=c99",
            HOST := "localhost"
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_lrb_icc := rec(
      name := "linux-lrb-icc",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-std=c99 -w -vec-report0 -O",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

     linux_lrb_icc_openmp := rec(
        name := "linux-lrb-icc",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-O2 -openmp -w -std=c99 -fomit-frame-pointer",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_lrb_icc_threads := rec(
        name := "linux-lrb-icc",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-O2 -Wall -std=c99 -openmp",
            LDFLAGS := "-lguide -lpthread -L/lib/tls -lm",
            ADDSRC := "../../../lib/smp2.c",
            TIMER := "../common/time_threads.c",
            TIMER_OPTS := ""
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_x86_vtune := rec(
        name := "linux-x86-vtune",
        makeopts := rec(
            CC := "gcc",
            CFLAGS := "-O2 -g -fomit-frame-pointer -std=c99",
            RUNS := 1000,
            EVENT := "L1D_REPL",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_arm_gcc := rec(
        name := "linux-arm-gcc",
        makeopts := rec(
            CC := "gcc",
            CFLAGS := "-O2 -std=c99 -fomit-frame-pointer",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    # LINUX embedded profiles
    #########################

    linux_xscale_gcc := rec(
        name := "linux-xscale-gcc",
        makeopts := rec(
            CC := "arm-xscale-linux-gnu-gcc",
            CFLAGS := "-O2",
            COMPILER_DIR := "",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    ti_dsk_tms320c6713 := rec(
        name := "ti-dsk-tms320c6713",
        makeopts := rec(
            CFLAGS := "-O3 -std=c99",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    # MS WINDOWS profiles
    ##############

    win_x86_vcc := rec(
        name := "win-x86-vcc",
        makeopts := rec(
            CC := "cl",
            CFLAGS := "/O2",
        ),
        outdir := "/temp/vcc32",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x64_vcc := rec(
        name := "win-x64-vcc",
        makeopts := rec(
            CC := "cl",
            CFLAGS := "/O3",
        ),
        premake := () -> "vcvarsall.bat amd64 > nul",
        outdir := "/temp/vcc64",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x86_icc := rec(
        name := "win-x86-icc",
        makeopts := rec(
            CC := "icl",
            CFLAGS := "/O3", # /G7 /QxSSSE3",
        ),
        premake := () -> spiral.IntelC.ia32().premake,
        outdir := "/temp/icc32",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x86_icc_openmp := rec(
        name := "win-x86-icc-openmp",
        makeopts := rec(
            CC := "icl",
            CFLAGS := "/O3 /Qopenmp", # /G7 /QxSSSE3",
#            LDFLAGS := "/NODEFAULTLIB:libc /NODEFAULTLIB:libm /NODEFAULTLIB:libirc /DEFAULTLIB:libcmt /DEFAULTLIB:libmmt /DEFAULTLIB:libircmt"
        ),
        premake := () -> spiral.IntelC.ia32().premake,
        outdir := "/temp/icc32omp",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x86_icc_threads := rec(
        name := "win-x86-icc-threads",
        makeopts := rec(
            CC := "icl",
            CFLAGS := "/O3", # /G7 /QxSSSE3",
        ),
        premake := () -> spiral.IntelC.ia32().premake,
        outdir := "/temp/threads32",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x64_icc := rec(
        name := "win-x64-icc",
        makeopts := rec(
            CC := "icl",
            CFLAGS := "/O3 /G7 /QxSSSE3",
        ),
        premake := () -> spiral.IntelC.em64t().premake,
        outdir := "/temp/icc64",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x64_icc_openmp := rec(
        name := "win-x64-icc-openmp",
        makeopts := rec(
            CC := "icl",
            CFLAGS := "/O3 /G7 /QxSSSE3 /Qopenmp",
#            LDFLAGS := "/NODEFAULTLIB:libc /NODEFAULTLIB:libm /NODEFAULTLIB:libirc /DEFAULTLIB:libcmt /DEFAULTLIB:libmmt /DEFAULTLIB:libircmt"
        ),
        premake := () -> spiral.IntelC.em64t().premake,
        outdir := "/temp/icc64omp",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x64_icc_threads := rec(
        name := "win-x64-icc-threads",
        makeopts := rec(
            CC := "icl",
            CFLAGS := "/O3 /G7 /QxSSSE3",
        ),
        premake := () -> spiral.IntelC.em64t().premake,
        outdir := "/temp/threads64",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x86_gcc := rec(
        name := "win-x86-gcc",
        target := rec(name := "win-x86-gcc"),
        makeopts := rec(
            CC := "gcc",
            CFLAGS := "-O3 -march=native -std=c99 -Wno-implicit -Wno-aggressive-loop-optimizations",
        ),
        outdir := "/temp",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x86_llvm := rec(
        name := "win-x86-llvm",
        target := rec(name := "win-x86-llvm"),
        makeopts := rec(
            CC := "clang",
            CFLAGS := "-O2 -march=native -std=c99 -Wall",
        ),
        outdir := "/temp",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_x86_nvcc_gpu := rec(
        name := "win-x86-nvcc-gpu",
        makeopts := rec(
            CC := "nvcc",
            CFLAGS := "",
            GAP:= "gap.cu"
        ),
#   premake := () -> spiral.IntelC.ia32().premake,
        outdir := "/temp/nvcc",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
  ),

    win_x64_cuda := rec (
	name := "win-x64-cuda",
	target := rec(name := "win-x64-cuda"),
	makeopts := rec (
	    CC := "nvcc",
	    CFLAGS := "",
	),
        outdir := "/temp",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    # altivec profiles
    # ------------------------------------------------------------------------------
    linux_altivec_gcc := rec(
        name := "linux-altivec-gcc",
        makeopts := rec(
            CFLAGS := ""
        ),
        stubopts := rec(
        ),
        outdir := "/tmp/spiral/altivec",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify"),
        verifyfftw := (a,b) -> _StandardMeasureVerify(a,b, "fftwverify")
    ),

    # CELL processor profiles
    ##############

    linux_cellSPU_gcc := rec(
        name := "linux-cellSPU-gcc",
        makeopts := rec(
            CFLAGS := ""
        ),
        stubopts := rec(
        ),
        outdir := "/tmp/spiral/cellSPU",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_cellSPU_gcc_MMM := rec(
        name := "linux-cellSPU-gcc-MMM",
        makeopts := rec(
            CFLAGS := ""
        ),
        stubopts := rec(
        ),
        outdir := "/tmp/spiral/cellSPU",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    linux_cellmultiSPU_gcc := rec(
        name := "linux-cellmultiSPU-gcc",
        makeopts := rec(
            CFLAGS := "",
            GAP_PPE := "gap_ppe.c",
            GAP_PPE_TWIDDLES_DECL := "twiddles-declare.h",
            GAP_PPE_TWIDDLES_SET  := "twiddles-set.h",
        ),
        stubopts := rec(
            SPUS := 1,
            MULTIBUFFER_ITERATIONS := 1,
        ),
        outdir := "/tmp/spiral/cellmultiSPU",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify"),
        verifyfftw := (a,b) -> _StandardMeasureVerify(a,b, "fftwverify"),
        verifyquick  := (a,b) -> _StandardMeasureVerify(a,b, "quickverify")
    ),

    linux_cellmultiSPU_speadk := rec(
        name := "linux-cellmultiSPU-speadk",
        makeopts := rec(
            CFLAGS := ""
        ),
        stubopts := rec(
            SPUS := 1,
            MULTIBUFFER_ITERATIONS := 1,
        ),
        outdir := "/tmp/spiral/cellmultiSPUspeadk",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify"),
        verifyfftw := (a,b) -> _StandardMeasureVerify(a,b, "fftwverify")
    ),

    linux_cellPPU_gcc := rec(
        name := "linux-cellPPU-gcc",
        makeopts := rec(
            CFLAGS := ""
        ),
        stubopts := rec(
        ),
        outdir := "/tmp/spiral/cellPPU",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    win_remote := rec(
        name := "win-remote",
        host := "host.domain",
        userid := "user",
        passwd := "password",
        outdir := "S:/temp/win-remote",
        hostdir := ".",
        exec := "makecmd.cmd",
        remote_cmd := "remote.cmd",
#        meas := (a,b) -> _RemoteMeasureVerify(a,b, ""),
#        verify := (a,b) -> _RemoteMeasureVerify(a,b, "verify"),
#        runmake := (a,b) -> _RemoteRunMake(a,b),
        remote := true,
        library := "vanilla",
        remote_library := "vanilla",
        appendSymbol := "$*",
#        download := opts -> _RemoteDownload(opts),
#        clean := opts -> _RemoteClean(opts),
        libdir := "profiler",
        dload_cmd := "download.cmd",
        clean_cmd := "clean.cmd"
    ),

    # SIMPLESCALAR 3.0 profiles
    ##############

    ssnix_simple_gcc_cachemiss := rec(
        name := "ssnix-simple-gcc",
        makeopts := rec(
            SSDIR := "~/ss",
            CFLAGS := "-O2 -I~/ss/include",
            SSBIN := "sim-cache",
            SSPARAM := "dl1.misses"
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b,""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    ssnix_simple_gcc_instr := rec(
        name := "ssnix-simple-gcc",
        makeopts := rec(
            SSDIR := "~/ss",
            CFLAGS := "-O2 -I~/ss/include",
            SSBIN := "sim-outorder",
            SSPARAM := "sim_cycle"
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b,""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    ssnix_simple_gcc_cachemissnew := rec(
        name := "ssnix-simple-gcc-new",
        makeopts := rec(
            SSDIR := "~/ss",
            CFLAGS := "-O2 -I~/ss/include",
            SSBIN := "sim-cache",
            SSPARAM := "dl1.misses",
            TIMER_OPTS := "-n 1"
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b,""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    # FPGA Hardware generator profile
    ####################

    fpga_splhdl := rec(
        name := "fpga-splhdl",
        outdir := "/tmp/spiral",
        threshold := 2048,
        makeopts := rec(
            OUTNAME := "gap.v",
            GAP := "gap.spl",
            VLOGLIB := "/Users/pam/eclwork/SPLHDL/support",
            NCV := "ncverilog",
            SPLHDL := "splhdl",
            GETRES := "getRes",
            IVERILOG := "iverilog",
            VVP := "vvp",
            DATATYPE := "fix 16", #other possibility 'float'.
            TWIDTYPE := ""
        ),
        meas := (a,b) -> _StandardMeasureVerify(a,b,""),
    ),

    # INTEL MAC profiles
    #######

    darwin_x86_gcc := rec(
        name := "darwin-x86",
        makeopts := rec(
            CC := "gcc",
            CFLAGS := "-O2 -fomit-frame-pointer -msse2 -std=c99",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    darwin_x86_icc := rec(
        name := "darwin-x86",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-O3 -fomit-frame-pointer -std=c99",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    # PTLSim backend
    ############

    linux_ptlsim_icc := rec(
        name := "linux-ptlsim",
        makeopts := rec(
            CC := "icc",
            CFLAGS := "-O3 -fomit-frame-pointer -std=c99",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify"),
    ),

    # Basilio's code analyzer.
     linux_x86_anl := rec(
         name := "linux-x86-anl",
         makeopts := rec(
             CC := "gcc",
             CFLAGS := "-O2 -msse2 -w -std=c99 -fomit-frame-pointer",
         ),
         outdir := "/tmp/spiral",
         meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
         verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
     ),

    # DPA simulator profile
    linux_dpa_sim := rec(
        name := "linux-dpa-simulator",
        makeopts := rec(
            DPA_DIR := "${HOME}/DPA",
            DPA_SPEC := "lmvec_memvec_vecint",
            CC := "gcc",
            CFLAGS := "",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

    # DPA emulator (modelsim) profile
    linux_dpa_emu := rec(
        name := "linux-dpa-modelsim",
        makeopts := rec(
            DPA_DIR := "${HOME}/DPA",
            DPA_SPEC := "lmvec_memvec_vecint",
            XCC_DIR := "/opt/sparc-elf-4.4.2",
            MODELSIM_DIR := "/opt/modelsim",
            CC := "sparc-elf-gcc",
            CFLAGS := "",
        ),
        outdir := "/tmp/spiral",
        meas := (a,b) -> _StandardMeasureVerify(a,b, ""),
        verify := (a,b) -> _StandardMeasureVerify(a,b, "verify")
    ),

);


text:
--
-- An instance of this template must have a %Export section and the export_terminals option
--
-- Macros that may be redefined in an instance of this template
--
--     $eof_token
--     $additional_interfaces
--     $super_stream_class -- subclass LpgLexStream for getKind
--     $prs_stream_class -- use /.PrsStream./ if not subclassing
--     $super_class
--
-- B E G I N N I N G   O F   T E M P L A T E   LexerTemplateF
--
%Options programming_Language=typescript,margin=4
%Options table
%options action-block=("*.ts", "/.", "./")
%options ParseTable=ParseTable
%Options prefix=Char_

--
-- This template requires that the name of the EOF token be set
-- to EOF and that the prefix be "Char_" to be consistent with
-- KeywordTemplateD.
--
%Eof
    EOF
%End

--
-- This template also requires that the name of the parser EOF
-- Token to be exported be set to EOF_TOKEN
--
%Export
    EOF_TOKEN
%End

%Define
    --
    -- Macros that are be needed in an instance of this template
    --
    $eof_token /.%_EOF_TOKEN./

    $additional_interfaces /../
    $super_stream_class /.%file_prefix%LpgLexStream./
    $prs_stream_class /.IPrsStream./
    $super_class /.Object./

    $prs_stream /. // macro prs_stream is deprecated. Use function getPrsStream
                  this.getPrsStream()./
    $setSym1 /. // macro setSym1 is deprecated. Use function setResult
                this.this.lexParser.setSym1./
    $setResult /. // macro setResult is deprecated. Use function setResult
                  this.this.lexParser.setSym1./
    $getSym /. // macro getSym is deprecated. Use function getLastToken
               this.this.lexParser.getSym./
    $getToken /. // macro getToken is deprecated. Use function getToken
                 this.this.lexParser.getToken./
    $getLeftSpan /. // macro getLeftSpan is deprecated. Use function getLeftSpan
                    this.this.lexParser.getFirstToken./
    $getRightSpan /. // macro getRightSpan is deprecated. Use function getRightSpan
                     this.this.lexParser.getLastToken./

    --
    -- Macros useful for specifying actions
    --
    $Header
    /.
                //
                // Rule %rule_number:  %rule_text
                //
                ./

    $DefaultAction
    /.%Header%case %rule_number: { ./

    $BeginAction /.%DefaultAction./

    $EndAction
    /.            break;
                }./

    $BeginJava
    /.%BeginAction
                %symbol_declarations./

    $EndJava /.%EndAction./

    $NoAction
    /.%Header%case %rule_number:
                    break; ./

    $BeginActions
    /.
        public  ruleAction(ruleNumber : number ) : void
        {
            switch(ruleNumber)
            {./

    $SplitActions
    /.
                    default:
                        this.ruleAction%rule_number(ruleNumber);
                        break;
                }
                return;
            }

            public  ruleAction%rule_number(ruleNumber : number ) : void
            {
                switch (ruleNumber)
                {./

    $EndActions
    /.
                default:
                    break;
            }
            return;
        }./
%End

%Globals
    /.
  import { RuleAction, ParseTable, LexParser, ILexStream, IPrsStream, Monitor,LpgLexStream} from "lpg2ts";
  import { %prs_type } from ".\/%prs_type";
  import { %sym_type } from ".\/%sym_type";
  import { %kw_lexer_class } from ".\/%kw_lexer_class";
    ./
%End

%Headers
    /.
    export class %action_type extends %super_class implements RuleAction%additional_interfaces
    {
        private lexStream: %super_stream_class ;

        private static  prs : ParseTable = new %prs_type();
        public  getParseTable() : ParseTable{ return %action_type.prs; }

        private  lexParser  : LexParser= new LexParser();
        public  getParser()  : LexParser{ return this.lexParser; }

        public  getToken(i : number)  : number{ return this.lexParser.getToken(i); }
        public  getRhsFirstTokenIndex(i : number) : number{ return this.lexParser.getFirstToken(i); }
        public  getRhsLastTokenIndex(i : number)  : number{ return this.lexParser.getLastToken(i); }

        public getLeftSpan() : number{ return this.lexParser.getToken(1); }
        public getRightSpan() : number { return this.lexParser.getLastToken(); }

        public  resetKeywordLexer() : void
        {
            if (!this.kwLexer)
                  this.kwLexer = new %kw_lexer_class(this.lexStream.getInputChars(), %_IDENTIFIER);
             this.kwLexer.setInputChars(this.lexStream.getInputChars());
        }

        public  reset( filename : string,  tab : number = 4, input_chars? : string) : void
        {
            this.lexStream = new %super_stream_class(filename,input_chars, tab);
            this.lexParser.reset(<ILexStream>  this.lexStream, %action_type.prs, <RuleAction> this);
            this.resetKeywordLexer();
        }

        constructor( filename : string,  tab : number =  4 ,input_chars? : string)
        {
            super();
            this.lexStream = new %super_stream_class(filename,input_chars, tab);
            this.lexParser.reset(<ILexStream>  this.lexStream, %action_type.prs, <RuleAction> this);
            this.resetKeywordLexer();
        }

        public  getILexStream()  : ILexStream{ return  this.lexStream; }

        /**
         * @deprecated replaced by {@link #getILexStream()}
         */
        public  getLexStream()  : ILexStream{ return  this.lexStream; }

        private initializeLexer(prsStream : %prs_stream_class ,  start_offset : number, end_offset : number) : void
        {
            if (this.lexStream.getInputChars() == null)
                throw new ReferenceError("LexStream was not initialized");
            this.lexStream.setPrsStream(prsStream);
            prsStream.makeToken(start_offset, end_offset, 0); // Token list must start with a bad token
        }

        private  addEOF(prsStream : %prs_stream_class, end_offset : number ) : void
        {
            prsStream.makeToken(end_offset, end_offset, %eof_token); // and end with the end of file token
            prsStream.setStreamLength(prsStream.getSize());
        }

        public  lexerWithPosition(prsStream: %prs_stream_class , start_offset : number , end_offset : number, monitor? : Monitor) : void
        {
            if (start_offset <= 1)
                 this.initializeLexer(prsStream, 0, -1);
            else this.initializeLexer(prsStream, start_offset - 1, start_offset - 1);

            this.lexParser.parseCharacters(start_offset, end_offset,monitor);

            this.addEOF(prsStream, (end_offset >= this.lexStream.getStreamIndex() ? this.lexStream.getStreamIndex() : end_offset + 1));
        }

        public  lexer(prsStream: %prs_stream_class ,  monitor? : Monitor) : void
        {

            this.initializeLexer(prsStream, 0, -1);
            this.lexParser.parseCharactersWhitMonitor(monitor);
            this.addEOF(prsStream, this.lexStream.getStreamIndex());
        }

        /**
         * If a parse stream was not passed to this Lexical analyser then we
         * simply report a lexical error. Otherwise, we produce a bad token.
         */
        public  reportLexicalError( startLoc : number,  endLoc : number) : void {
            let prs_stream = this.lexStream.getIPrsStream();
            if (!prs_stream)
                this.lexStream.reportLexicalError(startLoc, endLoc);
            else {
                //
                // Remove any token that may have been processed that fall in the
                // range of the lexical error... then add one error token that spans
                // the error range.
                //
                for (let i : number = prs_stream.getSize() - 1; i > 0; i--) {
                    if (prs_stream.getStartOffset(i) >= startLoc)
                         prs_stream.removeLastToken();
                    else break;
                }
                prs_stream.makeToken(startLoc, endLoc, 0); // add an error token to the this.prsStream
            }
        }
    ./
%End

%Rules
    /.%BeginActions./
%End

%Trailers
    /.
        %EndActions
    }
    ./
%End

--
-- E N D   O F   T E M P L A T E
--

ext: gi


text:
# Copyright (c) 2018-2021, Carnegie Mellon University
# See LICENSE for details

#F ==========================================================================
#F Diag(<diag-func>)
#F ==========================================================================
Class(Diag, BaseMat, rec(
    _short_print := true,
    abbrevs := [ arg -> When(Length(arg)=1,
                         When(IsFunction(arg[1]) or IsFuncExp(arg[1]) or (IsRec(arg[1]) and not IsScalar(arg[1])) or IsList(arg[1]), [arg[1]], [[arg[1]]]),
                 [Flat(arg)]) ],

    new := meth(self, L)
        if IsList(L) then
            L := List(L, toExpArg);
            L := FList(UnifyTypes(List(L, x->x.t)), L);
        elif not IsRec(L) or not IsBound(L.lambda) then
            Error("List of numbers or LambdaList expected");
        fi;
        return SPL(WithBases(self, rec(element := L, TType := L.range()))).setDims();
    end,
    #-----------------------------------------------------------------------
    dims := self >> Replicate(2, self.element.domain()),
    #-----------------------------------------------------------------------
    isPermutation := self >> false,
    #-----------------------------------------------------------------------
    isReal := self >> let(
	t := self.element.range(),
        tt := Cond(IsVecT(t), t.t, t),
	tt <> TComplex and ObjId(tt)<>T_Complex),
    #-----------------------------------------------------------------------
    toAMat := self >> DiagonalAMat(List(EvalScalar(self.element.tolist()), EvalScalar)),
    #-----------------------------------------------------------------------
    transpose := self >> self,
    conjTranspose := self >> Diag(FConj(self.element)),
    inverse := self >> Diag(FInv(self.element)),
    #-----------------------------------------------------------------------
    normalizedArithCost := self >> 0,
    #-----------------------------------------------------------------------
    arithmeticCost := (self, costMul, costAddMul) >> Sum(self.element.tolist(), costMul),
    #-----------------------------------------------------------------------
    toloop := (self, bksize) >> let(
	j := Ind(self.element.domain()),
	ISum(j,
	    Scat(fTensor(fBase(j), fId(1))) *
	    Diag(fCompose(self.element, fTensor(fBase(j), fId(1)))) *
	    Gath(fTensor(fBase(j), fId(1)))
	).split(bksize)
    )

));

#F ==========================================================================
#F DiagCpxSplit(<diag-func>) - complex diagonal specified in split format
#F NOTE: maybe this should be somehow replaced by VRCDiag (?)
#F  this object is helpful for complex code, because it improves performance
#   when using SSE
#F ==========================================================================
Class(DiagCpxSplit, Diag, rec(
    #-----------------------------------------------------------------------
    dims := self >> Replicate(2, div(self.element.domain(), 2)),
    #-----------------------------------------------------------------------
    isReal := self >> false,
    #-----------------------------------------------------------------------
    toAMat := meth(self)
        local lst, i, cpxlst;
        lst := List(EvalScalar(self.element.tolist()), EvalScalar);
        cpxlst := [];
        for i in [0..Length(lst)/2-1] do
            Add(cpxlst, lst[2*i+1]+E(4)*lst[2*i+2]);
        od;
        return DiagonalAMat(cpxlst);
    end,
    #-----------------------------------------------------------------------
    transpose := self >> self,
    conjTranspose := self >> ObjId(self)(FRConj(self.element)),
    #-----------------------------------------------------------------------
    normalizedArithCost := self >> 0,
    #-----------------------------------------------------------------------
    #arithmeticCost := (self, costMul, costAddMul) >> Sum(self.element.tolist(), costMul)
));

Declare(RowVec, ColVec);

Class(RowVec, Diag, rec(
    dims := self >> [1, self.element.domain()],
    toAMat := self >> AMatMat([List(self.element.tolist(), EvalScalar)]),
    transpose := self >> ColVec(self.element),
    conjTranspose := self >> ColVec(FConj(self.element)),
    arithmeticCost := (self, costMul, costAddMul) >> Sum(self.element.tolist(), costAddMul),

    toBlk := self >> Checked(not IsSymbolic(self.element.domain()), Blk([self.element.tolist()])),
    toDiagBlk := self >> Checked(not IsSymbolic(self.element.domain()),
	Blk([Replicate(EvalScalar(self.element.domain()), 1)]) * Diag(self.element)),
));

Class(ColVec, Diag, rec(
    dims := self >> [self.element.domain(), 1],
    toAMat := self >> AMatMat(TransposedMat([List(self.element.tolist(), EvalScalar)])),
    transpose := self >> RowVec(self.element),
    conjTranspose := self >> RowVec(FConj(self.element)),

    toBlk := self >> self.transpose().toBlk().transpose(),
    toDiagBlk := self >> self.transpose().toDiagBlk().transpose(),
));

Declare(RCDiag);

#F RCDiagonalAMat(<elts>, <post>)
#F
#F Works similarly to RCDiag, but creates an AMat object instead of SPL.
#F See Doc(RCDiag).
#F
#F <elts> must be a list of size 2*n, which consists of interleaved real/imaginary data.
#F (not a symbolic function as in RCDiag)
#F
#F <post> must be an <amat>, and not spl
#F
RCDiagonalAMat := (elts, post) ->
    DirectSumAMat(List([1..Length(elts)/2], x ->
            let(r := EvalScalar(elts[2*x-1]), i := EvalScalar(elts[2*x]),
                post * AMatMat([[r,-i],[i,r]]))));

#F RCDiag(<diagfunc>)
#F RCDiag(<diagfunc>, <2x2 spl>)
#F
#F  Complex diagonal operating on real data in (r,i) format.
#F  Represents a block diagonal with 2x2 blocks (complex rotations),
#F  with post-processing matrix <post-spl> applied to each block.
#F
#F  For n complex numbers, <diagfunc> must be a diagonal function of size 2*n,
#F  which consists of interleaved real/imaginary data.
#F
#F  Example: RCDiag(RCData(Tw1(8,4,1))              normal twiddle diagonal
#F           RCDiag(RCData(Tw1(8,4,1)), 1/2*F(2))   twiddles for Hartley transform
#F
Class(RCDiag, BaseMat, rec(
    dims := self >> Replicate(2, self.element.domain()),
    area := self >> 2*self.element.domain(),
    transpose := self >> RCDiag(FRConj(self.element), self.post),

    conjTranspose := self >> Cond(self.element.range()=TComplex,
        RCDiag(FRConj(FConj(self.element)), self.post),
        RCDiag(FRConj(self.element), self.post)),

    toAMat := self >> let(elts := self.element.tolist(), # r,i,r,i,...
        Checked(Length(elts) mod 2 = 0,
            DirectSumAMat(List([1..Length(elts)/2], x ->
                    let(r := EvalScalar(elts[2*x-1]), i := EvalScalar(elts[2*x]),
                        self.post.toAMat() * AMatMat([[r,-i],[i,r]])))))),

    toloop := self >> let(
        func := self.element, # r,i,r,i,...
        j    := Ind(idiv(func.domain(),2)),
        re   := func.at(2*j),
        im   := func.at(2*j+1),
        IDirSum(j, j.range,
                self.post * Mat([[re, -im],
                                 [im,  re]]))),

    abbrevs := [
        () -> Error("Usage: \n  RCDiag(<diagfunc>, <2x2 spl>)\n",
                    "  RCDiag(<diagfunc>)\n",
                    "  RCDiag(<e0>, <e1>, ...)\n"),
        (L)    -> Checked(IsList(L) or IsFunction(L), [L, I(2)]),
        (L, P) -> Checked(IsList(L) or IsFunction(L), IsSPL(P), [L, P])
    ],

    new := meth(self, L, P)
        local inline, res;
        if IsList(L) then L := FList(L);
        elif not IsRec(L) or not IsBound(L.lambda) then
            Error("List of numbers or LambdaList expected");
        fi;
        res := SPL(WithBases(self, rec(element := L, post := P, TType := L.range())));
        res.dimensions := res.dims();
        return res;
    end,

    isReal := self >> self.element.range() <> TComplex and self.post.isReal(),
    rChildren := self >> [self.element, self.post],
    rSetChild := rSetChildFields("element", "post"),

    normalizedArithCost := self >> 0,
));

# Won't work for now because divisions by zero need to be handled.
# Declare(RCDiagLiftingSteps);
#
# #F RCDiagLiftingSteps(<diagfunc>)
# #F RCDiagLiftingSteps(<diagfunc>, <2x2 spl>)
# #F
# #F  Complex diagonal operating on real data in (r,i) format.
# #F  Represents a block diagonal with 2x2 blocks (complex rotations),
# #F  with post-processing matrix <post-spl> applied to each block.
# #F
# #F  Example: RCDiagLiftingSteps(T(8,4))   normal twiddle diagonal
# #F           RCDiagLiftingSteps(T(8,4), 1/2*F(2))   twiddles for Hartley transform
# #F
#
# Class(RCDiagLiftingSteps, BaseMat, rec(
#     dims := self >> Replicate(2, self.element.domain()),
#
#     transpose := self >> RCDiagLiftingSteps(FRConj(self.element), self.post),
#     conjTranspose := self >> self.transpose(),
#
#     toAMat := self >> let(elts := self.element.tolist(), # r,i,r,i,...
#   Checked(Length(elts) mod 2 = 0,
#       DirectSumAMat(List([1..Length(elts)/2],
#       x -> let(r := EvalScalar(elts[2*x-1]), i := EvalScalar(elts[2*x]),
#           self.post.toAMat() * AMatMat([[r,-i],[i,r]])))))),
#
#     abbrevs := [
#   () -> Error("Usage: \n  RCDiagLiftingSteps(<diagfunc>, <2x2 spl>)\n",
#          "  RCDiagLiftingSteps(<diagfunc>)\n",
#          "  RCDiagLiftingSteps(<e0>, <e1>, ...)\n"),
#   (L)    -> Checked(IsList(L) or IsFunction(L), [L, I(2)]),
#   (L, P) -> Checked(IsList(L) or IsFunction(L), IsSPL(P), [L, P])
#     ],
#
#     new := meth(self, L, P)
#         local inline, res;
#         if IsList(L) then L := FList(L);
#   elif not IsRec(L) or not IsBound(L.lambda) then
#       Error("List of numbers or LambdaList expected");
#   fi;
#   inline := IsBound(L.inline) and L.inline;
#         res := SPL(WithBases(self, rec(element := L, post := P, inline := inline)));
#   res.dimensions := res.dims();
#   return res;
#     end,
#
#     isReal := True,
#     rChildren := self >> [self.element, self.post],
#     rSetChild := rSetChildFields("element", "post"),
#     print := (self, i, is) >> Print(self.name, "(", self.element,
#         When(ObjId(self.post)<>I, Print(", ", self.post)), ")")
# ));


text:
for i in [1, 3 .. 11] do
    Print(i, "\n");
od;

1
3
5
7
9
11

ext: gap

max_issues_repo_name: seanwallawalla-forks/RosettaCodeData

max_forks_repo_name: seanwallawalla-forks/RosettaCodeData


text:
NextPermutation := function(a)
   local i, j, k, n, t;
   n := Length(a);
   i := n - 1;
   while i > 0 and a[i] > a[i + 1] do
      i := i - 1;
   od;
   j := i + 1;
   k := n;
   while j < k do
      t := a[j];
      a[j] := a[k];
      a[k] := t;
      j := j + 1;
      k := k - 1;
   od;
   if i = 0 then
      return false;
   else
      j := i + 1;
      while a[j] < a[i] do
         j := j + 1;
      od;
      t := a[i];
      a[i] := a[j];
      a[j] := t;
      return true;
   fi;
end;

Permutations := function(n)
   local a, L;
   a := List([1 .. n], x -> x);
   L := [ ];
   repeat
      Add(L, ShallowCopy(a));
   until not NextPermutation(a);
   return L;
end;

Permutations(3);
[ [ 1, 2, 3 ], [ 1, 3, 2 ],
  [ 2, 1, 3 ], [ 2, 3, 1 ],
  [ 3, 1, 2 ], [ 3, 2, 1 ] ]


text:
# Copyright (c) 2018-2021, Carnegie Mellon University
# See LICENSE for details

# RuleStrategy := [
#     RulesSums, RulesFuncSimp, RulesGMonTensorPullOut, RulesFuncSimp,
#     RulesGMonToSGMon, RulesFuncSimp,
#     RulesSGMonTensorPullIn, RulesSums, RulesFuncSimp
# ];

StandardSumsRules := MergedRuleSet(
    RulesSums, RulesFuncSimp, RulesDiag, RulesDiagStandalone, RulesStrengthReduce, RulesRC, RulesII, OLRules
);

StandardSumsRulesNoRC := MergedRuleSet(
    RulesSums, RulesFuncSimp, RulesDiag, RulesDiagStandalone, RulesStrengthReduce, RulesII, OLRules
);

HfuncSumsRules := MergedRuleSet(
    StandardSumsRules, RulesHfunc
);

LibStrategy := [ StandardSumsRules, HfuncSumsRules ];

# HasRM := e -> ObjId(e) in [Gath, Scat] and e.func.range() > 16 and
#               Collect(e.func, @(1,RM,e->e.range()>16)) <> [];

# PrecomputeRM := s -> SubstBottomUp(s, @.cond(HasRM), e->ObjId(e)(GenerateData(e.func)));

#F RecompileStrategies(<opts>)
#F
RecompileStrategies := function(opts)
    local fld, lst, rset;
    for fld in UserRecFields(opts.formulaStrategies) do
        lst := opts.formulaStrategies.(fld);
        if not IsList(lst) then lst := [lst]; fi;
        for rset in lst do
            if IsRec(rset) and IsBound(rset.compile) then rset.compile(); fi;
        od;
    od;
end;


text:
--
-- The Java KeyWord Lexer
--
%Options fp=JavaKWLexer,states
%options template=KeywordTemplateF.gi

%Include
    KWLexerMapF.gi
%End

%Export
    abstract
    assert
    boolean
    break
    byte
    case
    catch
    char
    class
    const
    continue
    default
    do
    double
    enum
    else
    extends
    false
    final
    finally
    float
    for
    goto
    if
    implements
    import
    instanceof
    int
    interface
    long
    native
    new
    null
    package
    private
    protected
    public
    return
    short
    static
    strictfp
    super
    switch
    synchronized
    this
    throw
    throws
    transient
    true
    try
    void
    volatile
    while

    BeginAction
    BeginJava
    EndAction
    EndJava
    NoAction
    NullAction
    BadAction
%End

%Terminals
    a    b    c    d    e    f    g    h    i    j    k    l    m
    n    o    p    q    r    s    t    u    v    w    x    y    z
%End

%Start
    KeyWord
%End

%Notice
/.
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2007 IBM Corporation.
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
//
//Contributors:
//    Philippe Charles (pcharles@us.ibm.com) - initial API and implementation

////////////////////////////////////////////////////////////////////////////////
./
%End
%Globals
    /.
#include "$sym_type.h"
#include "$prs_type.h"
    ./
%End
%Rules

    -- The Goal for the parser is a single Keyword

    KeyWord ::= a b s t r a c t
        /.$BeginAction
            $setResult($_abstract);
          $EndAction
        ./

              | a s s e r t
        /.$BeginAction
            $setResult($_assert);
          $EndAction
        ./

              | b o o l e a n
        /.$BeginAction
            $setResult($_boolean);
          $EndAction
        ./

              | b r e a k
        /.$BeginAction
            $setResult($_break);
          $EndAction
        ./

              | b y t e
        /.$BeginAction
            $setResult($_byte);
          $EndAction
        ./

              | c a s e
        /.$BeginAction
            $setResult($_case);
          $EndAction
        ./

              | c a t c h
        /.$BeginAction
            $setResult($_catch);
          $EndAction
        ./

              | c h a r
        /.$BeginAction
            $setResult($_char);
          $EndAction
        ./

              | c l a s s
        /.$BeginAction
            $setResult($_class);
          $EndAction
        ./

              | c o n s t
        /.$BeginAction
            $setResult($_const);
          $EndAction
        ./

              | c o n t i n u e
        /.$BeginAction
            $setResult($_continue);
          $EndAction
        ./

              | d e f a u l t
        /.$BeginAction
            $setResult($_default);
          $EndAction
        ./

              | d o
        /.$BeginAction
            $setResult($_do);
          $EndAction
        ./

              | d o u b l e
        /.$BeginAction
            $setResult($_double);
          $EndAction
        ./

              | e l s e
        /.$BeginAction
            $setResult($_else);
          $EndAction
        ./

              | e n u m
        /.$BeginAction
            $setResult($_enum);
          $EndAction
        ./

              | e x t e n d s
        /.$BeginAction
            $setResult($_extends);
          $EndAction
        ./

              | f a l s e
        /.$BeginAction
            $setResult($_false);
          $EndAction
        ./

              | f i n a l
        /.$BeginAction
            $setResult($_final);
          $EndAction
        ./

              | f i n a l l y
        /.$BeginAction
            $setResult($_finally);
          $EndAction
        ./

              | f l o a t
        /.$BeginAction
            $setResult($_float);
          $EndAction
        ./

              | f o r
        /.$BeginAction
            $setResult($_for);
          $EndAction
        ./

              | g o t o
        /.$BeginAction
            $setResult($_goto);
          $EndAction
        ./

              | i f
        /.$BeginAction
            $setResult($_if);
          $EndAction
        ./

              | i m p l e m e n t s
        /.$BeginAction
            $setResult($_implements);
          $EndAction
        ./

              | i m p o r t
        /.$BeginAction
            $setResult($_import);
          $EndAction
        ./

              | i n s t a n c e o f
        /.$BeginAction
            $setResult($_instanceof);
          $EndAction
        ./

              | i n t
        /.$BeginAction
            $setResult($_int);
          $EndAction
        ./

              | i n t e r f a c e
        /.$BeginAction
            $setResult($_interface);
          $EndAction
        ./

              | l o n g
        /.$BeginAction
            $setResult($_long);
          $EndAction
        ./

              | n a t i v e
        /.$BeginAction
            $setResult($_native);
          $EndAction
        ./

              | n e w
        /.$BeginAction
            $setResult($_new);
          $EndAction
        ./

              | n u l l
        /.$BeginAction
            $setResult($_null);
          $EndAction
        ./

              | p a c k a g e
        /.$BeginAction
            $setResult($_package);
          $EndAction
        ./

              | p r i v a t e
        /.$BeginAction
            $setResult($_private);
          $EndAction
        ./

              | p r o t e c t e d
        /.$BeginAction
            $setResult($_protected);
          $EndAction
        ./

              | p u b l i c
        /.$BeginAction
            $setResult($_public);
          $EndAction
        ./

              | r e t u r n
        /.$BeginAction
            $setResult($_return);
          $EndAction
        ./

              | s h o r t
        /.$BeginAction
            $setResult($_short);
          $EndAction
        ./

              | s t a t i c
        /.$BeginAction
            $setResult($_static);
          $EndAction
        ./

              | s t r i c t f p
        /.$BeginAction
            $setResult($_strictfp);
          $EndAction
        ./

              | s u p e r
        /.$BeginAction
            $setResult($_super);
          $EndAction
        ./

              | s w i t c h
        /.$BeginAction
            $setResult($_switch);
          $EndAction
        ./

              | s y n c h r o n i z e d
        /.$BeginAction
            $setResult($_synchronized);
          $EndAction
        ./

              | t h i s
        /.$BeginAction
            $setResult($_this);
          $EndAction
        ./

              | t h r o w
        /.$BeginAction
            $setResult($_throw);
          $EndAction
        ./

              | t h r o w s
        /.$BeginAction
            $setResult($_throws);
          $EndAction
        ./

              | t r a n s i e n t
        /.$BeginAction
            $setResult($_transient);
          $EndAction
        ./

              | t r u e
        /.$BeginAction
            $setResult($_true);
          $EndAction
        ./

              | t r y
        /.$BeginAction
            $setResult($_try);
          $EndAction
        ./

              | v o i d
        /.$BeginAction
            $setResult($_void);
          $EndAction
        ./

              | v o l a t i l e
        /.$BeginAction
            $setResult($_volatile);
          $EndAction
        ./

              | w h i l e
        /.$BeginAction
            $setResult($_while);
          $EndAction
        ./

    KeyWord ::= '$' bB eE gG iI nN aA cC tT iI oO nN
        /.$BeginAction
            $setResult($_BeginAction);
          $EndAction
        ./
              | '$' bB eE gG iI nN jJ aA vV aA
        /.$BeginAction
            $setResult($_BeginJava);
          $EndAction
        ./

    KeyWord ::= '$' eE nN dD aA cC tT iI oO nN
        /.$BeginAction
            $setResult($_EndAction);
          $EndAction
        ./
              | '$' eE nN dD jJ aA vV aA
        /.$BeginAction
            $setResult($_EndJava);
          $EndAction
        ./

    KeyWord ::= '$' nN oO aA cC tT iI oO nN
        /.$BeginAction
            $setResult($_NoAction);
          $EndAction
        ./
    KeyWord ::= '$' nN uU lL lL aA cC tT iI oO nN
        /.$BeginAction
            $setResult($_NullAction);
          $EndAction
        ./
    KeyWord ::= '$' bB aA dD aA cC tT iI oO nN
        /.$BeginAction
            $setResult($_BadAction);
          $EndAction
        ./

    aA -> a | A
    bB -> b | B
    cC -> c | C
    dD -> d | D
    eE -> e | E
    gG -> g | G
    iI -> i | I
    jJ -> j | J
    lL -> l | L
    nN -> n | N
    oO -> o | O
    tT -> t | T
    uU -> u | U
    vV -> v | V
%End

max_stars_repo_name: kuafuwang/LPGRuntimeCpp

max_issues_repo_name: kuafuwang/LPGRuntimeCpp

max_forks_repo_name: kuafuwang/LPGRuntimeCpp


text:
# phpstorm project files
.idea

# netbeans project files
nbproject

# zend studio for eclipse project files
.buildpath
.project
.settings

# sublime text project / workspace files
*.sublime-project
*.sublime-workspace

# windows thumbnail cache
Thumbs.db

# composer vendor dir
/vendor
# cubrid install dir
/cubrid

# composer itself is not needed
composer.phar

# composer.lock in applications is ignored since it's automatically created by composer when application is installed
/apps/*/composer.lock

# Mac DS_Store Files
.DS_Store

# phpunit itself is not needed
phpunit.phar
# local phpunit config
/phpunit.xml

# ignore dev installed apps and extensions
/apps
/extensions

# NPM packages
/node_modules

max_stars_repo_path: .gi

max_issues_repo_path: .gi

max_forks_repo_path: .gi


text:
## recursive implementation

fibonacci_rec := function( n )

  if n = 1 or n = 2 then

      return 1;

  fi;

  return fibonacci_rec( n - 1 ) + fibonacci_rec( n - 2 );

end;

## iterative implementation

fibonacci_iterative := function( n )
  local prev, prev2, curr_fib;

  if n = 1 or n = 2 then

      return 1;

  fi;

  prev := 1;

  prev2 := 1;

  while n > 2 do

      curr_fib := prev + prev2;

      prev2 := prev;

      prev := curr_fib;

      n := n - 1;

  od;

  return curr_fib;

end;

## using the internal function

fibonacci_internal := i -> Fibonacci( i );

## fibonacci iterator

fibonacci_iterator := function( )
  local previous_list;

  previous_list := [ 1, 1 ];

  return function( )
    local ret_val, tmp_val;

    ret_val := previous_list[ 1 ];

    tmp_val := previous_list[ 1 ] + previous_list[ 2 ];

    previous_list[ 1 ] := previous_list[ 2 ];

    previous_list[ 2 ] := tmp_val;

    return ret_val;

  end;

end;

max_stars_repo_name: Mynogs/Algorithm-Implementations

max_issues_repo_name: Mynogs/Algorithm-Implementations

max_forks_repo_name: Mynogs/Algorithm-Implementations


text:
# Copyright (c) 2018-2021, Carnegie Mellon University
# See LICENSE for details

Declare(DirectSum);
# ==========================================================================
# DirectSum
# ==========================================================================
Class(DirectSum, BaseOperation, rec(
    _spl_name := "direct_sum",

    abbrevs := [ arg ->
    [ Filtered(
        Flat(List(Flat(arg),
            s -> When(IsSPL(s) and ObjId(s)=DirectSum, s.children(), s))), x->x.dimensions<>[0,0]) ]
    ],

    new := meth(self, L)
        #ForAll(L, x -> Constraint(IsSPL(x)));
    if ForAll(L, IsIdentitySPL)
        then return I(Sum(L, Rows));
    else
        return SPL(WithBases( self,
        rec( _children := L,
        dimensions := [ Sum(L, t -> t.dimensions[1]),
                        Sum(L, t -> t.dimensions[2]) ] )));
    fi;
    end,
    #-----------------------------------------------------------------------
    dims := self >> [ Sum(self._children, t -> t.dimensions[1]),
                  Sum(self._children, t -> t.dimensions[2]) ],
    area := self >> Sum(self._children, t -> t.area()),
    #-----------------------------------------------------------------------
    isPermutation := self >> ForAll(self._children, IsPermutationSPL),
    #-----------------------------------------------------------------------
    toAMat := self >> DirectSumAMat(List(self._children, AMatSPL)),
    #-----------------------------------------------------------------------
    transpose := self >> CopyFields(self, rec(
        _children := List(self._children, x->x.transpose()),
        dimensions := Reversed(self.dimensions))),
    conjTranspose := self >> CopyFields(self, rec(
        _children := List(self._children, x->x.conjTranspose()),
        dimensions := Reversed(self.dimensions))),
    inverse := self >> CopyFields(self, rec(
        _children := List(self._children, x->x.inverse()),
        dimensions := Reversed(self.dimensions))),
    #-----------------------------------------------------------------------
    arithmeticCost := (self, costMul, costAddMul) >>
        Sum(List(self.children(), x -> x.arithmeticCost(costMul, costAddMul)))
));

Class(DelayedDirectSum, DirectSum, rec(sums := self >> self));


text:
# Copyright (c) 2018-2021, Carnegie Mellon University
# See LICENSE for details

Import(search);

#   These functions merge multiple hashtables into a single one
AllHashEntries := function(table)
    local e, i, res;
    res := [];
    for e in Filtered(table.entries, IsList) do
        for i in e do
            if i.data <> [] then Add(res, i); fi;
        od;
    od;
    return res;
end;

AddMergedHashTables := function(target, newhashs)
    local e, v, h, i;
    for e in Flat(List(newhashs, i->AllHashEntries(i))) do
        v := [];
        for h in newhashs do
            Add(v, HashLookup(h, e.key));
        od;
        v := Filtered(v, i -> i <> [] and i <> false);
        if v <> [] then
            Sort(v, (j,k) -> j[1].measured < k[1].measured);
            HashAdd(target, e.key, v[1]);
        fi;
    od;
end;

#   Build all base cases for a given SIMD ISA.
#   Currently only L(2v, 2), L(2v, v), L(v^2, v)
#
SIMD_ISA_DB.buildBases := meth(self, isa)
    local rebind, t, v, tags, cxtags, t1, t2, rt, brules, common, rset1, rset2, tab1, tab2, e, h;

    if self.verbose then Print("Building bases for ", isa, "\n"); fi;
    self.hash_rebuilt := true;
    v := isa.v;
    tags := isa.getTags();
    cxtags := isa.getTagsCx();

    # == do TL base cases======================================
    # TL usually is not measured in DP
    rebind := IsBound(TL.doNotMeasure) and TL.doNotMeasure;
    if rebind then
        TL.doNotMeasure := false;
    fi;

    brules := paradigms.tSPL_Globals.getDPOpts().breakdownRules;
    common := [ SIMD_ISA_Bases1, SIMD_ISA_Bases2, IxLxI_kmn_n, IxLxI_kmn_km, paradigms.vector.breakdown.IxLxI_vtensor ];

    rset1 := CopyFields(brules, rec(TL := Concat(common, [IxLxI_IxLxI_up])));
    rset2 := CopyFields(brules, rec(TL := Concat(common, [IxLxI_IxLxI_down])));

    tab1 := HashTableDP();
    for t in SIMD_ISA_DB.getBases(isa) do
#    [ TL(2*v,v,1,1).withTags(tags), TL(2*v,2,1,1).withTags(tags), TL(v*v,v,1,1).withTags(tags), TL(v*v/4,v/2,1,2).withTags(tags) ]
        t1 := DP(t, rec(measureFunction := VCost, verbosity := 0, hashTable := tab1, globalUnrolling := true),
                CopyFields(isa.splopts, rec(breakdownRules := rset1, dataType := "no default", baseHashes := [], globalUnrolling := 10000)));
    od;

    tab2 := HashTableDP();
    for t in SIMD_ISA_DB.getBases(isa) do
#    [ TL(2*v,v,1,1).withTags(tags), TL(2*v,2,1,1).withTags(tags), TL(v*v,v,1,1).withTags(tags), TL(v*v/4,v/2,1,2).withTags(tags) ]
        t2 := DP(t, rec(measureFunction := VCost, verbosity := 0, hashTable := tab2, globalUnrolling := false),
                CopyFields(isa.splopts, rec(breakdownRules := rset2, dataType := "no default", baseHashes := [], globalUnrolling := 10000)));
    od;
    AddMergedHashTables(self.hash, [tab1, tab2]);
    # restore TL
    if rebind then
        TL.doNotMeasure:=true;
    fi;

    # == do other base cases===================================
    # do other base cases
    #
    # none here yet :(
    #

    # == final check - did all work? ==========================
    for e in self.getBases(isa) do
        h := HashLookup(self.hash, e);
        if  h=false or h=[] then Print(e, " could not be built\n"); fi;
    od;
end;


text:
# The Hamming graph H(d, e) of vectors with d elements
# over an alphabet with e elements.
BindGlobal("HammingGraph", function(d, e)
    return Graph(WreathProductSymmetricGroups(e, d),
        Elements(ZmodnZ(e)^d), OnZmodnZVectors(d, e),
        function(x, y) return WeightVecFFE(x-y) = 1; end, true);
end);

# The d-dimensional hypercube
BindGlobal("HypercubeGraph", d -> HammingGraph(d, 2));

# The Shrikhande graph with parameters v = 16, k = 6, lm = 2, mu = 2,
# i.e., the same as H(2, 4), but not isomorphic to it.
BindGlobal("ShrikhandeGraph",
    ComplementGraph(LatinSquareGraph(CyclicGroup(4))));

# The Doob graph Doob(n, d) of diameter 2*n+d
# as a box product of n copies of the Shrikhande graph and H(d, 4).
BindGlobal("DoobGraph", function(n, d)
    local l;
    l := ListWithIdenticalEntries(n, ShrikhandeGraph);
    if d > 0 then
        Add(l, HammingGraph(d, 4));
    fi;
    return BoxProductGraph(l);
end);

# The halved d-cube.
BindGlobal("HalvedCubeGraph",
    d -> HalvedGraph(HammingGraph(d, 2))
);

# The folded d-cube.
BindGlobal("FoldedCubeGraph",
    d -> AntipodalQuotientGraph(HammingGraph(d, 2))
);

# The folded halved 2d-cube.
BindGlobal("FoldedHalvedCubeGraph",
    d -> AntipodalQuotientGraph(HalvedGraph(HammingGraph(2*d, 2)))
);

# The Brouwer graph Br(q) of pairs of 3-dimensional vectors over F_q,
# with two pairs being adjacent whenever the difference of the first vectors
# equals the cross product of the second vectors.
BindGlobal("BrouwerGraph", function(q)
    return Graph(WreathProduct(FieldAdditionPermutationGroup(q),
            MatrixColumnEvenPermutationGroup(2, 3)), Elements(GF(q)^[2,3]),
        OnVectorPairs(q), function(x, y)
            return x <> y and x[1] - y[1] = VectorProduct(x[2], y[2]);
        end, true);
end);

# The Pasechnik graph Pa(q) as the extended bipartite double
# of the Brouwer graph Br(q).
BindGlobal("PasechnikGraph",
    q -> ExtendedBipartiteDoubleGraph(BrouwerGraph(q))
);

# The additive symplectic cover of the complete graph on q^{2n} vertices.
BindGlobal("AdditiveSymplecticCoverGraph", function(arg)
    local B, F, G, K, V, h, m, q, dp;
    if Length(arg) < 2 then
        Error("at least two arguments expected");
        return fail;
    fi;
    if Length(arg) > 2 then
        h := arg[3];
    else
        h := 0;
    fi;
    q := arg[1];
    F := GF(q);
    m := 2*arg[2];
    G := Sp(m, q);
    V := F^m;
    B := InvariantBilinearForm(G).matrix;
    dp := DirectProduct(Concatenation([G],
        ListWithIdenticalEntries(m+1, FieldAdditionPermutationGroup(q))));
    if h = 0 then
        K := AdditiveGroup(0*Z(q));
    else
        K := AdditiveGroup(BasisVectors(Basis(F)){[1..h]});
    fi;
    return Graph(dp, Cartesian(Unique(List(F, x -> x+K)), V),
        OnAdditiveSymplecticCover(q, m, B, dp),
        function(x, y)
            return x <> y and x[2]*B*y[2]+y[1]-Elements(x[1])[1] = K;
        end, true);
end);

# The multiplicative symplectic cover of the complete graph on q+1 vertices.
# It is distance-regular when m divides q-1 and either q or m is even.
BindGlobal("MultiplicativeSymplecticCoverGraph", function(q, m)
    local B, F, G, K, dp;
    F := GF(q);
    K := Group(Z(q)^((q-1)/m));
    G := Sp(2, q);
    B := InvariantBilinearForm(G).matrix;
    dp := DirectProduct(G, Group((1,2)),
                        FieldExponentiationPermutationGroup(q));
    return Graph(dp, Unique(List(Filtered(F^2, x -> x <> Zero(F^2)),
                                 v -> Set(List(K, g -> List(v, x -> g*x))))),
                 OnMultiplicativeSymplecticCover(q, dp), function(x, y)
                    return x <> y and x[1]*B*y[1] in K;
                 end, true);
end);

# The affine polar graph VO^{(+/-)}(d, q)
# with respect to a nondegenerate quadratic form.
BindGlobal("AffinePolarGraphVO", function(arg)
    local d, e, q, B, G, Q, V, dp;
    if Length(arg) < 2 then
        Error("at least two arguments expected");
        return fail;
    elif Length(arg) = 2 then
        e := 0;
        d := arg[1];
        q := arg[2];
    else
        e := arg[1];
        d := arg[2];
        q := arg[3];
    fi;
    G := GO(e, d, q);
    dp := DirectProduct(Concatenation([G],
            ListWithIdenticalEntries(d, FieldAdditionPermutationGroup(q))));
    Q := InvariantQuadraticForm(G).matrix;
    return Graph(dp, Elements(GF(q)^d), OnAffine(q, d, dp), function(x, y)
                    return x <> y and IsZero((x-y)*Q*(x-y));
                end, true);
end);

# The affine polar graph VNO^{(+/-)}(d, q)
# with respect to a nondegenerate quadratic form.
BindGlobal("AffinePolarGraphVNO", function(arg)
    local d, e, q, B, G, H, Q, V, dp;
    if Length(arg) < 2 then
        Error("at least two arguments expected");
        return fail;
    elif Length(arg) = 2 then
        e := 0;
        d := arg[1];
        q := arg[2];
    else
        e := arg[1];
        d := arg[2];
        q := arg[3];
    fi;
    G := GO(e, d, q);
    dp := DirectProduct(Concatenation([G],
            ListWithIdenticalEntries(d, FieldAdditionPermutationGroup(q))));
    Q := InvariantQuadraticForm(G).matrix;
    return Graph(dp, Elements(GF(q)^d), OnAffine(q, d, dp),
                function(x, y)
                    return x <> y and IsOne(((x-y)*Q*(x-y))^((q-1)/2));
                end, true);
end);

max_stars_repo_name: jaanos/gap-graphs

max_issues_repo_name: jaanos/gap-graphs

max_forks_repo_name: jaanos/gap-graphs


text:
# Copyright (c) 2018-2021, Carnegie Mellon University
# See LICENSE for details

#---------------------------------------------------------------------------------------
#   altivec vector instructions
#---------------------------------------------------------------------------------------

#Class(vbinop_4x32f_av, vbinop_av, rec( v := self >> 4));

#Class(exp_4x32f, rec(v := 4, computeType := self >> TVect(TDouble, 4)));

#Class(cmd_4x32f, rec(v := 4, computeType := self >> TVect(TDouble, 4)));

# Load -----------------------------

# Store ----------------------------

# Zero -----------------------------
# use data_type.zero() instead of special class
# Class(vzero_4x32f, vop_av, exp_4x32f, rec(numargs := 0));

# Subvec ---------------------------

# Binary ---------------------------
# Class(bin_or, vbinop_new, exp_4x32f);

# Rotates ---------------------------

# Binary shuffle -------------------

#Class(vperm_4x32f_spu, vbinop_4x32f_spu, rec(
#    semantic := (in1, in2, p) -> vpermop(in1, in2, p, 4),
#    params := self >> sparams(4, 8),
#    permparams := aperm
#));

# Unary shuffle --------------------
#Class(vuperm_4x32f_spu, vunbinop_spu, rec(binop := vperm_4x32f_spu));


text:
# This is a rather basic helper function to do
# completion. It is related to the completion
# function provided in lib/cmdledit.g in the GAP
# distribution
InstallGlobalFunction(JUPYTER_Complete,
function(code, cursor_pos)
    local default, cand, i, matches, tokens, tok;

    default := rec( matches := [], cursor_start := 0,
                    cursor_end := cursor_pos, metadata := rec(),
                    status := "ok" );

    code := code{[1..cursor_pos]};
    if Length(code) = 0 then
        return default;
    fi;
    tokens := SplitString(code, "():=<>,.[]?-+*/; ");

    if tokens = [] then
        return default;
    fi;

    tok := tokens[Length(tokens)];
    cand := IDENTS_BOUND_GVARS();
    matches := Filtered(cand, i -> PositionSublist(i, tok) = 1);
    SortBy(matches, Length);
    return rec( matches := matches
              , cursor_start := cursor_pos - Length(tok)
              , cursor_end := cursor_pos
              , metadata := rec()
              , status := "ok" );
end);

max_stars_repo_name: ZachNewbery/JupyterKernel

max_issues_repo_name: ZachNewbery/JupyterKernel

max_forks_repo_name: ZachNewbery/JupyterKernel


text:
_diceIt := (k,d) -> let(fct := Factors(k), l := Length(fct), lx:= Replicate(d-1, Int(l/d)), ll := l-Sum(lx), prt := lx::[ll],
    pfx := [0]::List([1..d], i -> Sum(prt{[1..i]})), prtl := List([1..d], i->Product(fct{[pfx[i]+1..pfx[i+1]]})),
    Reversed(prtl));

NewRulesFor(MDDFT, rec(
    MDDFT_tSPL_pencil := rec(

        applicable := (self, t) >> Length(t.params[1]) > 1 and let(tg := t.getTags()[1], IsBound(tg.isParMPI) and tg.isParMPI),

        children := nt -> [let(tags := nt.getTags(), dd := Length(tags), peelof := Product(nt.getTags()[1].params[1]),
                              pencils := List([1..Length(nt.params)], d -> TMap(DFT(nt.params[1][d], nt.params[2]),
                                  [peelof]::_diceIt(Product(nt.params[1]{[1..d-1]}::nt.params[1]{[d+1..Length(nt.params[1])]})/peelof, dd-1), APar, APar).withTags(nt.getTags())),
                              perms := List([1..Length(nt.params)], d -> TPrm(fCubeTranspose(Product(nt.params[1]), d, nt.params[1]))),
                              DropLast(Flat(Zip2(pencils, perms)), 1)
                           )],

        apply := (t, C, Nonterms) -> Compose(C),
        switch := true
    ),
    MDDFT_tSPL_pencil_cuFFT_MPI := rec(

        applicable := (self, t) >> Length(t.params[1]) > 1 and let(tg := t.getTags()[1], IsBound(tg.isParMPI) and tg.isParMPI),

        children := nt -> [[ TCompose([
                                TTensorII(DFT(nt.params[1][3], nt.params[2]), nt.params[1]{[1,2]}, ACubeRot_ZXY, ACubeRot_XYZ),
                                TPrm(fCubeTranspose(Product(nt.params[1]), "FFTX_MPI_3D_CUFFT_STAGE1", nt.params[1])),
                                TTensorII(DFT(nt.params[1][2], nt.params[2]), nt.params[1]{[1,3]}, ACubeRot_ZXY, ACubeRot_XYZ),
                                TPrm(fCubeTranspose(Product(nt.params[1]), "FFTX_MPI_3D_CUFFT_STAGE2", nt.params[1])),
                                TTensorII(DFT(nt.params[1][1], nt.params[2]), nt.params[1]{[2,3]}, ACubeRot_ZXY, ACubeRot_XYZ)
                            ]).withTags(nt.getTags()) ]],

        apply := (t, C, Nonterms) -> C[1],
        switch := true
    )
));

NewRulesFor(TPrm, rec(
    TPrm_MPI := rec(
        forTransposition := false,
        children := nt -> [[  ]],
        apply := (nt, c, cnt) -> NoPull(MPIPrm(nt.params[1]))
    )
));

NewRulesFor(TTensorI, rec(
    IxA_MPI := rec(
        info := "IxA base",
        forTransposition := false,
        applicable := nt -> nt.hasTags() and let(tg := nt.getTags()[1], IsBound(tg.isParMPI) and tg.isParMPI) and IsParPar(nt.params),
        children := nt -> [[ nt.params[1].withTags(Drop(nt.getTags(), 1)) ]],
        apply := (nt, c, cnt) ->  MPITensor(c[1], nt.params[2])
    )
));

NewRulesFor(TTensorII, rec(
    batch_cuFFT_cuberot_3D := rec(
        info := "IxA base",
        forTransposition := false,
        applicable := nt -> nt.hasTags() and let(tg := nt.getTags()[1], IsBound(tg.isParMPI) and tg.isParMPI) and
            nt.params[3] = ACubeRot_ZXY and nt.params[4] = ACubeRot_XYZ and
            ObjId(nt.params[1]) = DFT,
        children := nt -> [[ ]],
        apply := (nt, c, cnt) ->  let(K := nt.params[1].params[1], k := nt.params[1].params[2], M := nt.params[2][1], N := nt.params[2][2],
                                      pg := nt.getTags()[1].params[1], p1 := pg[1], p2 := pg[2],
            MPITensor(
                CUFFTCall(
#                    Tensor(L(N*M/p1, M/p1), I(K/p2)) * Tensor(I(N), L(M*K/(p1*p2), M/p1)) * Tensor(I(p1*p2), DFT(K, k)), # this formula is only an approximation
                    TTensorII(nt.params[1], List([1..2], i-> nt.params[2][i]/nt.getTags()[1].params[1][i]), ACubeRot_ZXY, ACubeRot_XYZ),
                    rec(K := K, M := M, N := N, p1 := p1, p2 := p2, k := k)),
                Product(pg)))
    )
));

max_stars_repo_name: spiral-software/spiral-package-mpi

max_issues_repo_name: spiral-software/spiral-package-mpi

max_forks_repo_name: spiral-software/spiral-package-mpi


text:
FixedPartitions := function(arg)
	local aux;
	aux := function(i, u)
		local r, v, w;
		if i = Size(arg) then
			return [[u]];
		else
			r := [ ];
			for v in Combinations(u, arg[i]) do
				for w in aux(i + 1, Difference(u, v)) do
					Add(r, Concatenation([v], w));
				od;
			od;
			return r;
		fi;
	end;
	return aux(1, [1 .. Sum(arg)]);
end;

FixedPartitions(2, 0, 2);
# [ [ [ 1, 2 ], [  ], [ 3, 4 ] ], [ [ 1, 3 ], [  ], [ 2, 4 ] ],
#   [ [ 1, 4 ], [  ], [ 2, 3 ] ], [ [ 2, 3 ], [  ], [ 1, 4 ] ],
#   [ [ 2, 4 ], [  ], [ 1, 3 ] ], [ [ 3, 4 ], [  ], [ 1, 2 ] ] ]

FixedPartitions(1, 1, 1);
# [ [ [ 1 ], [ 2 ], [ 3 ] ], [ [ 1 ], [ 3 ], [ 2 ] ], [ [ 2 ], [ 1 ], [ 3 ] ],
#   [ [ 2 ], [ 3 ], [ 1 ] ], [ [ 3 ], [ 1 ], [ 2 ] ], [ [ 3 ], [ 2 ], [ 1 ] ] ]

max_stars_repo_name: mullikine/RosettaCodeData