Re: [julia-users] Re: How to convert a cell type to array type?
Thanks for the advice I tried to find an original function in order to guarantee its speed. I thought the for loops written by me could not compare with that since seemlingly I made no performance effort. Do you mean the speed of for loops in Julia without other improvement can compete with C's? But even so does it mean it can compete with Matlab in this case(pure matrix operation)? On Sunday, September 21, 2014 5:32:48 PM UTC+8, Tim Holy wrote: Feel free to write one! Unlike Matlab, you don't have to descend into C to provide basic functionality; a pair of loops will often suffice. I suspect this may be the main reason there isn't a cell2mat in base, it's usually easy enough (and often clearer, with fewer trips needed to read documentation) to do what you want directly. However, cell2mat does keep coming up. By all means, take a stab at the general problem, and then post as a package or submit to base and see if folks are interested. (I'd start with the standalone option, though.) --Tim On Sunday, September 21, 2014 01:38:25 AM Staro Pickle wrote: Thank you for help. I have checked the docs, no direct substitution for cell2mat :( On Sunday, September 21, 2014 1:01:22 PM UTC+8, Don MacMillen wrote: I haven't seen it, but that doesn't mean it's not there. Maybe time to hit readthedocs? On Saturday, September 20, 2014 9:48:02 PM UTC-7, Staro Pickle wrote: There is no automatic way, like the cell2mat command in matlab? On Sunday, September 21, 2014 12:42:44 PM UTC+8, Don MacMillen wrote: short answer is hvcat((2,2), A...) but make certain it is doing the concatenation in the order you really want, else call it out specifically as hvcat((2,2), A[2,1], A[1,1], A[2,2], A[1,2]) for example. On Saturday, September 20, 2014 8:34:32 PM UTC-7, Staro Pickle wrote: I define a matrix using cell, like: A = cell(2,2) b = ones(2,2) A[1,1] = b A[1,2] = b A[2,1] = b A[2,2] = b Then I want to make A a 4*4 2-D array: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 How to do this?
Re: [julia-users] Re: How to convert a cell type to array type?
Yes, C code transliterated into Julia typically run within 2x of the original. There are some of corner cases though, where Julia has safer semantics that slow down execution. Julia checks that when you access a legal part of an array when you index it. The @inbounds macro can give you the segfaults and speed associated with C. Another common problem is that the C program use a different library, so we get comparisons between the libraries, not the languages. Julia is currently not very smart about memory management, but if you manage to write the performance critical parts of your code allocation free, that does not tax your execution time much. Matlab is a old language where lots of smart people have spent much time on recognizing problem patterns and doing lots of tricks under the hood so that it appears to run fast. Writing fast Matlab is about knowing these patterns that get recognized and exploit them. When matlab recognizes your problem, and swaps in a hand tuned implementation, it is hard to compete. kl. 09:56:06 UTC+2 mandag 22. september 2014 skrev Staro Pickle følgende: Thanks for the advice I tried to find an original function in order to guarantee its speed. I thought the for loops written by me could not compare with that since seemlingly I made no performance effort. Do you mean the speed of for loops in Julia without other improvement can compete with C's? But even so does it mean it can compete with Matlab in this case(pure matrix operation)? On Sunday, September 21, 2014 5:32:48 PM UTC+8, Tim Holy wrote: Feel free to write one! Unlike Matlab, you don't have to descend into C to provide basic functionality; a pair of loops will often suffice. I suspect this may be the main reason there isn't a cell2mat in base, it's usually easy enough (and often clearer, with fewer trips needed to read documentation) to do what you want directly. However, cell2mat does keep coming up. By all means, take a stab at the general problem, and then post as a package or submit to base and see if folks are interested. (I'd start with the standalone option, though.) --Tim On Sunday, September 21, 2014 01:38:25 AM Staro Pickle wrote: Thank you for help. I have checked the docs, no direct substitution for cell2mat :( On Sunday, September 21, 2014 1:01:22 PM UTC+8, Don MacMillen wrote: I haven't seen it, but that doesn't mean it's not there. Maybe time to hit readthedocs? On Saturday, September 20, 2014 9:48:02 PM UTC-7, Staro Pickle wrote: There is no automatic way, like the cell2mat command in matlab? On Sunday, September 21, 2014 12:42:44 PM UTC+8, Don MacMillen wrote: short answer is hvcat((2,2), A...) but make certain it is doing the concatenation in the order you really want, else call it out specifically as hvcat((2,2), A[2,1], A[1,1], A[2,2], A[1,2]) for example. On Saturday, September 20, 2014 8:34:32 PM UTC-7, Staro Pickle wrote: I define a matrix using cell, like: A = cell(2,2) b = ones(2,2) A[1,1] = b A[1,2] = b A[2,1] = b A[2,2] = b Then I want to make A a 4*4 2-D array: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 How to do this?
Re: [julia-users] Re: How to convert a cell type to array type?
On Monday, September 22, 2014 02:23:59 AM Ivar Nesje wrote: When matlab recognizes your problem, and swaps in a hand tuned implementation, it is hard to compete. I disagree; it may be hard to do _better_, but it's not usually hard to compete. At least in my own tests, I'm mildly offended :-) when Matlab gets within a factor of 2 of my own Julia code, even when I know Matlab is doing much/all of the work in C. See a recent example: https://github.com/timholy/Images.jl/issues/69#issuecomment-56296037. --Tim
[julia-users] Re: How to convert a cell type to array type?
Thank you for help. I have checked the docs, no direct substitution for cell2mat :( On Sunday, September 21, 2014 1:01:22 PM UTC+8, Don MacMillen wrote: I haven't seen it, but that doesn't mean it's not there. Maybe time to hit readthedocs? On Saturday, September 20, 2014 9:48:02 PM UTC-7, Staro Pickle wrote: There is no automatic way, like the cell2mat command in matlab? On Sunday, September 21, 2014 12:42:44 PM UTC+8, Don MacMillen wrote: short answer is hvcat((2,2), A...) but make certain it is doing the concatenation in the order you really want, else call it out specifically as hvcat((2,2), A[2,1], A[1,1], A[2,2], A[1,2]) for example. On Saturday, September 20, 2014 8:34:32 PM UTC-7, Staro Pickle wrote: I define a matrix using cell, like: A = cell(2,2) b = ones(2,2) A[1,1] = b A[1,2] = b A[2,1] = b A[2,2] = b Then I want to make A a 4*4 2-D array: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 How to do this?
[julia-users] Re: How to convert a cell type to array type?
perhaps this? *cell2mat(A)=hvcat(size(A),reshape(A,*(size(A)...))...)*
[julia-users] Re: How to convert a cell type to array type?
short answer is hvcat((2,2), A...) but make certain it is doing the concatenation in the order you really want, else call it out specifically as hvcat((2,2), A[2,1], A[1,1], A[2,2], A[1,2]) for example. On Saturday, September 20, 2014 8:34:32 PM UTC-7, Staro Pickle wrote: I define a matrix using cell, like: A = cell(2,2) b = ones(2,2) A[1,1] = b A[1,2] = b A[2,1] = b A[2,2] = b Then I want to make A a 4*4 2-D array: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 How to do this?
[julia-users] Re: How to convert a cell type to array type?
There is no automatic way, like the cell2mat command in matlab? On Sunday, September 21, 2014 12:42:44 PM UTC+8, Don MacMillen wrote: short answer is hvcat((2,2), A...) but make certain it is doing the concatenation in the order you really want, else call it out specifically as hvcat((2,2), A[2,1], A[1,1], A[2,2], A[1,2]) for example. On Saturday, September 20, 2014 8:34:32 PM UTC-7, Staro Pickle wrote: I define a matrix using cell, like: A = cell(2,2) b = ones(2,2) A[1,1] = b A[1,2] = b A[2,1] = b A[2,2] = b Then I want to make A a 4*4 2-D array: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 How to do this?
[julia-users] Re: How to convert a cell type to array type?
I haven't seen it, but that doesn't mean it's not there. Maybe time to hit readthedocs? On Saturday, September 20, 2014 9:48:02 PM UTC-7, Staro Pickle wrote: There is no automatic way, like the cell2mat command in matlab? On Sunday, September 21, 2014 12:42:44 PM UTC+8, Don MacMillen wrote: short answer is hvcat((2,2), A...) but make certain it is doing the concatenation in the order you really want, else call it out specifically as hvcat((2,2), A[2,1], A[1,1], A[2,2], A[1,2]) for example. On Saturday, September 20, 2014 8:34:32 PM UTC-7, Staro Pickle wrote: I define a matrix using cell, like: A = cell(2,2) b = ones(2,2) A[1,1] = b A[1,2] = b A[2,1] = b A[2,2] = b Then I want to make A a 4*4 2-D array: 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 1.0 How to do this?