r/Julia

▲ 28 r/Julia

What's the most straightforward way to read and write numerical data from a file in Julia?

I'm interested in picking up Julia as a scientific computing language, hopefully to replace my current system of Fortran-for-speed and Python-for-convenience. However, I'm getting hung up on its file handling.

The issue is that in Julia, all of my options for file I/O look pretty confusing. The built-in read and write functionality seems to only take text input as strings, rather than as numeric types. The CSV package is powerful, but then it complicates things because it only returns a 'dataframe', whatever that is. Likewise, the documentation for CSV.write() says that it will "write a Tables.jl interface input to a csv file." All I want to do is read some numbers into a couple 1D arrays, do some math on them, then write them back out. I feel like I must be missing something stupidly obvious, because I don't understand why it seems so hard for Julia to do something that creaky old Fortran figured out decades ago.

To illustrate more clearly what I'm trying to do, sample code follows in Fortran 90 and Python. In both cases, the code reads an input file (file.txt) and stores the data in 1D arrays a and b. Then, assuming further computations follow producing 1D arrays x and y, those two arrays are written to a new file (file2.txt).

Fortran 90:

open(10, 'file.txt')

do i = 1, 10
   read(10, *) a(i), b(i)
end do

close(10)

...
(further computations on a and b, producing outputs x and y)
...

open(11, 'file2.txt')

do i = 1, 10
   write(10, *) x(i), Y(i)
end do

close(11)

Python:

a, b = numpy.loadtxt("file.txt", unpack=True)

...
(further computations on a and b, producing outputs x and y)
...

data = numpy.column_stack((x, y))

numpy.savetxt(file2.txt, data, fmt='%.16E', delimiter=' ')

As you can see, the Fortran method is a little clunky but very explicit about what it's doing, whereas the Python method is slick but requires a little extra formatting work.

reddit.com
u/ducks_over_IP — 2 days ago
▲ 15 r/Julia

Help Needed: Can Anyone Benchmark Tsetlin.jl on Ryzen 9950X or Apple M5 Pro/Max?

If you have a Ryzen 9950X (or 9950X3D / 9950X3D2) or an Apple M5 Pro/Max with 18 CPU cores, could you please benchmark the latest Tsetlin.jl library on those CPUs and share the results in the comments?

I only have a Ryzen 7950X3D and an Apple M1 Pro, and I’m curious how the latest version performs on newer hardware.

MNIST benchmark

julia -t 18 examples/MNIST/mnist.jl  # M5 Pro/Max
julia -t 32 examples/MNIST/mnist.jl  # 9950X

I’m interested in:

  • Total training time for 1000 epochs
  • How many million predictions per second your CPU can achieve

Text generation benchmark

julia -t 18 examples/TEXT/train.jl  # M5 Pro/Max
julia -t 32 examples/TEXT/train.jl  # 9950X

Here I’m mainly interested in the time for the first few training epochs.

I would really appreciate any results you can share.

u/ArtemHnilov — 6 days ago
▲ 19 r/Julia

Learning Julia and the chapter about scoping in the docsgave me pause

What happened there ? Everything before was elegant enough. But complexity in how scoping is presented feels leaky and inelegant. I don't know, still wrapping my mind around it. Compared to how closure is effortless in Scheme in comparison this feels like too much cognitive load, and worse is I don't see the point for it yet. Is it for performance reasons ?

reddit.com
u/HilbertInnerSpace — 9 days ago