
@maxim_jaffe has joined the channel

Hello, everyone! New to Racket (about 2 weeks), long-time programmer (mostly python)

Hi!

Hey :slightly_smiling_face:

Apart from being a LISP dialect I became interested because Racket has some great plotting and image libraries as well as a nice PDE (DrRacket). I was wondering if I could get some help figuring out what would be the best way to go about the following

I am working on a dynamic land use model, I initially built it on NetLogo and wanted to make some sort of port of it for Racket

My first goal is plotting the land use, each cell/patch has a number value and I want it to be displayed with a certain color

would be nice to have something reasonably fast to render

From what I’ve seen the plot library might not be the best option (I started implementing something like this in python with matplotlib), guessing the image libraries would be the best approach

is there a simple function that just converts a matrix of these land use values

into an image, mapping the numbers to colors?

How large is the matrix?

upper limit about 1000 x 1000

but closer to 800 x 800

One option is to use the draw library and simply draw squares on a canvas.

But maybe you can use … what they called …

yes :slightly_smiling_face:?

I thought about drawing squares after I saw the checkerboard example of the quick introduction with images, was just wondering if it made sense and if it was fast enough with that amount of data


I have a computation that’s consuming too much memory and blowing up the limits. Is there a way inside DrRacket to break the computation and get a backtrace of where the computation broke - which might give me an idea of where the memory consumption is coming from?

@soegaard2 thanks I’ll look into flomaps :slightly_smiling_face:!

@maxim_jaffe I am not sure they are the best fit.

Low level drawing to a canvas can be done using a dc (drawing context): http://docs.racket-lang.org/draw/dc___.html

hummm, I think I found the culprit actually, although I haven’t found how to get the backtrace in DrRacket.

@maxim_jaffe It is worth playing around with some options first. Also make sure to check out the pict library: http://docs.racket-lang.org/pict/index.html?q=pict

@pocmatos In DrRacket click the image with the three red signs.

read with white cross

read -> red

Also: in the language menu: choose “Debugging” (I think it is on as default)

@soegaard2 thanks will have a look

@soegaard2 ah, yes, I had debugging off. Thanks for the reminder.

@maxim_jaffe A quick example of how to use the low level drawing library: http://soegaard.github.io/blog/2013/06/27/drawing-bezier-curves/

it’s on by default but at some point I must have disabled it.

Maybe you were benchmarking something?

Likely. :slightly_smiling_face:

By the way is there a simple way of combining the canvas created by 2htdp/universe with a regular gui, with sliders and buttons?

not sure

oh well

Will keep going :wink:, hopefully I can get something reasonable working

I love the language and the environment

I haven’t felt this good since I first learned Python

by the way when I generate a large array using math/array

It prints out in a long sequence

is there a way of changing how it prints (maybe omitting middle values?)

a bit like in numpy of Python?

Do you need matrix operations - or just something to store 2d data?

hum mostly pointwise operations, although I would need something like a kernel/window operation

Consider using a vector instead then.

actually there is one calculation that I need some broadcasting for example

basically multiplying a 3d array

by a 1d

and then doing and argmax or argmin

on one of the axes

basically I have a main land use matrix

and then a bunch of layers to determine the next land use

would be nice to be able to calculate a softmax too

I couldn’t find a random array generator (maybe my google-fu wasn’t good enough). If it really is the case that there isn’t one, would such a function be useful in the base math/array library? It’s quite a common thing in Python, Julia and I think R and Matlab..!

That could be useful. I worked a bit with the matrix features of Racket (for deep learning) and found a lack of some useful functions like that. Didn’t quite got the time do do PRs, as I was learning the language in the same time, so I wasn’t ready to make changes to racket’s core. But “making Racket a cool language for AI by improving racket/math” is on my list of things to contribute :wink:

yeah would be great

:slightly_smiling_face:

I’ll collect some of the functions I write, maybe in future I can contribute

Still learning too

By the way is there a quick way of finding the code for a particular function of racket?

@maxim_jaffe in DrRacket, you can right click on identifiers and select “open defining file”, and in racket-mode, you can use racket-visit-definition

Thanks :slightly_smiling_face:!

that’s really helpful :slightly_smiling_face:

DrRacket really is great

DrRacket won’t be able to find the source for some of the core functions because they’re defined in C at the level of the runtime, but it will find the source for anything defined in Racket.

wait — raco te
is a synonym for raco test
???

@ben any unambigouous prefix can be used with raco

wow

Hello hello, any recommendation for terminal UI libs? I’m looking for something like this in racket: https://github.com/rivo/tview

@markx there’s nothing as feature-full as that, but you might be interested in the “charterm” pkg

@samth Thanks. It doesn’t seem to support creating boxes… That’s what I really want.

@leif This commit of yours appears to have broken the build on Windows. https://github.com/racket/racket/commit/eaaede9c2c40f40e9f322998a5a876a3b5170ccb

I haven’t looked into it enough to know if it’s an issue with the test suite or an actual problem, but it would be nice if you could resolve it, especially if that commit is going into the Racket 7 release.

wonders, “If I have to ask what a :kidney: reaction means, does that make me an oldster?”

how come they don’t have :liver: emoji ?

I haven’t the foggiest idea what it means, either, so you can probably rest easy.

The kidney above is basically the same as the foggy/panda/cocktails on this message, except Leif and I have used the kidney as a "+1" before. I’m hoping Leif goes “oh Ben sent a kidney hahahahahaha okay I better go fix the build (and then maybe replies with a matching kidney)”