• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 09:33
CET 14:33
KST 22:33
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Team Liquid Map Contest #22 - Presented by Monster Energy5ByuL: The Forgotten Master of ZvT30Behind the Blue - Team Liquid History Book19Clem wins HomeStory Cup 289HomeStory Cup 28 - Info & Preview13
Community News
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool29Weekly Cups (March 9-15): herO, Clem, ByuN win32026 KungFu Cup Announcement6BGE Stara Zagora 2026 cancelled12Blizzard Classic Cup - Tastosis announced as captains18
StarCraft 2
General
Blizzard Classic Cup @ BlizzCon 2026 - $100k prize pool Team Liquid Map Contest #22 - Presented by Monster Energy Serral: 24’ EWC form was hurt by military service Weekly Cups (March 9-15): herO, Clem, ByuN win Weekly Cups (August 25-31): Clem's Last Straw?
Tourneys
RSL Season 4 announced for March-April Sparkling Tuna Cup - Weekly Open Tournament WardiTV Team League Season 10 KSL Week 87 [GSL CK] #2: Team Classic vs. Team Solar
Strategy
Custom Maps
Publishing has been re-enabled! [Feb 24th 2026] Map Editor closed ?
External Content
The PondCast: SC2 News & Results Mutation # 517 Distant Threat Mutation # 516 Specter of Death Mutation # 515 Together Forever
Brood War
General
Gypsy to Korea ASL21 General Discussion JaeDong's form before ASL BGH Auto Balance -> http://bghmmr.eu/ BSL Season 22
Tourneys
[BSL22] Open Qualifiers & Ladder Tours [Megathread] Daily Proleagues Small VOD Thread 2.0 IPSL Spring 2026 is here!
Strategy
Simple Questions, Simple Answers Soma's 9 hatch build from ASL Game 2 Fighting Spirit mining rates
Other Games
General Games
Nintendo Switch Thread General RTS Discussion Thread Path of Exile Stormgate/Frost Giant Megathread Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion The Story of Wings Gaming
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Five o'clock TL Mafia Mafia Game Mode Feedback/Ideas Vanilla Mini Mafia TL Mafia Community Thread
Community
General
US Politics Mega-thread Canadian Politics Mega-thread Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread Mexico's Drug War
Fan Clubs
The IdrA Fan Club
Media & Entertainment
[Req][Books] Good Fantasy/SciFi books [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion Tokyo Olympics 2021 Thread General nutrition recommendations Cricket [SPORT]
World Cup 2022
Tech Support
Laptop capable of using Photoshop Lightroom?
TL Community
The Automated Ban List
Blogs
Funny Nicknames
LUCKY_NOOB
Money Laundering In Video Ga…
TrAiDoS
Iranian anarchists: organize…
XenOsky
FS++
Kraekkling
Shocked by a laser…
Spydermine0240
Unintentional protectionism…
Uldridge
ASL S21 English Commentary…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 3693 users

The Big Programming Thread - Page 778

Forum Index > General Forum
Post a Reply
Prev 1 776 777 778 779 780 1032 Next
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
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2016-10-10 22:54:23
October 10 2016 22:52 GMT
#15541
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.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-10-11 20:02:25
October 11 2016 01:24 GMT
#15542
edit: I've learned everything I need to about what was here


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
Profile Blog Joined August 2007
New Zealand4438 Posts
Last Edited: 2016-10-11 01:47:12
October 11 2016 01:46 GMT
#15543
Don't you need to free your old, too-small array when you're creating a new array? Been a while since I've done any C++ so I could be wrong but looks like a memory leak at first glance.
Same for popping from your linked list,what happens to the popped node?
Red classic | A butterfly dreamed he was Zhuangzi | 4.5k, heading to 5k as support!
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
October 11 2016 02:01 GMT
#15544
well this is java, so with the linked list, the node will definitely become garbage once there is no reference to it, which is after the method has been returned. in java garbage is typically just handled by JVM (I believe), and in like c++ I think you have to explicitly deal with the garbage.

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
Profile Blog Joined August 2010
United States13132 Posts
October 11 2016 02:23 GMT
#15545
Java has garbage collection yes so no worries about destructors or cleaning up. For testing, you want to do something that causes a capacity increase and probably a mixture of pushes and pops just as a sanity check.
I'll always be your shadow and veil your eyes from states of ain soph aur.
Manit0u
Profile Blog Joined August 2004
Poland17695 Posts
Last Edited: 2016-10-11 03:14:28
October 11 2016 03:13 GMT
#15546
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.
Time is precious. Waste it wisely.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 11 2016 06:01 GMT
#15547
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
Profile Blog Joined July 2010
United States958 Posts
October 11 2016 06:25 GMT
#15548
On October 11 2016 06:31 maybenexttime wrote:
Show nested quote +
On October 10 2016 08:10 maybenexttime wrote:
Is anyone here familiar with Python code profiling with Spyder? How do I save the analysis results? :<


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 --#

import argparse # This will import the argparse command-line parameters module.
import textwrap as _textwrap
import math # This will import the math module
import numpy as np # This will import the random number generation module
import matplotlib.pylab as plt

#-- FUNCTION DEFINITIONS --#

# Definition of the help text wrapping class:

class MultilineFormatter(argparse.HelpFormatter):
def _fill_text(self, text, width, indent):
text = self._whitespace_matcher.sub(' ', text).strip()
paragraphs = text.split('|n ')
multiline_text = ''
for paragraph in paragraphs:
formatted_paragraph = _textwrap.fill(paragraph, width, \
initial_indent = indent, subsequent_indent = indent) + '\n\n'
multiline_text = multiline_text + formatted_paragraph
return multiline_text

#---------------------------------------------------------------------------------------
def calculate_variance(x, y, x_foc, y_foc, \
x_min, x_max, y_min, y_max):

# Calculation of the number of focal points:

m = len(x_foc) # Number of focal points = number of iterations in
# the first loop.
# Calculation of the number of scales:

scale = np.arange(1,45+1,1) # All scales.
#scale = 1 # Only one scale.
l = len(scale)

# Preallocation of memory for all focal points:

variance_avg_scale = np.zeros((m, 180))

# Calculation of the number of analyzed points:

n = len(x)

# Calculation of transect properties:

transect_angles = np.arange(0,180,1)
slopes = np.tan((np.deg2rad(transect_angles)))

# Selection of the focal point

for j in range(m):

# Creation of local coordinates /vectorized:

i = np.arange(0,n,1) # One iteration for each (x, y) point.
x_local = x[i] - x_foc[j]
y_local = y[i] - y_foc[j]

# Limits of the studied area in local coordinates:

x_min_local = x_min - x_foc[j]
x_max_local = x_max - x_foc[j]
y_min_local = y_min - y_foc[j]
y_max_local = y_max - y_foc[j]

# Translation to local polar coordinates:

[angle, radius] = cart_to_pol(x_local,y_local)
angle = np.rad2deg(angle)

# Consolidation of coordinates data:

data = np.vstack((angle, radius))

# Preallocation of memory for all scales:

transect_area = np.zeros(180)

# Calculation of the transect area:

for p in range(180):

transect_angle = transect_angles[p]
slope = slopes[p]

transect_area[p] = calculate_transect_area(x_min_local, \
x_max_local, y_min_local, y_max_local, transect_angle, slope)

# Preallocation of memory for all scales:

variance_scale = np.zeros((l,180))

# Selection of scale:

for k in range(l):

# Transect width:

transect_width = scale

# Preallocation of memory for all positions:

wavelet_transform = np.zeros(180)
variance_normalized = np.zeros(180)

# Selection of angular position:

for p in range(180):

# Finding the points inside the specified transect:

points_observed = observe_points(data, p, transect_width[k]

# Extraction of the polar coordinates of the observed points:

angle_observed = points_observed[0,:]
radius_observed = points_observed[1,:]

# Calculation of the number of observed points:

observations = len(angle_observed)

# Calculation of scaled wavelets for each point within the transect /vectorized:

if observations == 0:
scaled_wavelet = [0] # Has to be '[0]' instead of '0' because '0' cannot be used
# in sum (TypeError: 'int' object is not iterable).
else:
o = np.arange(0,observations,1)
t = (angle_observed[o] - transect_angles[p]/scale[k]
scaled_wavelet = radius_observed*wavelet_function(t)

wavelet_transform[p] = sum(scaled_wavelet)/scale[k] # No density measure.
variance_normalized[p] = wavelet_transform[p]**2/transect_area[p]
variance_scale[k,:] = variance_normalized
variance_avg_scale[j,:] = sum(variance_scale)/l # All specified scales.
#variance_avg_scale[j,:] = variance_scale # Only one scale (1 degree).
variance_avg_foc = sum(variance_avg_scale)/m
return variance_avg_foc

#---------------------------------------------------------------------------------------
def cart_to_pol(x, y):

angle = arctan(y, x)
radius = np.sqrt(x**2 + y**2)
return [angle, radius]

#---------------------------------------------------------------------------------------
def arctan(y, x):

n = len(x);
angle = np.zeros(n)
for i in range(n):
angle[i] = math.atan2(y[i], x[i]
if angle[i] < 0:
angle[i] = angle[i] + math.pi
return angle

#---------------------------------------------------------------------------------------
def observe_points(data, p, transect_width):

# Finding the points inside the specified transect:

log_ind = ( np.logical_or( np.logical_and( \
((p - (transect_width/2)) <= data[0,:], \
(data[0,:] <= (p + (transect_width/2))) ), \
np.logical_and( \
((p - (transect_width/2) + 180) <= data[0,:], \
(data[0,:] <= (p + (transect_width/2) + 180)) ) ) )

points_observed = data[:,log_ind]
return points_observed

#---------------------------------------------------------------------------------------
def calculate_transect_area(x_min_local, x_max_local, y_min_local, y_max_local, \
transect_angle, slope):

# Slope variants:

if (transect_angle == 0) or (transect_angle == 180): # Horizontal line.
x_lim_1 = x_min_local
x_lim_2 = x_max_local
y_lim_1 = 0
y_lim_2 = 0
elif transect_angle == 90: # Vertical line.
x_lim_1 = 0
x_lim_2 = 0
y_lim_1 = y_min_local
y_lim_2 = y_max_local
elif transect_angle > 0 and transect_angle < 90:

# Boundary coordinates:

if y_min_local/slope >= x_min_local:
x_lim_1 = y_min_local/slope
y_lim_1 = y_min_local
else:
x_lim_1 = x_min_local
y_lim_1 = slope*x_min_local

if y_max_local/slope <= x_max_local:
x_lim_2 = y_max_local/slope
y_lim_2 = y_max_local
else:
x_lim_2 = x_max_local
y_lim_2 = slope*x_max_local

else:

# Boundary coordinates:

if y_min_local/slope >= x_max_local:
x_lim_1 = x_max_local
y_lim_1 = slope*x_max_local
else:
x_lim_1 = y_min_local/slope
y_lim_1 = y_min_local

if y_max_local/slope <= x_min_local:
x_lim_2 = x_min_local
y_lim_2 = slope*x_min_local
else:
x_lim_2 = y_max_local/slope
y_lim_2 = y_max_local

transect_area = (x_lim_1)**2 + (y_lim_1)**2 + (x_lim_2)**2 + (y_lim_2)**2
return transect_area
# This is not real area of the transect.
# It's area divided by omega/2, but that holds
# for all transects and omega is constant.

#---------------------------------------------------------------------------------------
def wavelet_function(t):

mexican_hat = 2/(3**(1/2))*math.pi**(-1/4)*(1 - 4*t**2)*np.exp(-2*t**2) # Wavelet function normalized to have unit energy.
return mexican_hat

#-- PARAMETERS --#

parser = argparse.ArgumentParser(description = 'This program quantifies the degree \
of banding in the microstructure by means of angular wavelet analysis. The only \
valid name of the input data is "coordinates.txt". \n',
formatter_class = MultilineFormatter)

# Optional arguments:

parser.add_argument("-p", "--edge_parameter", # Edge parameter limiting the focal points area.
type = float,
default = 0.25,
help = 'Edge parameter determines the boundaries of the focal \
points area, as measured from the edge of the analyzed image. The default value of \
the edge parameter is 0.25.')

parser.add_argument("-f", "--focal_points", # Shows points within the focal points area.
action = 'store_true',
help = 'Shows points within the focal points area.')

args = parser.parse_args()

#-- IMPORT OF DATA --#

D = np.loadtxt("coordinates.txt", delimiter = ' ')

#-- EXTRACTION OF COORDINATES --#

x_extracted = D[:,0]
y_extracted = D[:,1]

# Transposition into vectors:

x = x_extracted.T
y = y_extracted.T

# Verification of vector lengths:

if len(x) != len(y):
print('The imported data is corrupted: the numbers of the x and y coordinates \
do not match')

#-- BOUNDARY CONDITIONS --#

# Limits of the analyzed space:

x_min = min(x)
x_max = max(x)
y_min = min(y)
y_max = max(y)

# Edge region parameters for each coordinate:

edge_parameter = args.edge_parameter

edge_parameter_x = edge_parameter*(x_max - x_min)
edge_parameter_y = edge_parameter*(y_max - y_min)

# Limits of the focal point space:

x_foc_min = x_min + edge_parameter_x
x_foc_max = x_max - edge_parameter_x
y_foc_min = y_min + edge_parameter_y
y_foc_max = y_max - edge_parameter_y

#-- EXTRACTION OF FOCAL POINTS --#

# Generation of focal points:

x_foc = x[np.logical_and(np.logical_and(x > x_foc_min,x < x_foc_max), \
np.logical_and(y > y_foc_min,y < y_foc_max))]
y_foc = y[np.logical_and(np.logical_and(x > x_foc_min,x < x_foc_max), \
np.logical_and(y > y_foc_min,y < y_foc_max))]

# Focal points plot:

if args.focal_points:

fig = plt.figure()
ax1 = fig.add_subplot(111)

ax1.scatter(x, y, s = 1, color = 'black') # All points.
ax1.scatter(x_foc, y_foc, s = 1, color = 'red') # Focal points.
plt.show()

#-- ANALYSIS --#

overall_variance = calculate_variance(x, y, x_foc, y_foc, x_min, x_max, y_min, y_max)

#-- OUTPUT --#

# Original variance peak:

print('Original variance peak:')
print(max(overall_variance))

# Plot:

plt.plot(np.arange(0,180,1), overall_variance)
plt.show()


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..
RIP GOMTV. RIP PROLEAGUE.
Acrofales
Profile Joined August 2010
Spain18239 Posts
Last Edited: 2016-10-11 09:30:32
October 11 2016 07:04 GMT
#15549
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
Profile Blog Joined November 2006
Poland5763 Posts
Last Edited: 2016-10-11 09:15:30
October 11 2016 08:46 GMT
#15550
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
Profile Joined August 2010
Spain18239 Posts
Last Edited: 2016-10-11 09:14:33
October 11 2016 09:14 GMT
#15551
Well, you need to understand that not all programming languages work the same. MATLAB, as the name implies, is a mathematical package focused on matrix operations. Python is a multi-purpose scripting language, with numpy and scipy providing some extremely useful mathematical tools, including matrix operations. Numpy, in particular, leverages the power of the libatlas and libblas packages to do fast matrix operations, but matlab has some further optimizations. You could probably get your python code to run faster if you tweaked your libatlas/libblas/liblapack installations to optimize them to your architecture (the prepackaged binaries are good for the most common configuration, which means they will run reasonably, but probably not fast). Additionally, some of the operations in numpy are poorly packaged, and will calculate unnecessary stuff, whereas matlab doesn't do that.

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
Profile Blog Joined August 2004
Poland17695 Posts
Last Edited: 2016-10-11 10:24:14
October 11 2016 10:21 GMT
#15552
I need some help with docker...


------------------ docker build attempt ----------------------------------
/bin/sh: 13: /root/ubuntu.sh: Syntax error: "(" unexpected (expecting "then")
The command '/bin/sh -c . /root/ubuntu.sh' returned a non-zero code: 2


------------------ failing command attempted locally --------------------
kkarski@debian:~/dockerbuilds/ubuntu12.04_php5.3 $ svn export [url=https://github.com/StanAngeloff/vagrant-shell-scripts/trunk/ubuntu.sh]https://github.com/StanAngeloff/vagrant-shell-scripts/trunk/ubuntu.sh[/url] ubuntu.sh
A ubuntu.sh
Export complete.
kkarski@debian:~/dockerbuilds/ubuntu12.04_php5.3 $ . ubuntu.sh
kkarski@debian:~/dockerbuilds/ubuntu12.04_php5.3 $ php-settings-update 'date.timezone' 'Europe/Warsaw'
php-settings-update('date.timezone' 'Europe/Warsaw')...


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.
Time is precious. Waste it wisely.
Ropid
Profile Joined March 2009
Germany3557 Posts
October 11 2016 10:42 GMT
#15553
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?
"My goal is to replace my soul with coffee and become immortal."
Manit0u
Profile Blog Joined August 2004
Poland17695 Posts
Last Edited: 2016-10-11 10:51:34
October 11 2016 10:50 GMT
#15554
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 +


# Dockerfile for Ubuntu 12.04 image with stock php 5.3 with all necessary extensions installed.
#
FROM ubuntu:12.04
MAINTAINER Krzysztof Karski

# Set correct environment variables.
ENV HOME /root
ENV DEBIAN_FRONTEND noninteractive
ENV INITRD No

# Our user in the container
USER root
WORKDIR /root

# Need to generate our locale
RUN locale-gen pl_PL pl_PL.UTF-8
ENV LANG pl_PL.UTF-8
ENV LANGUAGE pl_PL.UTF-8

# Update system
RUN apt-get update

# Install and Test PHP
RUN apt-get install --no-install-recommends -y \
build-essential \
zip \
unzip \
curl \
git \
subversion \
ca-certificates \
php5-cli \
php5-dev \
php5-json \
php5-pgsql \
php5-mcrypt \
php5-ldap \
php5-gmp \
php5-intl \
php5-imagick \
php5-gd \
php5-exactimage \
php5-imap \
php5-curl \
php5-librdf \
php5-mapscript \
php5-radius \
php5-remctl \
php5-sasl \
php5-rrd \
php5-ps \
php5-ming \
php5-xsl \
php5-xmlrpc \
php5-tidy \
php5-recode \
php5-pspell \
php-pear && \
php --version && \
php -m

# Tidy up
RUN apt-get -y autoremove && apt-get clean && apt-get autoclean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Update PHP settings
RUN svn export [url=https://github.com/StanAngeloff/vagrant-shell-scripts/trunk/ubuntu.sh]https://github.com/StanAngeloff/vagrant-shell-scripts/trunk/ubuntu.sh[/url] /root/ubuntu.sh
RUN . /root/ubuntu.sh
RUN php-settings-update 'date.timezone' 'Europe/Warsaw'

# Install composer
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
RUN php composer-setup.php --install-dir=/usr/local/bin --filename=composer
RUN php -r "unlink('composer-setup.php');"
RUN chmod +x /usr/local/bin/composer

# Allow mounting files
VOLUME ["/root"]

# PHP is our entry point
CMD ["/usr/bin/php"]



The bash script that's failing on the image: https://github.com/StanAngeloff/vagrant-shell-scripts/blob/master/ubuntu.sh
Time is precious. Waste it wisely.
Manit0u
Profile Blog Joined August 2004
Poland17695 Posts
October 11 2016 11:46 GMT
#15555
Changed my docker script to work like that for now:


# Update PHP settings
RUN for php_ini in $(find /etc -type f -iname 'php*.ini'); \
do \
php_extra="$(dirname "$php_ini")/conf.d"; \
mkdir -p "$php_extra"; \
echo "date.timezone=Europe/Warsaw" | tee "$php_extra/0-date-timezone-europe-warsaw.ini" > /dev/null; \
done


This works just fine.
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2016-10-11 11:58:23
October 11 2016 11:48 GMT
#15556
--- Nuked ---
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
October 11 2016 14:25 GMT
#15557
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.
"windows bash is a steaming heap of shit" tofucake
TheEmulator
Profile Blog Joined July 2010
28099 Posts
Last Edited: 2016-10-11 16:54:26
October 11 2016 16:53 GMT
#15558
I'm writing a math paper and I needed to do some research at the natural sciences library in my uni. I guess the math section is in the absolute lowest basement floor (never went to it before), which is nice because I found like 3-4 long rows of old comp sci books there as well. There's literally everything here, it's actually really cool (I mean it's all out of date stuff, but whatever). Time to read up on dos
Administrator
JWD[9]
Profile Blog Joined November 2015
364 Posts
October 11 2016 17:43 GMT
#15559
This is directly from the book

Programming: Principles and Practice Using C++
Second Edition
Bjarne Stroustrup



template<class T> class Vector_ref {
vector<T*> v;
vector<T*> owned;
public:
Vector_ref() {}
Vector_ref(T* a, T* b = 0, T* c = 0, T* d = 0);

~Vector_ref() { for (int i=0; i<owned.size(); ++i) delete owned[i]; }

void push_back(T& s) { v.push_back(&s); }
void push_back(T* p) { v.push_back(p); owned.push_back(p); }

T& operator[](int i) { return *v[i]; }
const T& operator[](int i) const { return *v[i]; }

int size() const { return v.size(); }
};


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?


Vector_ref(T* a, T* b = 0, T* c = 0, T* d = 0);
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2016-10-11 18:12:05
October 11 2016 18:08 GMT
#15560
--- Nuked ---
Prev 1 776 777 778 779 780 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 1h 27m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
SortOf 308
ProTech117
MindelVK 41
trigger 12
StarCraft: Brood War
Hyuk 14973
Calm 7050
Horang2 1594
Jaedong 1180
Zeus 380
Stork 363
EffOrt 289
Mong 134
ggaemo 133
Mind 132
[ Show more ]
Last 119
Pusan 117
Hyun 65
JulyZerg 64
hero 57
Backho 54
Aegong 48
[sc1f]eonzerg 42
Killer 37
sSak 31
ToSsGirL 28
sorry 23
Hm[arnc] 20
IntoTheRainbow 14
soO 14
zelot 11
SilentControl 11
Sacsri 10
Icarus 6
eros_byul 1
Terrorterran 1
Dota 2
XaKoH 644
canceldota290
LuMiX0
League of Legends
JimRising 177
Counter-Strike
fl0m3391
oskar37
Heroes of the Storm
Khaldor172
Trikslyr32
Other Games
singsing1418
B2W.Neo983
DeMusliM325
byalli284
Lowko213
Hui .172
Fuzer 170
RotterdaM135
Sick134
KnowMe26
Organizations
Dota 2
PGL Dota 2 - Main Stream225
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 11 non-featured ]
StarCraft 2
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
League of Legends
• Jankos2768
Upcoming Events
uThermal 2v2 Circuit
1h 27m
BSL
6h 27m
RSL Revival
20h 27m
herO vs MaxPax
Rogue vs TriGGeR
BSL
1d 6h
Replay Cast
1d 10h
Replay Cast
1d 19h
Afreeca Starleague
1d 20h
Sharp vs Scan
Rain vs Mong
Wardi Open
1d 22h
Monday Night Weeklies
2 days
Sparkling Tuna Cup
2 days
[ Show More ]
Afreeca Starleague
2 days
Soulkey vs Ample
JyJ vs sSak
Replay Cast
3 days
Afreeca Starleague
3 days
hero vs YSC
Larva vs Shine
Kung Fu Cup
3 days
Replay Cast
4 days
KCM Race Survival
4 days
The PondCast
4 days
WardiTV Team League
4 days
Replay Cast
5 days
WardiTV Team League
5 days
RSL Revival
6 days
Cure vs Zoun
WardiTV Team League
6 days
Liquipedia Results

Completed

Proleague 2026-03-20
WardiTV Winter 2026
Underdog Cup #3

Ongoing

KCM Race Survival 2026 Season 1
Jeongseon Sooper Cup
BSL Season 22
CSL Elite League 2026
RSL Revival: Season 4
Nations Cup 2026
NationLESS Cup
BLAST Open Spring 2026
ESL Pro League S23 Finals
ESL Pro League S23 Stage 1&2
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual

Upcoming

ASL Season 21
Acropolis #4 - TS6
2026 Changsha Offline CUP
CSL 2026 SPRING (S20)
CSL Season 20: Qualifier 1
Acropolis #4
IPSL Spring 2026
Kung Fu Cup 2026 Grand Finals
HSC XXIX
uThermal 2v2 2026 Main Event
IEM Cologne Major 2026
Stake Ranked Episode 2
CS Asia Championships 2026
Asian Champions League 2026
IEM Atlanta 2026
PGL Astana 2026
BLAST Rivals Spring 2026
CCT Season 3 Global Finals
IEM Rio 2026
PGL Bucharest 2026
Stake Ranked Episode 1
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.