This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-05
Channels
- # aws (1)
- # beginners (57)
- # boot (3)
- # cider (6)
- # clara (49)
- # cljs-dev (47)
- # cljsjs (23)
- # clojure (144)
- # clojure-dev (2)
- # clojure-finland (1)
- # clojure-germany (1)
- # clojure-sg (1)
- # clojure-spec (25)
- # clojure-uk (245)
- # clojurescript (39)
- # core-async (3)
- # cursive (6)
- # datomic (117)
- # emacs (3)
- # fulcro (6)
- # hoplon (10)
- # jobs (7)
- # juxt (5)
- # leiningen (11)
- # om (27)
- # pedestal (4)
- # perun (2)
- # re-frame (22)
- # reagent (35)
- # ring-swagger (11)
- # shadow-cljs (333)
- # spacemacs (10)
- # specter (10)
- # sql (20)
- # vim (8)
Since clojure.test
is compiled with direct linking, am I correct that I should be able to recompile it without direct linking using:
(binding [*compiler-options* (assoc *compiler-options* :direct-linking false)]
(load "/clojure/test"))
?load will just reload the class file. You'd need to do this and call compile to recompile the aot class without direct linking.
@ghadi So for Cursive’s test integration (looks sort of like this: https://cursive-ide.com/userguide/testing.html, slightly out of date but you get the idea) I with-redefs
do-report
, because report
gives no file/line info for :pass
events.
I have a simple test:
(defn patched-report [original]
(fn [report]
(println (pr-str report))
(clojure.stacktrace/print-cause-trace (Throwable.))
(flush)
(original report)))
(let [original-do-report do-report
original-report report]
(with-redefs [do-report (patched-report original-do-report)]
;(binding [report (patched-report original-report)]
(run-tests *ns*)))
Using this, I only get :pass
and :fail
events in Clojure 1.8, but not e.g. :begin-test-ns
I figured I should be able to reload clojure.test
with direct linking disabled, but AFAICT it doesn’t work.
I think the idea is that report
should be dynamic, but needing file/line info is kind of an esoteric use case.
Perhaps I should grab the contents of /clojure/test.clj
off the classpath and explicitly load that into the REPL.
(binding [*compiler-options* (assoc *compiler-options* :direct-linking false)]
(-> "clojure/test.clj"
( (-> (class list) .getClassLoader))
()
(load-reader)))
hahahaha
I need to generate a gaussian sampled float-array of 100 elements. Is there a builtin for this? If not, what library should I look into?
user=> (let [r (java.util.Random. 42)] (repeatedly 100 #(.nextGaussian r)))
(1.1419053154730547 0.9194079489827879 -0.9498666368908959 -1.1069902863993377 0.2809776380727795 0.6846227956326554 -0.8172214073987268 -1.3966434026780434 -0.19094451307087512 1.4862133923906502 0.8023071496873626 -0.12151292466549345 1.4105062239438624 -0.6402327822135738 -1.2096444592532913 0.35375769787202876 -0.4903496491990076 0.5507215382743629 -1.2035510019650835 0.3210160806416416 1.5511476388671834 0.43853028624710505 0.4815980608245389 1.5196310789680683 -0.2768317291873249 -0.08393897849486337 1.255833005788796 -0.3252727938665772 -0.17329033306108363 -1.8585851445864527 1.4238069456328435 -1.363726024075023 -1.964666098753878 -0.9185948439341892 -2.548887393384806 -1.6309606578419305 -0.12200477461989162 1.289159071801577 -0.2691388556559934 0.2574914085090889 -0.3199143760045327 -1.7684998592513064 -0.4834503128592458 -0.5099904653893699 1.1166733769661994 -0.04094720151728288 -1.1076715169200795 1.8623214176471945 1.1457411377091524 -1.0586772048930921 1.0725991339400673 -1.9317441520296659 0.30102521611534994 0.2475231582804265 1.406156849249087 -1.5202207203569256 0.2709294126920897 0.561249284813777 -0.5298295780368607 0.5390221914988275 2.2123402141787243 -0.6329335687728442 -1.8831759122084633 0.3865659853763343 0.32582927090649455 -0.9013043195000002 -0.002680308907617573 -0.4739592549853249 -0.5479781547659026 -0.01910014847196348 1.6468163882596327 -1.107062592215791 0.5938103926672539 -0.15566462108511642 0.6632872929286855 1.226793360688623 0.8839698437730904 0.22172454670212935 0.9197020859698617 -0.7393758185888677 0.803517749531419 -0.2539417447630359 -0.7638388605060555 -1.8645567427274516 -1.861306200027518 -0.576599881116305 -0.40899380621224757 0.24846093761654187 -0.48091295490277447 0.44621205735391023 -0.4465888888803913 0.045638687865053575 0.7045663273135641 -0.2718240183671583 0.08074877915238832 1.2590964696340183 0.7635098382407334 1.7220810801509723 0.14595005405372477 -0.9946630124621867)
the "42" there is the seed
@noisesmith 1. nice, this answered the question I initially asked 2. is this making a function call per random number? as it turns out, I need to generate lots of random numbers (simulating noise for machine learning) -- is there a 'vectorized' approach where I specify the # of random numbers I want, make one call, and it all happens inside some highly optimized java code ?
I'd assume hotspot would likely be able to optimize it, but we'd need to test
you might be able to get better results with filling a mutable array instead of using repeatedly, depending on how much of a bottleneck this is
and no, as far as I know there's no vectorized version - I don't know of good RNGs that parallelize well (not that I'm an expert on that)
I think technically, one can run AES(key, i) all in parallel for different values of i, but running an entire round of AES just to generate a random number might be overkill
I've benchmarked the first version (15 microsecs) and I'm benchmarking the array version now
user=> (let [r (java.util.Random. 42) b (double-array 100)] (dotimes [i 100] (aset b i (.nextGaussian r))) (seq b))
(1.1419053154730547 0.9194079489827879 -0.9498666368908959 -1.1069902863993377 0.2809776380727795 0.6846227956326554 -0.8172214073987268 -1.3966434026780434 -0.19094451307087512 1.4862133923906502 0.8023071496873626 -0.12151292466549345 1.4105062239438624 -0.6402327822135738 -1.2096444592532913 0.35375769787202876 -0.4903496491990076 0.5507215382743629 -1.2035510019650835 0.3210160806416416 1.5511476388671834 0.43853028624710505 0.4815980608245389 1.5196310789680683 -0.2768317291873249 -0.08393897849486337 1.255833005788796 -0.3252727938665772 -0.17329033306108363 -1.8585851445864527 1.4238069456328435 -1.363726024075023 -1.964666098753878 -0.9185948439341892 -2.548887393384806 -1.6309606578419305 -0.12200477461989162 1.289159071801577 -0.2691388556559934 0.2574914085090889 -0.3199143760045327 -1.7684998592513064 -0.4834503128592458 -0.5099904653893699 1.1166733769661994 -0.04094720151728288 -1.1076715169200795 1.8623214176471945 1.1457411377091524 -1.0586772048930921 1.0725991339400673 -1.9317441520296659 0.30102521611534994 0.2475231582804265 1.406156849249087 -1.5202207203569256 0.2709294126920897 0.561249284813777 -0.5298295780368607 0.5390221914988275 2.2123402141787243 -0.6329335687728442 -1.8831759122084633 0.3865659853763343 0.32582927090649455 -0.9013043195000002 -0.002680308907617573 -0.4739592549853249 -0.5479781547659026 -0.01910014847196348 1.6468163882596327 -1.107062592215791 0.5938103926672539 -0.15566462108511642 0.6632872929286855 1.226793360688623 0.8839698437730904 0.22172454670212935 0.9197020859698617 -0.7393758185888677 0.803517749531419 -0.2539417447630359 -0.7638388605060555 -1.8645567427274516 -1.861306200027518 -0.576599881116305 -0.40899380621224757 0.24846093761654187 -0.48091295490277447 0.44621205735391023 -0.4465888888803913 0.045638687865053575 0.7045663273135641 -0.2718240183671583 0.08074877915238832 1.2590964696340183 0.7635098382407334 1.7220810801509723 0.14595005405372477 -0.9946630124621867)
same answer, theoretically faster methodthat's just over twice as fast
user=> (crit/bench (let [r (java.util.Random. 42)] (doall (repeatedly 100 #(.nextGaussian r)))))
Evaluation count : 3887760 in 60 samples of 64796 calls.
Execution time mean : 15.584700 µs
Execution time std-deviation : 244.518601 ns
Execution time lower quantile : 15.212346 µs ( 2.5%)
Execution time upper quantile : 16.101522 µs (97.5%)
Overhead used : 1.570108 ns
Found 1 outliers in 60 samples (1.6667 %)
low-severe 1 (1.6667 %)
Variance from outliers : 1.6389 % Variance is slightly inflated by outliers
nil
+user=> (crit/bench (let [r (java.util.Random. 42) b (double-array 100)] (dotimes [i 100] (aset b i (.nextGaussian r)))))
Evaluation count : 9223620 in 60 samples of 153727 calls.
Execution time mean : 6.688612 µs
Execution time std-deviation : 115.068935 ns
Execution time lower quantile : 6.514699 µs ( 2.5%)
Execution time upper quantile : 6.917354 µs (97.5%)
Overhead used : 1.570108 ns
nil
(map identity (let [r (java.util.Random.)] (as-> r (.ints 0 100) (.limit 100) (.toArray )))) this isn't gaussian yet, but there is limit / toArray
wait, where is that ints method comingfrom? I don't see it in the docs
also you can use seq instead of map identity
oh I see it now, it's new in java 8
next question is whether 6.8 microsecs per 100 numbers is too slow
(or whatever that translates to on your target of course)
I'm probably prematurely optimizing -- but I'm translating over numpy code, and the one thing that numpy has hammered into my thought process is "vector ops" instead of "for loops"
anyway, thanks for your help / benchmarking -- back to translating numpy/tensorflow code 🙂
yeah, I think for actual vectorized stuff you need to use native libs with the jvm
there's bindings to the fortran libs right?
jblas
so I think the situation is: there are java tensorflow bindings, but there are NOT java numpy bindings
@qqq This is one of the simplest things that Bayadera does, and it can give you billions of such numbers (not only Gaussian) in very short time (AMD GPU only for now, Nvidia support is comming).
@blueberry oh, i had not run into that library, neat. Although afaik, tensorflow is nvidia only (or at least was), so that's an annoying gpu support mismatch for qqq's problem. 😞
Is there a reason that for doesn't have an implied do in it's body? It's an inconvenience when I want to add a debug print statement. (for [] x)
has to become (for [] (do (print...) x))
Perhaps there's a performance hit or some optimisation issue. I'm just curious really.
just guessing but doseq
is for imperative code and for
is for pure collection processing - the fact that doseq
has implicit do
but for
doesn't reflects that difference
I agree the logic is there. Just wondering if it's pedantic or pragmatic. Print statements are kind of important when you want to know lazy things happened.
I agree, I've definitely run into this before
pro tip: (for [x xs] (doto (do-something x) prn))
Genius!
hi, (resolve (symbol "prn"))
resolves well to function that I can call, but if i require a function called export-csv
then (resolve (symbol "export-csv"))
does not work anymore, resolves to`nil`
I have a vector of (vector of (vector of float))) representing a 3d array of height width depth what is the best way to flatten this into a "float-array" ?
(flatten your-vector-of-vector-of-vector-of-float)
Why not (float-array (flatten [[[1.0 2.0] [3.0 4.0]] [[5.0 6.0] [7.0 8.0]] [[9.0 10.0] [11.0 12.0]]])) ?
Interesting, thanks. Is there a workaround?
Yeah, it was definitely a hack in the first place.
Will there be specs for functions in clojure.core? Are they needed? Or is it too difficult to make?
Huh. Interestingly leaky abstraction.
Just that it works in some cases and not others, presumably has something to do the underlying implementation.
I see. Good tip, actually was able to get my hack to work with that in mind.
I am trying to migrate from clj to cljc some ns but I get java.io.FileNotFoundException: Could not locate... on classpath
Apparently something is renaming my cljc file extension to cljc.clj
at least emacs displays the file with this weird extension
Anyone has an idea?
My file system still sees .cljc but emacs tells me otherwise when browsing the file tree
so i'll take a wild guess. you have clj-refactor along with cider. your buffers are in clojure-mode
and the refactoring is ensuring that the file suffix is appropriate. i'll bet that if you change to clojurec-mode
(note the c) you will end this algorithmic tug of war
Thank you @dpsutton 🙂 How to change to clojurec-mode?
(no match)
Not sure. I am in a clojure file then I type M-x clojurec-mode
i see clojure-mode but not clojurec-mode
not sure if this get me in a clojure buffer. I am not an emacs pro 😞
Ok I reinstalled clojure-mode and I see clojurec-mode
i select it, but still see .cljc.clj …
Even if I reboot emacs
Does anyone use Jupyter Notebooks with Clojure? There are three Clojure kernels and I have no idea which are best.
And even if I close emacs and have proper .cljc extension, I get java.io.FileNotFoundException: Could not locate
I seems to be two problems
I got Could not locate foo/bar__init.class or foo/bar.clj on classpath.
instead of Could not locate foo/bar__init.class, foo/bar.clj, or foo/bar.cljc on classpath.
I seams cljc in not there
I have clojure 1.8.0
and i got :source-paths ["src/clj" "src/cljc"]
in my projet.clj
Thank you anyway for your help
there’s a ticket for that - the error message is just missing it. it is actually looking for foo/bar.cljc though
ok thanks @alexmiller
Reloading Clojure file "/foo/bar.cljc.clj" failed.
even without emacs, I get .cljc.clj
file naming issue
Compiling ClojureScript...
Reloading Clojure file “/foo/bar.cljc.clj” failed.
clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Conditional read not allowed, compiling:(foo/bar.cljc.clj:3:6)
that ends in .clj so will be treated as a Clojure file, not a cljc file
but maybe that’s an error message error. That “Reloading” message is not part of Clojure core, not sure where that’s from.
I think that’s lein-cljsbuild? https://github.com/emezeske/lein-cljsbuild/blob/master/support/src/cljsbuild/compiler.clj#L126
On my mac, if I do CMD + i on file, I see the file has .cljc.clj extension. When I rename it from there, it compiles
Seems really an Emacs issue
Sorry about that
np, too many things that need to work together!
If I'm invoking a static operation in a java class in repl, is the static initializer block in the class guaranteed to be executed? because it looks to me it's not. it only seems to be normally executed if I add an extra level of indirection, i.e. have another class on java side that invokes the static operation
well I noticed a very odd behavior when my unit test in clj failed even though it executed the same code as the corresponding junit class. they invoke static operation but results depend on the static initializer block to be run before
have you been able to directly observe effects of the static initializer not happening?
I can't explain the result otherwise. there are no other code changes involved, but no, not directly. I suppose it'd be simple to write a standalone test for it. but sounds like this is not a known issue?
the static initiliazer isn't usually something you have to invoke directly, but there are ways to load a class without having it invoked, and clojure has had some changes over the years to delay when the static initializers are run
if the compiler can't determine the types to resolve the method at compile time it will insert the reflection for you
you can (set! *warn-on-reflection* true)
at the top of your source file and then recompile it to get warnings about it
hello everybody, is anyone aware of some webserver in cljs? something like a port of compojure to run with nodejs or something like that
compojure is a router
@plins anyway you might find macchiato interesting https://github.com/macchiato-framework
just be aware that if you care about performance or resources jvm clojure is going to be the better bet
What would be the best way to have an experimental namespace? So maybe one day the fns inside it move to another namespace, but I wouldn't want people to need to change their require when that happens. So the experimental should still point to the now none experimental fn.
Potemkin's import-vars https://github.com/ztellman/potemkin#import-vars does what you want. Personally, rather than doing it that way though, I'd probably just tag the function as experimental in the final intended namespace, rather than having an NS of experimental things imported all over the place