libera/#commonlisp - IRC Chatlog
Search
13:46:25
phantomics
Does anyone have an idea what the overhead of (adjust-array) is? I'm using it to reference small bits of a big array, changing the displaced-index-offset to do so, but it's a bit annoying that I have to pass the shape and :displaced-to every time rather than just being able to assign a new offset
13:48:52
phantomics
Ok, I don't change the length though, just the offset but it needs to calculate for the new length each time?
13:49:14
phantomics
How do I do that, afaik (adjust-array) requires you to give the desired shape each time
13:49:19
pjb
No, the length of the displaced array is the size of your window, it's unrelated to the size of the original array. Only it has to fit within.
13:50:23
phantomics
Got it, in my case I'm already storing the window dims and then just referencing them for every (adjust-array) invocation
13:50:52
phantomics
IIRC it also requires that I pass the :displaced-to each time even if it's the same as last time
13:52:02
Bike
adjust-array may not be super optimized, but if you give it an adjustable array it should at least be O(1). it looks like sbcl will inline adjust-array, but the inline body does a lot of checks
13:52:19
pjb
(adjust-array da (length da) :displaced-to (array-displacement da) :displaced-index-offset new-index)
13:52:41
phantomics
I don't know if it could optimize away doing the shape calculation if I'm keeping the same shape every time
13:53:26
pjb
(adjust-array da (array-dimensions da) :displaced-to (array-displacement da) :displaced-index-offset new-index)
13:54:01
phantomics
Could SBCL's compiler recognize the above code and optimize to just change the offset?
13:54:05
pjb
since they're accessors, you can consider the displaced array as an object or structure with the fields containing your pre-computed values.
13:55:39
Bike
it doesn't look like sbcl inlines unless the new dimensions are an integer. you might have to look deeper yeah...
13:57:44
phantomics
I see. Could be worth asking about. The window can't be a vector because the neural net I'm using requires a column as its input - it's a vector with 1 appended to its dims
14:00:49
Bike
i don't know how familiar you are with interpreting these, but the second lambda list with (array integer ...) indicates that this transform is only applied when the second argument is derived to be an integer. which it sounds like will not be the case for you.
14:10:11
pjb
phantomics: if you want to optimize, you could consider changing the order of the indices, so you can displace a vector.
14:12:57
phantomics
Bike: that's correct, I could see about modding the code that accepts it to handle vectors, but that gets into another realm of array stuff
14:14:07
phantomics
I could also render the big source array into a vector of X by 1 column arrays to save compute time, but that would be really wasteful of memory
14:33:52
Bike
phantomics: multidimensional arrays are probably not going to be as optimized as vectors generally. i would represent a column vector as a vector if at all possible.
16:34:44
Shinmera
jackdaniel: CLASS-PRECEDENCE-LIST may fail if the class has not been finalised yet.
16:37:50
jackdaniel
even if so, I'd still call finalize-inheritance and then class-precedence-list (for aesthetics if not anything else) - if the class can't be finalized compute will also fail miserably
16:39:16
Shinmera
in real code, sure. in the context it was originall suggested; just to look at the resulting precedence at the repl; idk.
16:40:31
jackdaniel
that's why I've said "if not aything else [but aesthetics]" ,) I agree that this does not matter (aesthetics aside) when you want to look at the resulting precedence at the repl
16:45:02
jackdaniel
(sufficienly clever implementation would call finalize-inheritance when the slot is unbound)
18:41:03
piethesailor
I am getting an error trying to parse the JSON I get from a succesful api call
18:43:06
jackdaniel
I doubt that any json parser wants to concern itself with encodings and coercing to a string
18:50:52
Bike
i have never used drakma, but i can look at its manual, and it says that :decode-content relies on the Content-Encoding header in the webpage. so maybe you're not getting one.
18:50:52
jackdaniel
the thing is that you pass a vector (not a stream nor a string) to parsing functions
18:52:06
Bike
if you know the encoding used by some other means (like guessing) you can do babel:octets-to-string or something.
18:53:45
piethesailor
I suppose drakma isnt really giving me json though now that I think about it, right? I am getting a vector, 200, and then a property list.
18:54:47
Bike
maybe this hasn't been made clear to you, but what's happening is that drakma is giving you the actual bytes it got over the wire. it cannot decode those into a string without knowing the character encoding those bytes were made with.
18:59:07
piethesailor
Bear with me, this might be a nonsensical statement.. So then the vector is just a bytes over the wire and the plist is the common lisp representation of those bytes?
18:59:50
jackdaniel
the first value is the result (be it a string or a byte vector that needs to be decoded if it is not binary)
19:03:14
Bike
oh, even better, RFC 8259 specifies that json in the wild must be utf-8, so i guess that's why you're not getting a header - you're supposed to assume that from the MIME
19:04:33
Bike
so yeah, just throw it at babel:octets-to-string and hopefully it will work out (pretty sure UTF-8 is the default for babel)
19:07:56
piethesailor
Yeah that works! So let me regurgitate somethings to make sure I am understanding everything..
19:10:42
piethesailor
The drakma script returned, as jackdaniel mentions, a vector of bytes that is utf-8 encoded, the http return code 200 or "ok", and then the http headers in the form of a plist.
19:14:08
jackdaniel
generally if you bind a result with (let ((result (call-function))) ...) then you bind only the first result
19:14:43
jackdaniel
but you may do (multiple-value-bind (result return-code plist) (call-function) ...) then if the function returns more values then they are bound
19:20:49
Bike
well - basically computers are creatures of arithmetic - they only know about numbers. when you "send text" over a line, what actually happens is that your text is encoded into a series of numbers which are actually sent. for example in ASCII or UTF-8, "A" becomes 65, whereas in EBCDIC "A" becomes 193.
19:21:05
Bike
In this case you have received a bunch of numbers, but without knowing how they were encoded, you can't get the corresponding text back.
19:21:30
Bike
(fsvo of "actually sent", since the numbers become electrical pulses, etc. irrelevant details)
19:28:37
piethesailor
Nice! Thanks for the explanation, Bike. I am curious though. I now have json from that babel:octets-to-string, which I have parsed with yason:parse. the result is a hash-table
19:33:36
piethesailor
how do I access the information in the hash table? I know I can click on #<HASH-TABLE :TEST EQUAL :COUNT 8 {10045A6943}> and emacs opens a buffer with the information pretty printed, but I am getting nil for (gethash 'results *my-hash*)
19:34:25
minion
piethesailor: please look at pcl: pcl-book: "Practical Common Lisp", an introduction to Common Lisp by Peter Seibel, available at http://www.gigamonkeys.com/book/ and in dead-tree form from Apress (as of 11 April 2005).
19:35:06
jackdaniel
generally you may map over hash table (maphash (lambda (key val) (format t "~s :: ~s~%" key val)) *hash-table*)
19:39:22
louis77
piethesailor: btw. you should be able to right click on the object in emacs and select "Inspect"... at will show you the contents of the hash table
19:42:15
piethesailor
Yes! That does work. I am thinking of how to access those data points with code. So far jackdaniels suggestion of maphash prints first level information like: ' "ticker" :: "AAPL" "queryCount" :: 1 "results" :: (#<HASH-TABLE :TEST EQUAL :COUNT 9 {10045A70F3}>) '
19:43:25
piethesailor
but I suppose I want to get information in "results" which is i guess another hash table
20:04:59
paulapatience
piethesailor: you may be interested in https://github.com/AccelerationNet/access to faciliate access to elements in nested hash tables (and other data structures)