Beispiel #1
0
    def split(self, assets: bool, code: bool, debug: bool):
        import split

        modes = ["ld"]
        if assets:
            modes.extend([
                "bin", "Yay0", "img", "vtx", "pm_map_data", "pm_msg",
                "pm_npc_sprites", "pm_charset", "pm_charset_palettes",
                "pm_effect_loads", "pm_effect_shims"
            ])
        if code:
            modes.extend(["code", "c", "data", "rodata"])

        splat_file = [str(self.version_path / "splat.yaml")]
        if debug:
            splat_file += [str(self.version_path / "splat-debug.yaml")]

        split.main(
            splat_file,
            None,
            str(self.version_path / "baserom.z64"),
            modes,
            verbose=True,
        )
        self.linker_entries = split.linker_writer.entries[:]
        self.asset_stack = split.config["asset_stack"]
Beispiel #2
0
    def split(self, assets: bool, code: bool):
        import split

        modes = ["ld"]
        if assets:
            modes.extend([
                "bin", "Yay0", "img", "PaperMarioMapFS", "PaperMarioMessages",
                "PaperMarioNpcSprites"
            ])
        if code:
            modes.extend(["code", "c", "data", "rodata"])

        split.main(
            str(self.version_path / "splat.yaml"),
            None,
            str(self.version_path / "baserom.z64"),
            modes,
            verbose=False,
        )
        self.linker_entries = split.linker_writer.entries[:]
        self.asset_stack = split.config["asset_stack"]
Beispiel #3
0
def main(sfile, sz):
    # invoke: $ python demo2.py "image.png" 80
    print("splitting image ...")
    split.main(sfile, sz)
    print("splits saved!")
    out = "mz/"
    if not os.path.exists(out):
        os.makedirs(out)
    print("making mazes ...")

    pool_size = 192
    pool = Pool(pool_size)
    for file in os.listdir("split/"):
        pool.apply_async(makeMazes, (file, out))
    pool.close()
    pool.join()

    print("mazes complete!")
    print("stitching segments ...")
    stitch.main("mz/")
    print("stitching complete!")
    return
Beispiel #4
0
def main():
    num = 1
    m = int(raw_input("The number of demand:"))
    n = int(raw_input("The number of facility:"))
    hbar = int(raw_input("Quantity Limit H-bar:"))
    dbar = int(raw_input("Distance Matrix D-bar:"))
    fbar = int(raw_input("Fix Cost Limit F-bar:"))

    # run random to generate random nums
    generator.main(num, m, n, hbar, dbar, fbar)

    prelamda = np.array([100] * m)  #init lamda
    while True:
        # split the random nums and generate j subdata files
        coor = split.main(
            prelamda)  #three element: 1. demand_coor 2, supply_coor 3. hi
        # solve each submodel and save the ampl solution
        submod.main(n)
        # merge the sols
        returnitem = merge.main(m, n)  #returnitem = [Xi,Yi,Z,subgrad]
Beispiel #5
0
def main():
    split.main('webwxgetms01.gif')
    coalesce.main(' PHP ')
Beispiel #6
0
async def main():
    global n, cpp, task_sem, num_tasks, num_tasks_done

    task_sem = asyncio.Semaphore(8)

    parser = ArgumentParser(description="Paper Mario build.ninja generator")
    parser.add_argument("--cpp", help="GNU C preprocessor command")
    parser.add_argument("--baserom",
                        default="baserom.z64",
                        help="Path to unmodified Paper Mario (U) z64 ROM")
    parser.add_argument("--cflags", default="", help="Extra cc/cpp flags")
    parser.add_argument("--no-splat",
                        action="store_true",
                        help="Don't split the baserom")
    args = parser.parse_args()

    # on macOS, /usr/bin/cpp defaults to clang rather than gcc (but we need gcc's)
    if args.cpp is None and sys.platform == "darwin" and "Free Software Foundation" not in (
            await shell("cpp --version"))[0]:
        print("error: system C preprocessor is not GNU!")
        print(
            "This is a known issue on macOS - only clang's cpp is installed by default."
        )
        print(
            "Use 'brew' to obtain GNU cpp, then run this script again with the --cpp option, e.g."
        )
        print("    ./configure.py --cpp cpp-10")
        exit(1)

    # verify baserom exists and is clean
    try:
        with open(args.baserom, "rb") as f:
            h = hashlib.sha1()
            h.update(f.read())

            if h.hexdigest() != "3837f44cda784b466c9a2d99df70d77c322b97a0":
                print(
                    f"error: baserom '{args.baserom}' is modified, refusing to split it!"
                )
                print(
                    "The baserom must be an unmodified Paper Mario (U) z64 ROM."
                )
                exit(1)
    except IOError:
        print(f"error: baserom '{args.baserom}' does not exist!")
        print(
            f"Please make sure an unmodified Paper Mario (U) z64 ROM exists at '{args.baserom}'."
        )

        if args.baserom == "baserom.z64":  # the default
            print("Or run this script again with the --baserom option:")
            print("    ./configure.py --baserom /path/to/papermario.z64")
            exit(1)

    cpp = args.cpp or "cpp"
    ccache = "ccache" if cmd_exists("ccache") else ""

    if not args.no_splat:
        # compile splat dependencies
        await shell("make -C tools/splat")

        # split assets
        print("Splitting segments from baserom", end="")
        split.main(
            args.baserom,
            "tools/splat.yaml",
            ".",
            [
                "ld", "bin", "Yay0", "PaperMarioMapFS", "PaperMarioMessages",
                "img", "PaperMarioNpcSprites"
            ],
            False,
            False,
        )

        print("")

    print("Configuring build...", end="")

    # generate build.ninja
    n = ninja_syntax.Writer(open("build.ninja", "w"), width=120)

    cppflags = "-Iinclude -Isrc -D _LANGUAGE_C -D _FINALROM -ffreestanding -DF3DEX_GBI_2 -D_MIPS_SZLONG=32 " + args.cflags

    n.variable("builddir", "build")
    n.variable("target", TARGET)
    n.variable("cross", "mips-linux-gnu-")
    n.variable("python", sys.executable)

    if sys.platform == "darwin":
        os_dir = "mac"
    elif sys.platform == "linux":
        if os.uname()[4] == "aarch64":
            os_dir = "arm"
        else:
            os_dir = "linux"
    else:
        print(f"Unsupported platform {sys.platform}")
        sys.exit(1)

    n.variable("os", os_dir)
    n.variable(
        "iconv", "tools/iconv.py UTF-8 SHIFT-JIS"
        if sys.platform == "darwin" else "iconv --from UTF-8 --to SHIFT-JIS")
    n.variable("cppflags", f"{cppflags} -Wcomment")
    n.variable(
        "cflags",
        "-O2 -quiet -G 0 -mcpu=vr4300 -mfix4300 -mips3 -mgp32 -mfp32 -Wuninitialized -Wshadow "
        + args.cflags)
    n.newline()

    n.rule(
        "cc",
        command=
        f"bash -o pipefail -c '{cpp} $cppflags $in -o - | $iconv | tools/$os/cc1 $cflags -o - | tools/$os/mips-nintendo-nu64-as -EB -G 0 - -o $out'",
        description="cc $in",
        depfile="$out.d",
        deps="gcc")
    n.rule(
        "cc_dsl",
        command=
        f"bash -o pipefail -c '{cpp} $cppflags $in -o - | $python tools/compile_dsl_macros.py | $iconv | tools/$os/cc1 $cflags -o - | tools/$os/mips-nintendo-nu64-as -EB -G 0 - -o $out'",
        description="cc (with dsl) $in",
        depfile="$out.d",
        deps="gcc")
    n.newline()

    n.rule("cpp",
           command=f"{cpp} -P -DBUILD_DIR=$builddir $in -o $out",
           description="cc (with dsl) $in",
           depfile="$out.d",
           deps="gcc")
    n.newline()

    n.rule("yay0compress",
           command=f"tools/Yay0compress $in $out",
           description="compress $in")
    n.newline()

    n.rule("bin",
           command="${cross}ld -r -b binary $in -o $out",
           description="bin $in")
    n.newline()

    n.rule("as",
           command=
           "${cross}as -EB -march=vr4300 -mtune=vr4300 -Iinclude $in -o $out",
           description="assemble $in")
    n.newline()

    # $img_type, $img_flags
    n.rule(
        "img",
        command="$python tools/convert_image.py $img_type $in $out $img_flags",
        description="image $in")
    n.newline()

    # $sprite_id, $sprite_dir, $sprite_name
    n.rule(
        "sprite_animations_h",
        command=
        "$python tools/gen_sprite_animations_h.py $out $sprite_dir $sprite_id",
        description="sprite_animations_h $sprite_name ($sprite_id)")
    n.rule("npc_sprite",
           command="$python tools/compile_npc_sprite.py $out $sprite_dir",
           description="npc_sprite $sprite_name ($sprite_id)")
    n.rule("npc_sprites",
           command="$python tools/compile_npc_sprites.py $out $in",
           description="package npc sprites")
    n.newline()

    n.rule(
        "ld_addrs_h",
        command=
        "grep -E \"[^\. ]+ =\" $in -o | sed 's/^/extern void* /; s/ =/;/' > $out",
        description="ld_addrs_h $in")
    n.newline()

    # $msg_combine_headers
    n.rule(
        "msg_combine",
        command=
        "$python tools/msg/combine.py $out $in --headers $msg_combine_headers",
        description="combine messages")
    n.rule("msg",
           command="$python tools/msg/parse_compile.py $in $out",
           description="msg $in")
    n.newline()

    n.rule("assets",
           command="$python tools/build_assets_bin.py $out $in",
           description="combine assets")
    n.newline()

    n.rule(
        "link",
        command=
        "${cross}ld -T undefined_syms.txt -T undefined_syms_auto.txt -T undefined_funcs.txt -T undefined_funcs_auto.txt -Map $builddir/$target.map --no-check-sections -T $in -o $out",
        description="link $out")
    n.newline()

    n.rule("rom",
           command="${cross}objcopy $in $out -O binary && tools/n64crc $out",
           description="rom $in")
    n.newline()

    n.rule("sha1sum",
           command="sha1sum -c $in && touch $out",
           description="compare")
    n.newline()

    n.rule("cc_modern_exe", command="cc $in -O3 -o $out")
    n.newline()

    objects, segments = read_splat("tools/splat.yaml")  # no .o extensions!
    c_files = (f for f in objects
               if f.endswith(".c"))  # glob("src/**/*.c", recursive=True)

    n.comment("target")
    n.build("$builddir/$target.ld", "cpp", "$target.ld")
    n.build("$builddir/$target.elf",
            "link",
            "$builddir/$target.ld",
            implicit=[obj(o) for o in objects],
            implicit_outputs="$builddir/$target.map")
    n.build("$target.z64",
            "rom",
            "$builddir/$target.elf",
            implicit="tools/n64crc")
    n.build("$builddir/is_ok",
            "sha1sum",
            "checksum.sha1",
            implicit="$target.z64")
    n.newline()

    n.default("$builddir/is_ok")
    n.newline()

    # generated headers
    n.comment("generated headers")
    generated_headers = []

    def add_generated_header(h: str):
        generated_headers.append(h)

        if not os.path.exists(h):
            # mkdir -p
            os.makedirs(os.path.dirname(h), exist_ok=True)

            # touch it so cpp doesn't complain if its #included
            open(h, "w").close()

            # mark it as really old so ninja builds it
            os.utime(h, (0, 0))

        return h

    n.build(add_generated_header("include/ld_addrs.h"), "ld_addrs_h",
            "$builddir/$target.ld")

    # messages
    msg_files = glob("src/**/*.msg", recursive=True) + glob("msg/**/*.msg",
                                                            recursive=True)
    for msg_file in msg_files:
        n.build(
            f"$builddir/{msg_file}.bin",
            "msg",
            msg_file,
            implicit="tools/msg/parse_compile.py",
        )
    n.build("$builddir/msg.bin",
            "msg_combine",
            [f"$builddir/{msg_file}.bin" for msg_file in msg_files],
            implicit="tools/msg/combine.py",
            implicit_outputs=[
                add_generated_header(f"{msg_file}.h") for msg_file in msg_files
            ],
            variables={
                "msg_combine_headers":
                [f"{msg_file}.h" for msg_file in msg_files]
            })
    n.build("$builddir/msg.o", "bin", "$builddir/msg.bin")

    # sprites
    npc_sprite_yay0s = []
    for sprite_id, sprite_name in enumerate(NPC_SPRITES, 1):
        sources = glob(f"sprite/npc/{sprite_name}/**/*.*", recursive=True)
        variables = {
            "sprite_name": sprite_name,
            "sprite_dir": f"sprite/npc/{sprite_name}",
            "sprite_id": sprite_id,
        }

        # generated header
        n.build(
            add_generated_header(f"include/sprite/npc/{sprite_name}.h"),
            "sprite_animations_h",
            implicit=sources + ["tools/gen_sprite_animations_h.py"],
            variables=variables,
        )

        # sprite bin/yay0
        n.build(
            f"$builddir/sprite/npc/{sprite_name}",
            "npc_sprite",
            implicit=sources + ["tools/compile_npc_sprite.py"],
            variables=variables,
        )
        yay0 = f"$builddir/sprite/npc/{sprite_name}.Yay0"
        npc_sprite_yay0s.append(yay0)
        n.build(
            yay0,
            "yay0compress",
            f"$builddir/sprite/npc/{sprite_name}",
            implicit=["tools/Yay0compress"],
        )

    n.newline()

    # fast tasks
    n.comment("data")
    for f in objects:
        segment = segments[f]

        if f.endswith(".c"):
            continue  # these are handled later
        elif f.endswith(".Yay0"):
            build_yay0_file(os.path.splitext(f)[0] + ".bin")
        elif f.endswith(".bin"):
            build_bin_object(f)
        elif f.endswith(".data"):
            n.build(obj(f), "as", "asm/" + f + ".s")
        elif f.endswith(".rodata"):
            n.build(obj(f), "as", "asm/" + f[2:] + ".s")
        elif f.endswith(".s"):
            n.build(obj(f), "as", f)
        elif f.endswith(".png"):
            build_image(f, segment)
        elif f == "sprite/npc":
            # combine sprites
            n.build(f"$builddir/{f}.bin",
                    "npc_sprites",
                    npc_sprite_yay0s,
                    implicit="tools/compile_npc_sprites.py")
            n.build(obj(f), "bin", f"$builddir/{f}.bin")
        elif f == "/msg":  # XXX: why does this have a leading '/'??
            continue  # done already above
        elif f == "bin/assets/assets":
            asset_files = [
            ]  # even indexes: uncompressed; odd indexes: compressed

            for asset_name in ASSETS:
                if asset_name.endswith("_tex"):  # uncompressed
                    asset_files.append(f"bin/assets/{asset_name}.bin")
                    asset_files.append(f"bin/assets/{asset_name}.bin")
                else:  # uncompressed
                    source_file = f"bin/assets/{asset_name}.bin"
                    asset_file = f"$builddir/assets/{asset_name}.Yay0"

                    asset_files.append(source_file)
                    asset_files.append(asset_file)
                    n.build(asset_file,
                            "yay0compress",
                            source_file,
                            implicit="tools/Yay0compress")

            n.build("$builddir/assets.bin", "assets", asset_files)
            n.build(obj(f), "bin", "$builddir/assets.bin")

        else:
            print("warning: dont know what to do with object " + f)
    n.newline()

    n.build("generated_headers", "phony", generated_headers)
    n.newline()

    # slow tasks generated concurrently
    n.comment("c")
    tasks = [
        task(build_c_file(f, "generated_headers", ccache, cppflags))
        for f in c_files
    ]
    num_tasks = len(tasks)
    num_tasks_done = 0
    await asyncio.gather(*tasks)
    print("")
    n.newline()

    # c tools that need to be compiled
    n.build("tools/Yay0compress", "cc_modern_exe", "tools/Yay0compress.c")
    n.build("tools/n64crc", "cc_modern_exe", "tools/n64crc.c")
    n.newline()

    print("")
    print("Build configuration complete! Now run")
    print("    ninja")
    print(f"to compile '{TARGET}.z64'.")
