Re: FileNotFoundException (Access is denied)
Robert Campbell napisał(a): > I'm trying to write a file scanner very similar to the one on page 131 > of Stuart's book: > > (ns user > (:use [clojure.contrib.duck-streams :only [reader]])) > > (defn scan [dir] > (for [file (file-seq dir)] > (with-open [rdr (reader file)] > (count (filter #(re-find #"foobar" %) (line-seq rdr)) > > user> (scan (java.io.File. "C:/SomeValidDir")) > > java.lang.RuntimeException: java.io.FileNotFoundException: > C:\publishing\cosmos\trunk\web (Access is denied) (NO_SOURCE_FILE:0) > > The strange part: > > user> (file-seq (java.io.File. "C:/SomeValidDir")) > ( # #) > and so on, properly listing the entire contents of the directory. > > user> (for [file (file-seq (java.io.File. > "C:/publishing/cosmos/trunk/web"))] nil) > (nil nil) and so on, again working properly. > > user> (for [file (file-seq (java.io.File. > "C:/publishing/cosmos/trunk/web"))] (with-open [rdr (reader file)] > nil)) > ; Evaluation aborted. (this one finally fails with the same error) > > So "with-open [rdr (reader file)]" is the problem, but why? I guess "reader" does not work for directories. Try to change your "for" loop like this: (for [file (file-seq dir) :when (.isFile file)] HTH, Rob -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: FileNotFoundException (Access is denied)
Thank you, that was the problem. I wonder if Stuart should change this line: (defn clojure-source? [file] (.endsWith (.toString file) ".clj" )) to this: (defn clojure-source? [file] (and (.isFile file) (.endsWith (.toString file) ".clj" ))) just to make sure directories like "myproj.clj" don't throw an error. I suppose that's being excessively safe for what's meant to be a simple example. On Thu, Nov 26, 2009 at 9:43 AM, Rob Wolfe wrote: > > > Robert Campbell napisał(a): >> I'm trying to write a file scanner very similar to the one on page 131 >> of Stuart's book: >> >> (ns user >> (:use [clojure.contrib.duck-streams :only [reader]])) >> >> (defn scan [dir] >> (for [file (file-seq dir)] >> (with-open [rdr (reader file)] >> (count (filter #(re-find #"foobar" %) (line-seq rdr)) >> >> user> (scan (java.io.File. "C:/SomeValidDir")) >> >> java.lang.RuntimeException: java.io.FileNotFoundException: >> C:\publishing\cosmos\trunk\web (Access is denied) (NO_SOURCE_FILE:0) >> >> The strange part: >> >> user> (file-seq (java.io.File. "C:/SomeValidDir")) >> ( # #) >> and so on, properly listing the entire contents of the directory. >> >> user> (for [file (file-seq (java.io.File. >> "C:/publishing/cosmos/trunk/web"))] nil) >> (nil nil) and so on, again working properly. >> >> user> (for [file (file-seq (java.io.File. >> "C:/publishing/cosmos/trunk/web"))] (with-open [rdr (reader file)] >> nil)) >> ; Evaluation aborted. (this one finally fails with the same error) >> >> So "with-open [rdr (reader file)]" is the problem, but why? > > I guess "reader" does not work for directories. Try to change your > "for" loop like this: > (for [file (file-seq dir) :when (.isFile file)] > > HTH, > Rob > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Atomic reloads and snapshots of namespaces
My web application needs updates from time to time. When this happens I often have to stop the server and shut down the JVM. Then the old (current) directories can be replaced by the new ones, and I restart the server. It's okay when there are several copies of the server running behind a load balancer. This allows updates while the service is available. I would like to ask what other ways there are for updating services. One idea could be to reload a namespace? The application could offer a way for an admin to kick of a reload of a given namespace. Two problems I see: 1) On the dev machine I make the changes and (compile ...) the system. On the live machine there already exist .class files with the same name, or at least with a very similar name. I don't know if there could be naming conflicts, and in such a case the OS might now allow me to overwrite a .class file, as it is in use currently. Even if compile produces files with new names (other number suffixes or something like that) this could end up in a mess. 2) And even if we can manage point 1) there is still the problem with atomicity. Or not? I imagine a chain of n functions. Callers or callees may expect different args. I would like to update the whole namespace as one unit. Maybe this already works in Clojure? One more question: could it make sense to have a reload function which first saves the whole namespace (by referencing all toplevel vars and functions in that ns), then atomically reloads the namespace from a given path on disk (containing all .class files) and finally returns the old instances of the ns? My idea behind this was: when a web server starts a request then some threads could still want to continue to execute functions of the old ns because they did not finish their request. Or there could be still an open session for some users which requirs that as long this session exists these specific users are served with the previous functions, from before the update. This sounds a bit like making snapshots and transactions over a namespace. Please let me know what you think about it, if this makes sense or would only cause too many problems, or if it won't work, etc. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Atomic reloads and snapshots of namespaces
I would appreciate, in a similar vein, an amplification of the "Use with caution" advice in the api docs for remove-ns. I'd like to use remove-ns but am reluctant to architect a system around a function marked 'use with caution' (remove-ns sym) Removes the namespace named by the symbol. Use with caution. Cannot be used to remove the clojure namespace. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Atomic reloads and snapshots of namespaces
> 2) And even if we can manage point 1) there is still the problem > with atomicity. Or not? > I imagine a chain of n functions. Callers or callees may expect > different args. I would like to update the whole namespace as > one unit. Maybe this already works in Clojure? There was a discussion on this topic back in September, titled "Fixing production systems on-the-fly". I wrote then: "Re consistency: I seem to recall Pascal Costanza working on activation of layers, so you can swap a whole set of stuff across your program. He spoke about it at ILC2009, but I'm not sure I've found the right paper. Common Lisp-specific, though." He showed a website, paused mid-request, where he swapped out several functions. Unpausing the request still ran to completion with the old functions. A new request ran with the new functions. Impressive. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Space leak with lazy sequences.
I'm writing some fairly complex code involving lazy sequences. I appear to be getting a space leak from what looks like something that is still holding a reference to the head of the sequence. Does anyone have any advice on how to go about finding this? Are there any JVM tools that might perchance tell me, for example, what classes are near the root of the largest groups of objects in memory. I guess I needed something to make me feel like I was programming in Haskell again. Thanks, David -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Space leak with lazy sequences.
On Thu, Nov 26, 2009 at 02:50:09PM -0800, David Brown wrote: >I'm writing some fairly complex code involving lazy sequences. I >appear to be getting a space leak from what looks like something that >is still holding a reference to the head of the sequence. Ok, I found the leak. I guess I'd call it a compiler problem. I haven't been able to narrow it down any further than the code below (any simpler, and it doesn't cause the problem). Basically, the with-open causes the generation of a closure which captures the value of 'coll', which it hangs onto throughout the lifetime of the call to 'write-mapping' which is what walks through the entire collection. For now, I'll do without the with-open, since in this particular case, errors are going to be fairly fatal anyway. Should I file a ticket about this? I'm running 1.1.0-alpha-SNAPSHOT, 20091113040146, from build.clojure.org. David Brown ;; (ns leak1) (import '[java.io FileOutputStream BufferedOutputStream DataOutputStream]) (defn make-name [& _]) (defn make-tmp-name [& _]) (defn store-properties [& _]) (defn write-mapping [& _]) (defn get-codec [& _]) (defn raise[& _]) (def error nil) ;;; The generated code creates a 'fn' class for the body of the ;;; with-open. This class binds several of the names, including ;;; 'coll', which it keeps through the lifetime of the function. (defn- store-index-file [index idx props coll] (let [path (make-name index idx) tmp-path (make-tmp-name path) fos (FileOutputStream. tmp-path) bos (BufferedOutputStream. fos)] (with-open [dos (DataOutputStream. bos)] (store-properties dos (assoc props :version "1.0")) (write-mapping dos (get-codec index) coll) (.flush bos) ;; Calls fsync to make sure data gets written to disk. (.force (.getChannel fos) true)) (when-not (.renameTo tmp-path path) (raise error (str "Unable to rename pool index file:" tmp-path " to " path) ;; -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Space leak with lazy sequences.
On Thu, Nov 26, 2009 at 04:00:34PM -0800, David Brown wrote: >For now, I'll do without the with-open, since in this particular case, >errors are going to be fairly fatal anyway. BTW, I still haven't been able to figure out how to write this function without hanging onto the collection across the call to 'write-mapping'. Any ideas? >;; >(ns leak1) >(import '[java.io FileOutputStream BufferedOutputStream DataOutputStream]) > >(defn make-name [& _]) >(defn make-tmp-name [& _]) >(defn store-properties [& _]) >(defn write-mapping [& _]) >(defn get-codec [& _]) >(defn raise[& _]) >(def error nil) > >;;; The generated code creates a 'fn' class for the body of the >;;; with-open. This class binds several of the names, including >;;; 'coll', which it keeps through the lifetime of the function. >(defn- store-index-file > [index idx props coll] > (let [path (make-name index idx) > tmp-path (make-tmp-name path) > fos (FileOutputStream. tmp-path) > bos (BufferedOutputStream. fos)] > (with-open [dos (DataOutputStream. bos)] > (store-properties dos (assoc props :version "1.0")) > (write-mapping dos (get-codec index) coll) > (.flush bos) > ;; Calls fsync to make sure data gets written to disk. > (.force (.getChannel fos) true)) > (when-not (.renameTo tmp-path path) > (raise error > (str "Unable to rename pool index file:" tmp-path " to " > path) >;; -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Space leak with lazy sequences.
On Thu, Nov 26, 2009 at 05:05:17PM -0800, David Brown wrote: >On Thu, Nov 26, 2009 at 04:00:34PM -0800, David Brown wrote: > >>For now, I'll do without the with-open, since in this particular case, >>errors are going to be fairly fatal anyway. > >BTW, I still haven't been able to figure out how to write this >function without hanging onto the collection across the call to >'write-mapping'. Ugh, I have found a very ugly hack that works. It seems that the compiler only nulls out locals before a call in the tail position, even if earlier calls don't reference the value any more. So, I went down in my call-chain to the first function that uses the sequence directly (in a doseq), and do something like this: (let [real-coll @coll] (swap! coll (constantly nil)) (doseq [item real-coll] ...)) I just have to wrap the collection in an atom up where I create it, and make sure I never keep a reference to it around. David -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Atomic reloads and snapshots of namespaces
On Nov 26, 7:39 pm, Richard Newman wrote: > "Re consistency: I seem to recall Pascal Costanza working on > activation of layers, so you can swap a whole set of stuff across your > program. He spoke about it at ILC2009, but I'm not sure I've found the > right paper. Common Lisp-specific, though." > > He showed a website, paused mid-request, where he swapped out several > functions. Unpausing the request still ran to completion with the old > functions. A new request ran with the new functions. Impressive. CLOS and the MOP allows you to change a class and have all already existing instances be transformed into the new form (in an automatic or user defined way), which makes these things much easier to achieve than in Java- and Clojure-world. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: Question about future
On Thu, Nov 26, 2009 at 2:11 AM, Christophe Grand wrote: > On Thu, Nov 26, 2009 at 8:05 AM, Robert Campbell wrote: > >> If you have this: >> >> user> (def f (future (Thread/sleep 2) :done)) >> #'user/f >> user> @f ; this immediate deref blocks for 20 sec, finally returning >> :block >> :done >> user> @f ; returns immediately >> :done >> >> What is actually happening when you call the first @f? You are waiting >> for the function to finish executing and return a value? Or are you >> waiting for a return value to appear in the ref slot? >> >> Is there any way to check if there is a value ready or if the function >> has returned w/out blocking? >> > > future-done? > Why isn't this on the api page? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: A Clojure Highlife
Thanks for sharing this. Coincidentally, I just wrote my first Clojure program which was... an implementation of Conway's Game of Life :-) I took a different approach - I represented the board as a vector of vectors of integers (1 for alive, 0 for dead) and then implemented a new-board function that takes a board as an argument and returns the next generation of that board. It seemed the functional way to do it. I then create an atom whose state is a grid and repeatedly call (swap! board new-board) in order to move it through the generations. I'll copy the source to my little program at the bottom of this email. If anyone has any comments on the style or possible improvements then I would be very interested to hear them. I'm particularly keen to hear how close to idiomatic Clojure style it is (is there a Clojure equivalent of the adjective "Pythonic"?) (import '(java.awt Color Graphics Dimension FlowLayout) '(javax.swing JPanel JFrame JButton Timer BoxLayout) '(java.awt.event MouseListener ActionListener ActionEvent)) (set! *warn-on-reflection* true) (def width 50) (def height 20) (def cell-width 10) (def cell-height 10) (def sleep-time 100) (def initial-board ; (apply vector (replicate height ; (apply vector (replicate width 0) [[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 1 1 0 1 0 0 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] [0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]]) (def board-atom (atom initial-board )) (def running-atom (atom false)) ;; Board manipulation functions (defn print-board [b] (doseq [row b] (println (str row (defn within [v min max] (and (>= v min) (< v max))) (defn cell-at [b x y] (if (and (within x 0 width) (within y 0 height)) (nth (nth b y) x) 0)) (defn occurences [l item] (count (filter #(= % item) l))) (defn new-cell-value [cell neighbours] (let [num-1s (occurences neighbours 1)] (if (= cell 0) ; cell is currently dead and will become alive iff it has 3 living ; neighbours (if (= num-1s 3) 1 0) ; else cell is currently alive and will die iff it has fewer than 2 or ; more than 3 living neighbours (if (or (< num-1s 2) (> num-1s 3)) 0 1 (defn cell-neighbours [b x y] [(cell-at b (- x 1) (- y 1)) (cell-at b x (- y 1)) (cell-at b (+ x 1) (- y 1)) (cell-at b (- x 1) y) (cell-at b (+ x 1) y) (cell-at b (- x 1) (+ y 1)) (cell-at b x (+ y 1)) (cell-at b (+ x 1) (+ y 1))]) (defn new-value-at [b x y] (let [cell (cell-at b x y) neighbours (cell-neighbours b x y)] (new-cell-value cell neighbours))) (defn new-board [b] (vec (for [y (range height)] (vec (for [x (range width)] (new-value-at b x y)) (defn flip-cell [b x y] (let [row (nth b y) cell (nth row x) new-cell (- 1 cell) new-row (assoc row x new-cell)] (assoc b y new-row))) (defn apply-n-times [f n x] (if (zero? n) x (recur f (dec n) (f x ;; GUI functions (defn make-action-listener [f] (proxy [ActionListener] [] (actionPerformed [e] (f e (defn render [#^Graphics g b] (doseq [y (range heigh
Re: performance issues with multi-dimensional array
I did, and it works like a charm. Couldn't figure out how to hint an array of objects (what should I put instead of the old #^objects? I still get it to work in 300 ms (which is not great but something I can live with). Thanks for the replies, On Nov 25, 8:01 pm, David Nolen wrote: > Read Christophe's post about multi-dim arrays. Reflection is getting in the > way here. > > > > On Wed, Nov 25, 2009 at 2:55 AM, Amnon wrote: > > Hi Konrad, > > In the original post, I put in the code, it was removed by the post > > editor. > > The way I wanted it implement, I have the main in java (gui and > > stuff). I create a 3D array in java, it's an int array (i.e. int arr[] > > [][] ) and call with that array to clojure. > > > It can be done in java at least 3 orders of magnitude faster so I'm > > sure there is something I'm doing wrong. > > I'll appreciate any suggestion. > > Thanks, > > Amnon > > > I've squeezed my example into two functions: > > > (defn light [arr x y] > > (+ (aget arr x y 0) (aget arr x y 1) (aget arr x y 2)) > > ) > > > (defn grey [arr] > > (dotimes [x (length arr)] > > (dotimes [y (alength (aget arr 0))] > > (let [lg (int (/ (light arr x y) 3))] > > (aset arr x y 0 lg) > > (aset arr x y 1 lg) > > (aset arr x y 2 lg) > > > > > On Nov 24, 8:35 pm, Konrad Hinsen wrote: > > > On 24 Nov 2009, at 17:30, Amnon wrote: > > > > > I hope it's not the billion time you get the question. > > > > I wanted to use clojure for image processing. I have a 3 dimensional > > > > array I'm passing to clojure from java. > > > > I then loop on the array to manipulate it. > > > > Even the simplest task takes about half a minutes (I expected it to be > > > > over in less than a second) > > > > Could you give some more details? For example, what is the Java class > > > you use for the 3D arrays? How are you accessing it from Clojure? How > > > do you do the loops? How do you create the destination array, and how > > > do you fill it with the grey-scale values? I suspect that many of > > > these steps could be optimized, but it's hard to say without knowing > > > how your current code works. > > > > Konrad. > > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clojure@googlegroups.com > > Note that posts from new members are moderated - please be patient with > > your first post. > > To unsubscribe from this group, send email to > > clojure+unsubscr...@googlegroups.com > > > > For more options, visit this group at > >http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en
Re: performance issues with multi-dimensional array
Check out this thread: http://groups.google.com/group/clojure/browse_frm/thread/4c52d4c3c19201b6/dd80d5e5bde4dc61 On Thu, Nov 26, 2009 at 4:49 AM, Amnon wrote: > I did, and it works like a charm. Couldn't figure out how to hint an > array of objects (what should I put instead of the old #^objects? > I still get it to work in 300 ms (which is not great but something I > can live with). > Thanks for the replies, > > On Nov 25, 8:01 pm, David Nolen wrote: > > Read Christophe's post about multi-dim arrays. Reflection is getting in > the > > way here. > > > > > > > > On Wed, Nov 25, 2009 at 2:55 AM, Amnon wrote: > > > Hi Konrad, > > > In the original post, I put in the code, it was removed by the post > > > editor. > > > The way I wanted it implement, I have the main in java (gui and > > > stuff). I create a 3D array in java, it's an int array (i.e. int arr[] > > > [][] ) and call with that array to clojure. > > > > > It can be done in java at least 3 orders of magnitude faster so I'm > > > sure there is something I'm doing wrong. > > > I'll appreciate any suggestion. > > > Thanks, > > > Amnon > > > > > I've squeezed my example into two functions: > > > > > (defn light [arr x y] > > >(+ (aget arr x y 0) (aget arr x y 1) (aget arr x y 2)) > > >) > > > > > (defn grey [arr] > > >(dotimes [x (length arr)] > > >(dotimes [y (alength (aget arr 0))] > > >(let [lg (int (/ (light arr x y) 3))] > > >(aset arr x y 0 lg) > > >(aset arr x y 1 lg) > > >(aset arr x y 2 lg) > > > > > > > > On Nov 24, 8:35 pm, Konrad Hinsen wrote: > > > > On 24 Nov 2009, at 17:30, Amnon wrote: > > > > > > > I hope it's not the billion time you get the question. > > > > > I wanted to use clojure for image processing. I have a 3 > dimensional > > > > > array I'm passing to clojure from java. > > > > > I then loop on the array to manipulate it. > > > > > Even the simplest task takes about half a minutes (I expected it to > be > > > > > over in less than a second) > > > > > > Could you give some more details? For example, what is the Java class > > > > you use for the 3D arrays? How are you accessing it from Clojure? How > > > > do you do the loops? How do you create the destination array, and > how > > > > do you fill it with the grey-scale values? I suspect that many of > > > > these steps could be optimized, but it's hard to say without knowing > > > > how your current code works. > > > > > > Konrad. > > > > > -- > > > You received this message because you are subscribed to the Google > > > Groups "Clojure" group. > > > To post to this group, send email to clojure@googlegroups.com > > > Note that posts from new members are moderated - please be patient with > > > your first post. > > > To unsubscribe from this group, send email to > > > clojure+unsubscr...@googlegroups.com > > > > > For more options, visit this group at > > >http://groups.google.com/group/clojure?hl=en > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en