// Integer inference stays Int64; explicit representations belong to Number.
let ordinary = 42
let sample: Int16 = -32000
let pixel = UInt8(255)
let large: UInt64 = 18446744073709551615
let same_large = UInt64(18446744073709551615)
print(type(ordinary)) // Int64
print(dtype(sample)) // Int16
print(type(pixel)) // UInt8
print(large == same_large) // true
print(large > 9223372036854775807) // true

var numeric: Number = pixel
print(type(numeric)) // UInt8
numeric = sample
print(type(numeric)) // Int16
numeric = 2.5
print(type(numeric)) // Float64

let source: Int64 = 200
let byte: UInt8 = source
let wider: UInt32 = byte
print(byte) // 200
print(type(wider)) // UInt32
print(Int16(3.9)) // 3
print(Int16(-3.9)) // -3
print(type(Int8(2) + UInt8(3))) // Int16
print(type(UInt8(250) + 1)) // Int64
print(integer_div(Int16(-7), Int16(3))) // -2
print(Int16(-7) % Int16(3)) // -1

let pixels = Array<UInt8>(size: 4, fill: 0)
pixels[0] = 255
pixels.set(1, 128)
print(dtype(pixels)) // UInt8
print(type(pixels.get(0))) // UInt8
print(pixels.to_list()) // List(255, 128, 0, 0)

let samples = DynamicArray<Int16>(capacity: 2)
samples.append(-100)
samples.append(200)
print(samples.sum()) // 100
print(type(samples.sum())) // Int16
let matrix = NDArray<Int32>(shape: List(2, 2), fill: 3)
print(matrix.matmul(matrix).to_list()) // List(18, 18, 18, 18)
let floating = samples.to_float()
print(dtype(floating)) // Float64
print(type(Float64(large))) // Float64: explicit permission to round

// Checked failures, intentionally disabled:
// let invalid: Int8 = source // R1003: 200 exceeds 127
// print(UInt8(-0.5)) // R1003: unsigned conversions reject negative floats
// print(UInt8(250) + UInt8(10)) // R0001: UInt8 scalar overflow
// print(large + 1) // no lossless common integer type with signed Int64
// pixels.set(0, 300) // R1003: scalar conversion fails before mutation
// print(pixels.sum()) // R3001: 383 exceeds UInt8; array sum retains dtype
