Edit: My first serious language was Java, so I know Java. I know some very basic HTML and CSS, too. Very basic C as well.
The Big Programming Thread - Page 778
Forum Index > General Forum |
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. | ||
Shield
Bulgaria4824 Posts
Edit: My first serious language was Java, so I know Java. I know some very basic HTML and CSS, too. Very basic C as well. | ||
Deleted User 3420
24492 Posts
new question: my current project is making my own linked list the list is of generic type T do you guys have any ideas of special cases this kind of list may want to test for so that I can make sure I pass all the secret tests for my project? I am thinking: test my methods with an empty list test them with only 1 node testing remove where it doesn't have the element not really sure what else but this project grade is mostly based on secret tests so I am sure they have some sneaky stuff planned (I edited what was here so what Birdie and I am discussing isn't in here anymore) | ||
Birdie
New Zealand4438 Posts
Same for popping from your linked list,what happens to the popped node? | ||
Deleted User 3420
24492 Posts
for the array... I think it's the same situation? maybe someone can confirm. I think that our public classwide T[] array gets reassigned to the bigger array, and the temparray becomes garbage when the method ends. | ||
Blitzkrieg0
United States13132 Posts
| ||
Manit0u
Poland17182 Posts
Ensure that your add/removal methods return sane values - an updated list or true in case of success and false in case of failure would be just fine in my opinion (you could throw but I think that's overkill for the task at hand). You could experiment with fluent interfaces here for method chaining but then you'd have to resort to throws and try/catch blocks. | ||
Deleted User 101379
4849 Posts
On October 11 2016 07:52 Shield wrote: I'm currently focusing on C++ and C# because this is what I use at work. I can't see myself switching to front-end web work. I'm happy with doing back-end. Do you think I should learn more languages to improve my CV or is C++ and C# good enough? Edit: My first serious language was Java, so I know Java. I know some very basic HTML and CSS, too. Very basic C as well. There is never a reason not to learn new languages. All languages have their own little quirks and ways to solve problems that make you think in a new way about approaching problems even in the languages you already know and that makes you a better programmer in all languages. For example, a decade ago I already knew C, C++, Perl and a few other languages. Then I started dabbling in Scheme, a pure functional language, which changed the whole way I thought about program flow and state, which changed the way I programmed in the other languages. I started including functional programming paradigms in C, C++ and Perl to solve problems differently and better. If you are purely thinking about your CV then more languages is always better as well. Most companies have a mix of languages and, if you were able to maintain or fix the business critical Python or Perl script that someone wrote 5 years ago shortly before leaving the company where no one knows how it actually works, it could be a big increase in your hiring chances. | ||
teamamerica
United States958 Posts
On October 11 2016 06:31 maybenexttime wrote: So I translated my code from MATLAB to Python. I paste in below in case anyone would like to suggest some improvements: + Show Spoiler + #-- IMPORTS --# What profiling method would you recommend? I tried Spyder (Anaconda's native profiler). I couldn't find a way to save the analysis... From what I remember, the calculation took around 10 minutes, compared to roughly 3 minutes in MATLAB (and around 1-2 minutes in the software I am basing my analysis on). What stood out was that show(), while being called only once, took something like 280 seconds to finish. I also tried using cProfile, but I am not sure how to read the output file. It's some gibberish when saved as .txt, and when read printed inside cmd, it's way too long and much of it is lost. If I understand the output correctly, the total calculation time as measured by cPython is only 5 minutes. Is it possible that Spyder is adding that much overhead? .show() in a script will be this blocking call...I'm not sure if you're calling your script from command line (or where you're running it) but as a script I'd recommend you call `.show(block=False)`, otherwise it just blocks there. There's some things I'd say about your code formatting, magic constants, redundant comments, renaming variables, but tbh if you have a different background maybe this is just your normal and works quickest for you. As to speed I'd wonder if there's any operations in calculate_variance you can pull out of the inner inner loops. Depending on your python version you can use xrange instead of range (if in 2, xrange is better for the way you're using), some of your array use seems unnecessary. For example for `wavelet_transform` you only ever seem to access the current scalar value so you can use arrays there. You can get marginal gains out of stuff like numpy.empty vs .zeros for some of the arrays you fill yourself, use of numpy.sum vs sum. It doesn't seem like there's any duplicate work you can pull out to out of some of the inner loops but I don't understand fundamentally what is going on. My 2cents.. | ||
Acrofales
Spain17821 Posts
On October 11 2016 12:13 Manit0u wrote: The only really tricky part I can see in this task is possible need for reindexing the list when you remove something from it or add something to the beginning. You should definitely test for that. Also, make sure you don't go out of bounds or don't get otherwise illegal indices (or that you end up with an infinite self-referencing loop inside). Ensure that your add/removal methods return sane values - an updated list or true in case of success and false in case of failure would be just fine in my opinion (you could throw but I think that's overkill for the task at hand). You could experiment with fluent interfaces here for method chaining but then you'd have to resort to throws and try/catch blocks. I'm confused. If the assignment is to implement a linked list, then why are you giving advice on arrays. You can sure make a data structure that uses an array under the hood look like a linked list, but it fundamentally won't be: they are 2 different ways of storing lists of data. An array is a single pointer, which you increment. In a linked list you keep "replacing" the head (or tail) pointer (implementation doesn't require both, but it's virtually free) when you add or remove nodes. Youn never have to resize any underlying arrays, because you don't have one. You have a next (or previous) pointer for each node. See it like this: an array is a filing cabinet with a fixed size. A linked list is a treasure hunt: every data point comes with a "clue" on where to find the next data point. There is no upfront limit to how many data points you chain together in the data structure. Here is a decent answer for the advantages and disadvantages of linked lists vs. arrays: http://stackoverflow.com/questions/393556/when-to-use-a-linked-list-over-an-array-array-list In particular the "not wanting random access" is very often a deal breaker. As for his final advantage (inserting into the middle). It's better in a linked list than in an array, but it's still not ideal. The "best" implementation of a priority queue is still in a heap, which has O(log n) insert instead of O(n) in a linked list. A heap can be implemented in different ways, but most modern libraries use arrays as the underlying data structure for this. As for what are obvious tests for a linked list: you mentioned a couple, but also test for calling next on the last node, or previous on the first. Were you given access time specifications? Add and delete on the front and end are an easy O(1), which is the main advantage of linked lists. However, any kind of get from the middle of a linked list is O(n), as is adding/deleting from an arbitrary index. Naïve implementation of size is also O(n), but you can maintain the information about size separately to make it O(1). | ||
maybenexttime
Poland5411 Posts
On October 11 2016 15:25 teamamerica wrote: .show() in a script will be this blocking call...I'm not sure if you're calling your script from command line (or where you're running it) but as a script I'd recommend you call `.show(block=False)`, otherwise it just blocks there. First of all, thanks! I am running the script in Spyder, an external program. I don't know how spider runs the script, though. I will see whether your suggestion helps. edit: It worked! I still have no idea what blocking calls are. I will read about that. (The code still takes almost 2 minutes longer than MATLAB's.) There's some things I'd say about your code formatting, magic constants, redundant comments, renaming variables, but tbh if you have a different background maybe this is just your normal and works quickest for you. Well, I don't have any background, to be honest, aside from one semester of MATLAB fundamentals. I am learning Python and MATLAB, as well as programming in general. Any suggestions regarding formatting are appreciated. I have no idea what magic constants are... As for redundant comments and variable renaming, they are vestiges of my MATLAB code (variable renaming was used for variable slicing, e.g.). I didn't have time to clean this up. As to speed I'd wonder if there's any operations in calculate_variance you can pull out of the inner inner loops. Depending on your python version you can use xrange instead of range (if in 2, xrange is better for the way you're using), some of your array use seems unnecessary. For example for `wavelet_transform` you only ever seem to access the current scalar value so you can use arrays there. You can get marginal gains out of stuff like numpy.empty vs .zeros for some of the arrays you fill yourself, use of numpy.sum vs sum. It doesn't seem like there's any duplicate work you can pull out to out of some of the inner loops but I don't understand fundamentally what is going on. My 2cents.. I am using Python 3. I have some ideas regarding moving some operations to outer loops/vectorization (based on my failed attempts in MATLAB - might work in Python, perhaps), but first I'd like to figure out why what is basically identical code in MATLAB and Python runs so much slower in Python. I will try using np.sum and np.empty instead. i am not sure what you mean regarding `wavelet_transform`. Could you elaborate? I am recreating this analysis: http://rosenberglab.net/Pubs/JVegSci2004v15p277.pdf I am basically dividing point data into transects, and checking how closely point spacing of in a given transect matches a wavelet template. I am doing this for all 180 degrees (180 transects, created with a step of 1 degree), and then averaging it over 45 transect widths (from 1 degree to 45 degrees), and averaging all of this over all focal points (a focal point is a point somewhere in the middle; the space is cut into transects around it). | ||
Acrofales
Spain17821 Posts
In addition, you might get speedups by using pythonic syntax (iterators and generators), which is heavily optimized in the python engine, but I haven't looked at your code at all. | ||
Manit0u
Poland17182 Posts
Could someone tell me why the hell this script sourcing attempt fails inside the image? Edit: For some reason tl.net still puts url tags inside the code blocks. I'll let R1ch know about it. | ||
Ropid
Germany3557 Posts
| ||
Manit0u
Poland17182 Posts
On October 11 2016 19:42 Ropid wrote: When you try it on the prompt, that's bash sourcing it which is different from /bin/sh on Debian. Perhaps the script uses bash features which don't work in sh? Is there any way around it? I'm pretty new to this whole docker shabang... My current dockerfile I'm trying to build: + Show Spoiler +
The bash script that's failing on the image: https://github.com/StanAngeloff/vagrant-shell-scripts/blob/master/ubuntu.sh | ||
Manit0u
Poland17182 Posts
This works just fine. | ||
Nesserev
Belgium2760 Posts
| ||
Djagulingu
Germany3605 Posts
On October 11 2016 20:48 Nesserev wrote: Because you're using the source command to run 'ubuntu.sh', the script is executed in the current shell, which seems to be regular old sh based on the error you got, which cannot interpret the script, which was written for bash. Yeah, Dockerfile builds still use ye olde /bin/sh. You should say /bin/bash /root/ubuntu.sh instead of /root/ubuntu.sh. | ||
![]()
TheEmulator
28078 Posts
![]() | ||
JWD[9]
364 Posts
Programming: Principles and Practice Using C++ Second Edition Bjarne Stroustrup
It is a vector, that provides an overloaded push_back function. If it is given a pointer, it assumes ownership, so you can push_back "new" objects and not worry about delete. Why is there a constructor declared and not defined though? What could have been it's original purpose?
| ||
Nesserev
Belgium2760 Posts
| ||
| ||