Beispiel #7
0
import split
import speech_recognition as sr

# use the audio file as the audio source
r = sr.Recognizer()
with sr.Microphone() as source:
    r.adjust_for_ambient_noise(source)
    print("listening...")
    audio = r.listen("E:/song/abc.wav")  # read the entire audio file

if __name__ == '__main__':
    split.main()
    IBM_USERNAME = "******"  # IBM Speech to Text usernames are strings of the form XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
    IBM_PASSWORD = "******"  # IBM Speech to Text passwords are mixed-case alphanumeric strings
    try:
        print("IBM Speech to Text thinks you said " + r.recognize_ibm(
            audio, username=IBM_USERNAME, password=IBM_PASSWORD))
    except sr.UnknownValueError:
        print("IBM Speech to Text could not understand audio")
    except sr.RequestError as e:
        print("Could not request results from IBM Speech to Text service; {0}".
              format(e))
#!/usr/bin/python

'''
Driver script for building and evaluating vw models

'''
import os,sys
import split,vw_evaluation

#vectors with training examples and numbers of passes, can be used with a for-loop to compute training and test errors for plots
# obs = [1000, 5000,10000,20000,30000,40000,50000,60000,70000,80000,90000,100000,110000,120000,132173]
# passes = [10,20,30,40,50,60,70,80,90,100]


