This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-03-31
Channels
- # announcements (5)
- # babashka (5)
- # beginners (24)
- # calva (21)
- # cherry (1)
- # clerk (20)
- # clj-kondo (3)
- # clj-otel (12)
- # clojure (50)
- # clojure-austin (2)
- # clojure-conj (3)
- # clojure-europe (40)
- # clojure-nl (1)
- # clojure-norway (203)
- # clojure-spec (3)
- # clojure-uk (6)
- # clojurescript (8)
- # conjure (1)
- # datomic (1)
- # deps-new (1)
- # emacs (5)
- # graphql (8)
- # gratitude (5)
- # holy-lambda (16)
- # honeysql (18)
- # hyperfiddle (12)
- # java (1)
- # jobs (1)
- # lsp (24)
- # membrane (8)
- # nbb (1)
- # off-topic (19)
- # portal (28)
- # proletarian (11)
- # rdf (63)
- # re-frame (38)
- # reagent (8)
- # reitit (1)
- # releases (6)
- # remote-jobs (1)
- # scittle (4)
- # shadow-cljs (20)
- # spacemacs (4)
- # sql (7)
- # transit (1)
I have a function that takes an object and returns a keyword of its "simple type", where (1 2 3)
is :list
and true
is :boolean
and both 1
and 1/2
are :number
. I've implemented it using cond
and the built in functions because I couldn't get case
to work (`type` returns the class object, not a symbol). is there a better way than this? function impl in thread
(defn simple-type
[elem]
(cond
; literals
(nil? elem) :nil
(boolean? elem) :boolean
(char? elem) :char
(number? elem) :number
(keyword? elem) :keyword
(string? elem) :string
(symbol? elem) :symbol
; reader macros
(map? elem) :map
(set? elem) :set
(vector? elem) :vector
(seq? elem) :list
:else (type elem)))
I don't think so cuz condp puts the predicate in the first position: (condp elem nil? :nil)
becomes (if (elem nil?) :nil)
@UEENNMX0T I have a similar function in clj-kondo
ha of course you do. i wonder how close ours are to each other
I was trying to embed PyTorch into a clojure project using libpython-clj, but I keep getting segmentation errors when I try to train models. This is my code:
(ns test
(:require [libpython-clj2.require :refer [require-python]]
[libpython-clj2.python :as py :refer [py. py.. py.-]]))
(require-python '[torch.nn :as nn]
'[torch])
(let [batch 32
dim-in 10
dim-h 50
dim-out 10
input-X (torch/randn batch, dim-in)
output-Y (torch/randn batch, dim-out)
model (nn/Sequential (nn/Linear dim-in, dim-h)
(nn/ReLU)
(nn/Linear dim-h, dim-out))
loss-fn (nn/MSELoss)]
(let [pred-y (model input-X)
loss (loss-fn pred-y output-Y)]
(py. loss backward)))
Does anyone know what's going on?This is the error message:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007ff804117589, pid=28256, tid=37891
#
# JRE version: OpenJDK Runtime Environment Homebrew (19.0.2) (build 19.0.2)
# Java VM: OpenJDK 64-Bit Server VM Homebrew (19.0.2, mixed mode, emulated-client, sharing, tiered, compressed oops, compressed class ptrs, g1 gc, bsd-amd64)
# Problematic frame:
#
C [libsystem_pthread.dylib+0x1589] pthread_mutex_lock+0x4
I have also had error logs where the problematic frame was # C [libpython3.9.dylib+0x1692de] take_gil+0x3e
, but since take_gil appears in the stacktrace of mutex_lock it seems like it's the same error.
I've found that it's the (py. loss backward)
expression that causes the error.
I'm using a conda venv for the python side with pytorch 1.12.1, and I have libpython-clj 2.024.
Since it seems like this is an issue with the global interpreter lock and thread safety, I tried wrapping my code in each of the four variations of py/with-gil, but none of those worked.
Finally, translating the code to python and running it in the same venv works fine.Hmm, you probably should post this in #CLR5FD4ET too @U05021LUYL8
Given the fact you included a very precise repro case, I tried it, and it's working correctly on my end (it produces nil
because that's the result of backward
how can i set enviroment variable using lein to execute my project? without docker or any machine...
i have this code: (System/getenv "DATABASE_URL"), but i need know how set DATABASE_URL in enviroment
i tried add .ENV file, but it did not work :((((
lein ring server-headless 5000 DATABASE_URL=something doesn't work either
This env var will be valid only for the current terminal session, so you might want to use some other tool to manage env vars, like https://direnv.net/
you set the env stuff at the beginning. as posted there that is an argument to lein ring server
I tried the suggestion and got this: The term 'DATABASE_URL=something' is not recognized as a cmdlet name
i'm using windows OS
export DATABASE_URL=something had the same problem
But it is only valid for the current session, using a separate tool to manage those env vars or putting on the lein command would be better... Not sure how to do any of those on windows tho
makes sense, I'll try
it's okay to be only in the session in my case...
set DATABASE_URL=something it didn't work correctly, it's not picking up the application's System/getenv
to add variables in .bat it's like SET VAR=something?
when i use echo, the variable appears correctly, weird
oops, wait
I think it worked here
Thank you so much guys! You are very good.
what works is set DATABASE_URL=something but in regular command prompt not powershell
you should give WSL a shot if you have not yet, windows always gave me headaches like this, no matter the language
really, i'm getting these headaches now while studying, for c# it's really good
I need to learn more about it before I switch entirely, thanks for the tip