workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
clojurians | clojure | it’d be pretty easy to make an amap-inplace that just doesn’t create a clone | 2017-11-05T14:00:28.000091 | Jonas |
clojurians | clojure | <@Jonas>: why is it faster than doseq, is it the loop+unchecked-inv vs range ? | 2017-11-05T14:06:47.000028 | Berry |
clojurians | clojure | the main reason is `aset-float` | 2017-11-05T14:07:03.000068 | Jonas |
clojurians | clojure | aset-float is *slower* than a regular aset ? | 2017-11-05T14:07:15.000003 | Berry |
clojurians | clojure | yea | 2017-11-05T14:07:22.000038 | Jonas |
clojurians | clojure | I think i mislead you there | 2017-11-05T14:07:27.000052 | Jonas |
clojurians | clojure | I thought giving it more info (hey, this is a float) would make it faster | 2017-11-05T14:07:28.000035 | Berry |
clojurians | clojure | if you do `(aset z i ^float i)` | 2017-11-05T14:07:32.000006 | Jonas |
clojurians | clojure | it runs faster | 2017-11-05T14:07:40.000003 | Jonas |
clojurians | clojure | but not as fast as `amap` | 2017-11-05T14:07:47.000115 | Jonas |
clojurians | clojure | ```(let [n (* 10 1000 1000)
z (float-array n)]
(doseq [^long i (range 1 n)]
(aset z i ^float i)))``` | 2017-11-05T14:07:57.000006 | Jonas |
clojurians | clojure | ```> (macroexpand-1 '(doseq [^long i (range 1 n)]
(aset ^floats z ^long i ^float i)))
(clojure.core/loop
[seq_75583 (clojure.core/seq (range 1 n)) chunk_75584 nil count_75585 0 i_75586 0]
(if
(clojure.core/< i_75586 count_75585)
(clojure.core/let
[i (.nth chunk_75584 i_75586)]
(do (aset z i i))
(recur seq_75583 chunk_75584 count_75585 (clojure.core/unchecked-inc i_75586)))
(clojure.core/when-let
[seq_75583 (clojure.core/seq seq_75583)]
(if
(clojure.core/chunked-seq? seq_75583)
(clojure.core/let
[c__4685__auto__ (clojure.core/chunk-first seq_75583)]
(recur
(clojure.core/chunk-rest seq_75583)
c__4685__auto__
(clojure.core/int (clojure.core/count c__4685__auto__))
(clojure.core/int 0)))
(clojure.core/let
[i (clojure.core/first seq_75583)]
(do (aset z i i))
(recur (clojure.core/next seq_75583) nil 0 0))))))``` | 2017-11-05T14:08:19.000119 | Jonas |
clojurians | clojure | interesting, aset-float -> aset changed runtime from "500ms" to "90ms" | 2017-11-05T14:08:29.000137 | Berry |
clojurians | clojure | but the doseq version is also doing a bunch of other stuff that makes it slower than the `amap` version as seen in the macroexpand | 2017-11-05T14:08:57.000079 | Jonas |
clojurians | clojure | it does seem crazy that aset-float is slower than aset | 2017-11-05T14:09:44.000030 | Jonas |
clojurians | clojure | but those are similar results to what i saw on my computer as well | 2017-11-05T14:10:02.000003 | Jonas |
clojurians | clojure | <@Jonas> this is so insightful:
aset-float -> aset = 500ms -> 90 ms
doseq -> loop + unchecked-inc = 90ms -> 20ms
which basically matches amap | 2017-11-05T14:10:17.000134 | Berry |
clojurians | clojure | now I'm happy | 2017-11-05T14:10:21.000086 | Berry |
clojurians | clojure | I feel like I've made every $&@(#$ possible numeri-clojure mistake there is to make :-) | 2017-11-05T14:10:39.000033 | Berry |
clojurians | clojure | i’m learning a lot from this too | 2017-11-05T14:11:10.000067 | Jonas |
clojurians | clojure | <@Berry> nah there's lots of numeri-clojure mistakes to make, you're still making the one where you write clojure instead of java when it has to be fast for numerics for example | 2017-11-05T14:12:01.000006 | Margaret |
clojurians | clojure | :smile: | 2017-11-05T14:12:03.000086 | Margaret |
clojurians | clojure | <@Margaret>: now you're ignoring what I'm saying ... see "numeri-clojure" :slightly_smiling_face: | 2017-11-05T14:12:54.000064 | Berry |
clojurians | clojure | <@Jonas>: showing the source of the amap macro was especially useful; as I actually need a 2d version | 2017-11-05T14:14:34.000019 | Berry |
clojurians | clojure | why wouldn't nested amap work for 2d? | 2017-11-05T14:15:31.000017 | Margaret |
clojurians | clojure | because it returns an array of array, instead of a flat float-array | 2017-11-05T14:15:48.000094 | Berry |
clojurians | clojure | and what I meant is that if you care about your time, writing it java in the first place is more expedient, no matter how much we all prefer writing clojure | 2017-11-05T14:16:28.000035 | Margaret |
clojurians | clojure | actually, most of the code is running the GPU using tensor libraries | 2017-11-05T14:16:53.000091 | Berry |
clojurians | clojure | why would anything give you a flat float array out of a 2d array? in java a 2d array is an array of arrays | 2017-11-05T14:16:58.000010 | Margaret |
clojurians | clojure | there just happens to be some $*@#($* ETL type work I need to do beforehand | 2017-11-05T14:17:02.000022 | Berry |
clojurians | clojure | i have jump to source setup and it’s really useful for clojure. either looking at source in clojure core or in libraries I consume | 2017-11-05T14:17:19.000105 | Jonas |
clojurians | clojure | <@Margaret> BufferedImage -> getRaster -> getData is an flat array | 2017-11-05T14:17:20.000043 | Berry |
clojurians | clojure | sounds like you could skip a bunch of trouble and use the flat array and do some simple indexing math instead of pretending it's 2d | 2017-11-05T14:17:58.000059 | Margaret |
clojurians | clojure | and I hear you saying that the GPU is doing most of the work, but if you'd written this in java in the first place you would have saved a lot of time, and that's 100% of my experience when numeric performance is an issue in clojure | 2017-11-05T14:20:22.000068 | Margaret |
clojurians | clojure | my workflow is write in clojure, if it's slow figure out the bottleneck, if the bottleneck is math related write a small java class for it | 2017-11-05T14:21:40.000093 | Margaret |
clojurians | clojure | is `float-array` guarnateed to be all 0?
<https://clojuredocs.org/clojure.core/float-array> does not mention it, but I ran `(seq (float-array 20))` a bunch of times, and it's all 0 all the time | 2017-11-05T14:56:37.000062 | Berry |
clojurians | clojure | <@Berry> <https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Numbers.java#L1126> | 2017-11-05T14:59:58.000054 | Margaret |
clojurians | clojure | <@Margaret>: I see, so float-array just creates a java float array, but then according to <https://stackoverflow.com/questions/2154251/any-shortcut-to-initialize-all-array-elements-to-zero>
that defaults to 0 | 2017-11-05T15:01:50.000024 | Berry |
clojurians | clojure | so that is using `new float[]` yeah <https://stackoverflow.com/a/3426854> | 2017-11-05T15:02:02.000017 | Margaret |
clojurians | clojure | Regarding Datomic, I'd like to have my unit tests running in isolated environments just like what was demonstrated in this video, [Test-driven Development with Datomic](<https://www.youtube.com/watch?v=JaZ1Tm6ixCY>), but using Datomic's Client API (`datomic.client`).
The author demonstrates a technique in which he creates an in memory database for every unit test in his suite, but it only seems to be possible to do using the Datomic API (`datomic.api`) because it has function `create-database` (<http://docs.datomic.com/clojure/index.html#datomic.api/create-database>) that provides some facilities for creating in memory databases whenever you want to.
I've been thinking about a work around for his technique using the Client API and the only thing that comes to my mind is executing from within my test code a peer server and then stopping it after the test finishes its execution. Something like: `bin/run -m datomic.peer-server -h localhost -p 8998 -a myaccesskey,mysecret -d hello,datomic:<mem://hello>`
It sounds like an overkill solution for me and I believe it's a pretty common use case to execute your unit tests against a fresh database instance. Does anyone have an easier solution that I could use? | 2017-11-05T16:23:41.000025 | Ahmad |
clojurians | clojure | On the one hand, you can create a fixture that deletes the database and reloads the necessary test data between every test. I found this example on SO: <https://stackoverflow.com/questions/35005669/wiping-out-a-datomic-db-for-test-environment> | 2017-11-05T18:59:10.000133 | Kyung |
clojurians | clojure | On the other hand, there’s the philosophy that you shouldn’t need to “unit test” with an external dependency like a database | 2017-11-05T19:04:46.000138 | Kyung |
clojurians | clojure | FWIW, this is pretty much exactly what we do for tests in our services that use the client API. It’s a little heavyweight, but not overly so. Running tests works fine with this procedure. | 2017-11-05T19:19:00.000025 | Wenona |
clojurians | clojure | <@Kyung> I don't think it would work for the Client API, it only connects to a peer server. And even though the Client API has similar methods for creating, deleting and listing databases (<http://docs.datomic.com/clojure-client/index.html#datomic.client.admin>), I'm not being able to make them work in memory databases. I guess I will have to make use of this dirty hack or I could use the older library, but wouldn't be this entertaining xD | 2017-11-05T19:33:54.000139 | Ahmad |
clojurians | clojure | <@Wenona> Good to know I'm not entirely mad in doing so xD Thanks for the letting me know! | 2017-11-05T19:36:33.000099 | Ahmad |
clojurians | clojure | When clojure tells me:
```
java.lang.IllegalArgumentException: More than one matching method found: add
clojure.lang.Compiler$CompilerException: java.lang.IllegalArgumentException: More than one matching method found: add, compiling:(
```
is there a way to respond: great, please list all the matching methods for me? | 2017-11-05T19:44:17.000119 | Berry |
clojurians | clojure | In Cursive you can use Ctrl+B and check the method overloads. But it seems that you will have to use type hints | 2017-11-05T19:47:44.000079 | Ahmad |
clojurians | clojure | yeah, so I try type hints, and it tells me "you ca't type hint this local" | 2017-11-05T19:48:41.000010 | Berry |
clojurians | clojure | maybe I should produce a minimal failure case | 2017-11-05T19:48:47.000161 | Berry |
clojurians | clojure | ```
(ns snip.fail
(:require [primitive-math :as p]))
(let [a (float-array 20)
y (aget ^floats a 0)]
(loop [x (float 0.0)]
(p/+ x y)))
```
^--- please help me typehint this
(yes, the loop is important, you can't change the loop to a ledt) | 2017-11-05T19:50:25.000136 | Berry |
clojurians | clojure | ```
(let [a (float-array 20)
y (aget a 0)]
(loop [x 0]
(p/+ (float x) (float y))))
``` | 2017-11-05T20:00:10.000241 | Ahmad |
clojurians | clojure | ^ It seems that you can do it like this <@Berry> | 2017-11-05T20:00:29.000065 | Ahmad |
clojurians | clojure | yes, indeed, how expensive is the (float ...) given the arg is already a float? | 2017-11-05T20:00:43.000045 | Berry |
clojurians | clojure | I genuinely don't know, and am trying to avoid as much boxing/unboxinga s possible | 2017-11-05T20:01:01.000074 | Berry |
clojurians | clojure | ```
public static float floatCast(Object x) {
if (x instanceof Float) {
return ((Float)x).floatValue();
} else {
double n = ((Number)x).doubleValue();
if (n >= -3.4028234663852886E38D && n <= 3.4028234663852886E38D) {
return (float)n;
} else {
throw new IllegalArgumentException("Value out of range for float: " + x);
}
}
}
``` | 2017-11-05T20:01:37.000131 | Ahmad |
clojurians | clojure | This is what happens every time you call `float`. Lots of unboxing | 2017-11-05T20:02:02.000117 | Ahmad |
clojurians | clojure | this also confuses me:
```
;; fails
(let [a (float-array 20)
y (aget ^floats a 0)]
(loop [x (float 0.0)]
(p/+ x y)))
;; works
(let [a (float-array 20)
y (aget ^floats a 0)
x (float 0.0)]
(p/+ x y))
``` | 2017-11-05T20:02:25.000095 | Berry |
clojurians | clojure | so for whatever reason, let = works, loop = fails, (unfortunately, I need to loop) | 2017-11-05T20:02:39.000024 | Berry |
clojurians | clojure | ```
(let [a [0.0 0.0 0.0 0.0 0.0]
y (a 0)]
(loop [x 0.0]
(p/+ x y)))
``` | 2017-11-05T20:06:47.000107 | Ahmad |
clojurians | clojure | It works this way too. Do you actually need to use `float-array`? | 2017-11-05T20:07:13.000103 | Ahmad |
clojurians | clojure | I think these are all doubles, not floats right ? | 2017-11-05T20:08:26.000023 | Berry |
clojurians | clojure | (I do have to use float-array, as I'm aset -ing alot) | 2017-11-05T20:08:37.000051 | Berry |
clojurians | clojure | ```
(let [a [(float 0.0)]
y (a 0)]
(loop [x (float 0.0)]
(p/+ x y)))
```
this also fails | 2017-11-05T20:09:08.000013 | Berry |
clojurians | clojure | question is: why is clojure making this a float vs double issue | 2017-11-05T20:10:26.000063 | Berry |
clojurians | clojure | Oh, you also have the option do use `unchecked-float`, it's a bit less expensive:
```
public static float uncheckedFloatCast(Object x) {
return ((Number)x).floatValue();
}
``` | 2017-11-05T20:14:06.000023 | Ahmad |
clojurians | clojure | ```
;; works
(let [a (double-array 20)
y (aget ^double a 0)]
(loop [x (double 0.0)]
(p/+ x y)))
;; fails
(let [a (float-array 20)
y (aget ^float a 0)]
(loop [x (float 0.0)]
(p/+ x y)))
``` | 2017-11-05T20:15:37.000221 | Berry |
clojurians | clojure | seems like double/float are treated differently | 2017-11-05T20:15:42.000133 | Berry |
clojurians | clojure | <@Haydee>: any chance you can help? :slightly_smiling_face: | 2017-11-05T20:15:51.000123 | Berry |
clojurians | clojure | alright, I have an even simple minimal failure case:
```
;; works
(let [y (double 0.0)]
(loop [x (double 0.0)]
(p/+ x y)))
;; fails
(let [y (float 0.0)]
(loop [x (float 0.0)]
(p/+ x y)))
``` | 2017-11-05T20:16:38.000005 | Berry |
clojurians | clojure | That's interesting, I wonder why `loop` works like that
```
(loop [x (float 0.0)]
(type x))
=> java.lang.Double
``` | 2017-11-05T20:21:20.000094 | Ahmad |
clojurians | clojure | Btw, <@Berry> that's what it's causing the impossibility to find the correct overload
```
(let [y (float 0.0)]
(loop [x (float 0.0)]
(println (type x) (type y))))
=> java.lang.Double java.lang.Float
``` | 2017-11-05T20:22:56.000026 | Ahmad |
clojurians | clojure | that clarifies so much | 2017-11-05T20:23:10.000085 | Berry |
clojurians | clojure | I don't know how to file clojure bug reports, but I think your example above has to be a bug | 2017-11-05T20:23:37.000065 | Berry |
clojurians | clojure | I don't think it's a bug, it's seems to be related to the quotes and unquotes being performed inside the `loop` macro. Check this out: | 2017-11-05T20:25:05.000107 | Ahmad |
clojurians | clojure | Regardless of the macro internals,
```
(loop [x (float 0.0)]
(type x))
=> java.lang.Double
```
should return Float instead of Double, IMHO | 2017-11-05T20:27:30.000056 | Berry |
clojurians | clojure | I agree | 2017-11-05T20:27:57.000142 | Ahmad |
clojurians | clojure | I guess you can try other alternatives to the loop macro, or the `unchecked-float` that seems to be a bit less expensive | 2017-11-05T20:29:50.000001 | Ahmad |
clojurians | clojure | <@Sandy> <@Sonny>: When you get a chance, can you please let us know what Clojure's semi-official stance on
```
(loop [x (float 0.0)]
(type x))
=> java.lang.Double
```
is intended behaviour -- or if it should return java.lang.Float, and thus a bug ? | 2017-11-05T20:31:18.000066 | Berry |
clojurians | clojure | <@Ahmad>: I'm going to go study loop* :slightly_smiling_face: | 2017-11-05T20:31:29.000147 | Berry |
clojurians | clojure | You will be taken to the depths of the compiler internals, be careful mate. `src/jvm/clojure/lang/Compiler.java#L6318` more precisely | 2017-11-05T20:36:00.000027 | Ahmad |
clojurians | clojure | yeah, it's kinda a bad sign when there are no docs, i.e.
```
boot.user> (clojure.repl/doc loop*)
nil
boot.user> (clojure.repl/doc loop)
-------------------------
clojure.core/loop
(loop [bindings*] exprs*)
``` | 2017-11-05T20:38:46.000012 | Berry |
clojurians | clojure | correct me if I"m wrong, the problem here is the loop macro is smart, so at compile time, it's like
"oh, I see (float 0.0)"
let me evaluate this at macro expansion time
"oh, we got 0.0"
[next stage:]
"oh, 0.0 is a double" | 2017-11-05T20:40:04.000093 | Berry |
clojurians | clojure | actually, my theory is wrong:
```
(macroexpand
'(loop [x (float 0.0)]
x))
;; ==> (loop* [x (float 0.0)] x)
``` | 2017-11-05T20:41:16.000187 | Berry |
clojurians | clojure | I don't think you will be able to expand everything inside this macro, `loop*` is a symbol defined in the compiler's code. I don't even think there's documentation for it. It's something we should never have to look at | 2017-11-05T20:42:39.000155 | Ahmad |
clojurians | clojure | ```
(macroexpand
'(loop [x (float 0.0)]
(type x)))
;; => (loop* [x (float 0.0)] (type x))
(loop [x (float 0.0)]
(type x))
;; => java.lang.Double
(loop* [x (float 0.0)] (type x))
;; => java.lang.Double
```
looking at that, it looks like everything is passed to loop* correctly (still as a float), but loop* [which is implemented in Java?] is doing the weird float -> double translation | 2017-11-05T20:43:27.000172 | Berry |
clojurians | clojure | Yup, the macro takes your bindings and body and send them to loop* so that it can perform the magic | 2017-11-05T20:44:04.000108 | Ahmad |
clojurians | clojure | Clojure only supports primitive long and double | 2017-11-05T20:44:49.000040 | Sonny |
clojurians | clojure | Loops support a wider set of loop local primitive types | 2017-11-05T20:45:27.000010 | Sonny |
clojurians | clojure | But once you leave the loop you’re back to long and double | 2017-11-05T20:46:10.000077 | Sonny |
clojurians | clojure | <@Sonny>: what does 'support' mean in 'Clojure only supports primitive long and double.'
We have `float-array` , `aget`, `float` -- this seems to contradict only supporting double. | 2017-11-05T20:47:37.000052 | Berry |
clojurians | clojure | Some of that is vestigial from an earlier time when a broader set were supported. Some is for limited interop | 2017-11-05T20:49:27.000137 | Sonny |
clojurians | clojure | Only float and double are supported as primitive args/returns in functions | 2017-11-05T20:50:05.000176 | Sonny |
clojurians | clojure | Sorry, only long and double | 2017-11-05T20:50:53.000161 | Sonny |
clojurians | clojure | `Only float and double are supported as primitive args/returns in functions` <-- Can you please explain what happens when I call a java function of type sig
` float java_add(float x, float y) `
and call it from clojure as (java_add (float 2.0) (float 3.0))
in particular, what is returned, a float or a double ? | 2017-11-05T20:52:13.000054 | Berry |
clojurians | clojure | Sorry, I’m signing off for the night | 2017-11-05T20:53:45.000071 | Sonny |
clojurians | clojure | Too long, catch you tomorrow | 2017-11-05T20:53:53.000077 | Sonny |
clojurians | clojure | thanks for your help; take care | 2017-11-05T20:53:56.000088 | Berry |
clojurians | clojure | Considering what alex said, you should try to use doubles instead of floats, they will fit your float values anyway. At least for these operations involving the loop macro. | 2017-11-05T20:57:45.000055 | Ahmad |
clojurians | clojure | I'm interfacing with other libraries that want floats. | 2017-11-05T21:14:38.000035 | Berry |
clojurians | clojure | I'm going to write this performance critical code in java :slightly_smiling_face:. | 2017-11-05T21:15:03.000115 | Berry |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.