## Split into training and test sets
split.main('../data/working/dataset_rand.vw','../data/working/train.vw','../data/working/test.vw', 0.7, 'randy')

## Train vw model using train set (run as system cmd from python), save into file
model_cmd = "vw -d ../data/working/train.vw -f ../data/output/vw.model  -c -k --oaa 5 --bfgs --loss_function logistic --passes 30"

print 'Training:'
print model_cmd
os.system(model_cmd) 


## Predict using vw model and train and test sets, save into file
os.system("vw -i ../data/output/vw.model --testonly -d ../data/working/train.vw -p ../data/working/train_pred.txt --quiet")
os.system("vw -i ../data/output/vw.model --testonly -d ../data/working/test.vw -p ../data/working/test_pred.txt --quiet")


## Evaluate results
Beispiel #9
0
import stitch
import split
from Mask import Mask
from MaskedGrid import MaskedGrid
# from BinaryTree import BinaryTree
# from Sidewinder import Sidewinder
from RecursiveBacktracker import RecursiveBacktracker

# invoke: $ python demo2.py "image.png" 80
# "off"
sfile = sys.argv[1]
# op = sys.argv[2]
sz = int(sys.argv[2])

print("splitting image ...")
split.main(sfile, sz)
print("splits saved!")

out = "mz/"
if not os.path.exists(out):
    os.makedirs(out)

print("making mazes ...")
for file in os.listdir("split/"):
    fl = "split/%s" % file
    mask = Mask.from_png(fl)
    grid = MaskedGrid(mask)
    loc = file[:-4]
    RecursiveBacktracker.on(grid)
    # rb = "out/recursivebacktracker/%s" % loc
    img3 = grid.to_png(cell_size=8, folder=out, name=loc)