Coder Social home page Coder Social logo

Another Test Issue about librapid HOT 2 CLOSED

Pencilcaseman avatar Pencilcaseman commented on June 1, 2024
Another Test Issue

from librapid.

Comments (2)

Pencilcaseman avatar Pencilcaseman commented on June 1, 2024

This is another comment on an issue, this time with some C++ code:


View raw code

librapid::optimiseThreads(0.1);
	librapid::setNumThreads(8);
	librapid::warmup();

	{
		librapid::Array test(librapid::Extent({1000, 1000}), "f32", "cpu");
		librapid::Array test2(librapid::Extent({1000, 1000}), "f32", "cpu");
		librapid::Array test3(librapid::Extent({1000, 1000}), "f32", "cpu");
		librapid::Array test4(librapid::Extent({1000, 1000}), "f32", "cpu");
		librapid::Array test5(librapid::Extent({1000, 1000}), "f32", "cpu");
		librapid::Array res(librapid::Extent({1000, 1000}), "f32", "cpu");

		test.fill(1);
		test2.fill(2);
		test3.fill(3);
		test4.fill(4);
		test5.fill(5);
		res.fill(0);

		fmt::print("Has OpenBLAS: {}\n", librapid::hasBlas());
		fmt::print("BLAS Dot: {}\n", test.dot(test));

		int64_t iters = 100;
		double start = librapid::seconds();
		for (int64_t i = 0; i < iters; ++i) {
			res =
					2 * test + 3 * test2 + 4 * test3 + 5 * test4 + 6 * test5 + 7 * test +
					8 * test2 + 9 * test3 + 10 * test4 + 11 * test5;
		}
		double end = librapid::seconds();
		fmt::print("Elapsed: {:.2f} s\n", end - start);
		fmt::print("Average: {:.3f} ms\n", ((end - start) * 1000) / (double) iters);
		fmt::print("Result: {}\n", res);
	}


from librapid.

Pencilcaseman avatar Pencilcaseman commented on June 1, 2024

Can I just paste in random things and have it work?


View raw code

# Guess the Number

import random

def computer_to_guess(n):
    print("Think of a number between 1 and", n)

    # Initial value
    highest = n
    lowest = 0
    tries = 0
    correct = False
    guess = 0

    # guessing loop
    while not correct: # Loop while correct is false
        guess = lowest + int((highest-lowest+1)/2)
        print("My guess is", guess, ".")
        print("Is this too [h]igh, too [l]ow, or [c]orrect? ",end="")
        reply = input().lower().strip()
        tries = tries + 1
        if reply == "h":
            highest = guess
        elif reply == "l":
            lowest = guess
        elif reply == "c":
            correct = True
        else:
            print("You did not enter h, l, or c. Try again.")
    print("I took", tries, "tries to guess ", guess, ".\n\n")

def human_to_guess(n):

    # Intial value
    the_number = random.randint(1, n)
    guessed = False
    tries = 0

    print("I've thought of a number between 1 and", n, "\nTry guessing")

    # guessing loop
    while not guessed: # Loop while guessed is false
        valid_guess = False
        while not valid_guess:
            try:
                guess = int(input("Enter your number: "))
                valid_guess = True
            except TypeError:
                print("Not a number")
        tries += 1
        if guess > the_number:  
            print("Too high!")
        elif guess < the_number:
            print ("Too low!")
        else:
            print ("Just right...")
            guessed = True
    print("well done, you took", tries, "tries.\n\n")

def print_menu(n):
    print("Guess a number between 1 and", n)
    print("  (H) - human to guess")
    print("  (C) - computer to guess")
    print("  (N) - change maximum number")
    print("  (Q) - quit the game")

# Main program ===============

max_number = 100
print("Welcome to GUESS THE NUMBER")

play_on = True
while play_on:
    print_menu(max_number)
    response = input("Your choice: ").strip().upper()
    if response == "H":
        human_to_guess(max_number)
    elif response == "C":
        computer_to_guess(max_number)
    elif response == "N":
        valid_n = False
        while not valid_n:
            try:
                max_number = int(input("New max number: "))
                if max_number >= 1:
                    valid_n = True
            except TypeError:
                print("Not a valid number")
    elif response == "Q":
        play_on = False
        print("Bye!")
    else:
        print("Not a valid choice - one of H, C, N or Q")


from librapid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.