Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Default argument value bugs #282

Closed
mojodojodev opened this issue May 29, 2023 · 0 comments
Closed

[BUG]: Default argument value bugs #282

mojodojodev opened this issue May 29, 2023 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@mojodojodev
Copy link
Contributor

mojodojodev commented May 29, 2023

Partial use of default values

@value
struct Benchmark:
    fn __init__(
        inout self,
        num_warmup: Int = 2,
        max_iters: Int = 100_000,
        min_time_ns: Int = 500_000_000,
        max_time_ns: Int = 1000_000_000,
    ):
        print(num_warmup)
        print(max_iters)
        print(min_time_ns)
        print(max_time_ns)

let b = Benchmark(5, 10)
5
10
2
100000

It pushes the first two default values that weren't used to position 3 and 4.

You can see this does effect the current implementation of Benchmark in the standard library:

from Time import sleep

fn bench_args():
    fn sleeper():
        print("sleeping 30,000ns")
        sleep(3e-5)
    
    let b = Benchmark(0, 10)
    print("max benchmark milliseconds:", b.max_time_ns)

    _ = b.run[sleeper]()

bench_args()
max benchmark milliseconds: 100000
sleeping 30,000ns
sleeping 30,000ns
sleeping 30,000ns

The max is 100,000ns, not 1,000,000,000ns as intended, so only three sets of 30,000ns can run of the intended 10 max iterations.

Max Digits

In the Mojo playground, when two or more arguments are used with default values for Int, the max digits is 11, anything more will remove digits at runtime. This problem doesn't occur for F64.

This works fine:

fn default_val(a: Int = 12345678901, b: Int = 12345678901):
    print(a, b)

default_val()
12345678901 12345678901

Here a has 12 digits and so will only print 10 digits:

fn default_val_2(a: Int = 123456789012, b: Int = 12345678901):
    print(a, b)

default_val_2()
1234567890 12345678901

Both arguments here have 13 digits, and so will only print 9 digits

fn default_val_3(a: Int = 1234567890123, b: Int = 1234567890123):
    print(a, b)

default_val_3()
123456789 123456789

System information

11:hugetlb:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
10:memory:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
9:cpu,cpuacct:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
8:perf_event:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
7:devices:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
6:freezer:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
5:blkio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
4:net_cls,net_prio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
3:cpuset:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
2:pids:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
1:name=systemd:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-podddf90e49_6441_40c3_988f_9c67757e9546.slice/cri-containerd-2e45bd416836a026b676986c3ea9aa9790058d18549073fd5e3e726eb3bc0ae7.scope
0::/
@mojodojodev mojodojodev added the bug Something isn't working label May 29, 2023
@mojodojodev mojodojodev changed the title [BUG]: Default argument values max digits [BUG]: Default argument value bugs May 29, 2023
@Mogball Mogball self-assigned this Jun 5, 2023
@Mogball Mogball closed this as completed Jun 6, 2023
@Mogball Mogball closed this as completed Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants