265 Topics

Member Avatar for daviddoria

I'm just starting python and it seemed reasonable to go ahead and learn the new version. I read that numpy wont be available for python3 until at least 2010. All I need is a basic "vector", "matrix", and some basic functions like matrix/vector multiplication. Is anything like this available for …

Member Avatar for sneekula
0
136
Member Avatar for daviddoria

If I have /home/doriad/Scripts/Python/ and inside I have a bunch of folders, ie Geometry, Math, Other, etc that each contain scripts (.py files), is there a way I can just add /home/doriad/Scripts/Python to PYTHONPATH and then somehow [code] from Geometry/Spherical import * [/code] rather than having to add every subdirectory …

Member Avatar for vegaseat
0
2K
Member Avatar for daviddoria

I want to make an input stream parser capable of handling input in any of the following forms: [code] x y z x,y,z x, y, z (x,y,z) (x, y, z) [/code] Is there a clever way to do this? Or do I have to check the first character, if it …

Member Avatar for ArkM
0
86
Member Avatar for daviddoria

Is it possible to indicate that a class function you are calling is static? [code] class Point { std::string name; public: Point(){} static void DisplayName() { std::cout << "Point" << std::endl;} }; int main() { Point.DisplayName(); //this doesn't indicate the the member function is static //maybe something like this: //static_call(Point.DisplayName()); …

Member Avatar for siddhant3s
0
100
Member Avatar for daviddoria

I have a "Tools" class which contains a lot of functions I commonly use. One is a parallel sort. I pass it a vector of Objects and a vector of indices, and it sorts the Objects and sorts the indices the same way (so the corresponding index is in the …

Member Avatar for Ancient Dragon
0
86
Member Avatar for daviddoria

I was looking at this: [url]http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.18[/url] I don't understand [code] File f = OpenFile("foo.txt"); [/code] It seems like File is one class, and OpenFile is a separate class, so how can you assign an OpenFile to a File? Also, is it necessary to have this second class? Why not something …

Member Avatar for Ancient Dragon
0
294
Member Avatar for daviddoria

To redirect clog, I have been using this: [code] std::streambuf* clog_save; std::ofstream ofs; clog_save = std::clog.rdbuf(); ofs.open(LogFilename.c_str()); std::clog.rdbuf(ofs.rdbuf()); cout << "Test cout." << endl; std::clog << "Test log." << endl; std::clog.rdbuf(clog_save); ofs.close(); [/code] However, it seems like bad "code reuse" practice to have to put this in every program I …

Member Avatar for ArkM
0
178
Member Avatar for daviddoria

I usually make a matrix like this [code] from Numeric import * A=zeros([3,3]) print str(A[0,1]) #access an element [/code] I would like to store a pair of values in each element, that is have a matrix where the (0,0) element is (2.3, 2.4), the (0,1) element is (5.6,6.7), etc. Is …

Member Avatar for vegaseat
0
103
Member Avatar for daviddoria

I have to call this many times: [code] MyScript.py --top='?_0.png' [/code] where the 0 should be replaced with 0, 1, 2, 3, etc I tried this: [code] for i in {0..3}; do echo MyScript.py --top="'?_${i}.png'"; MyScript.py --top="'?_${i}.png'"; done; [/code] It seems to make the command look correct (ie the single …

0
61
Member Avatar for daviddoria

I found some code to parse command line arguments (is there an easier way? sed always seems so complicated...) [code] #!/bin/bash for i in $* do case $i in --files=*) FILES=`echo $i | sed 's/[-a-zA-Z0-9]*=//'` ;; --default) DEFAULT=YES ;; *) # unknown option ;; esac done echo $FILES echo "File …

Member Avatar for hexram
0
109
Member Avatar for daviddoria

I need to get an unknown number of file names from the command line, ie ./python MyScript.py --Files 1.txt 2.txt 3.txt [code] parser.add_option("-n", "--NumFiles", type="int", help="Number of files") parser.add_option("--Files", nargs=options.NumFiles, help="a triple") (options, args) = parser.parse_args() [/code] Clearly this will not work because options.NumFiles is not available until after parse_args() …

Member Avatar for daviddoria
0
197
Member Avatar for daviddoria

I want to parse some simple arguments from the command line. This shows all of the arguments: [code] #!/usr/bin/python import sys #print all of the arguments for arg in sys.argv: print arg [/code] but I want to handle something like [code] --file a.txt [/code] or [code] --x 12 --y 13 …

Member Avatar for jlm699
0
111
Member Avatar for daviddoria

I tried to do this to redirect the clog output to a file: [code] ofstream ofs("file.log"); clog.rdbuf(ofs.rdbuf()); clog << "Logged." << endl; ofs.close(); [/code] It worked (the file contains the text), but the program segfaults. I read that you have to "restore" the original buffer, so I tried this [code] …

Member Avatar for Narue
0
120
Member Avatar for daviddoria

A friend of mine said that python could be used to make simple GUIs (ie. a couple of buttons and a text box). I googled "python gui" and it looks like there are 30934 libraries to make GUIs. Is there a "standard" or "built in" one? Thanks, Dave

Member Avatar for jlm699
0
109
Member Avatar for daviddoria

Does anyone have a good 2 line summary of WHEN to use perl/python/bash/etc? To do easy-ish things, they can clearly all be used, but there is likely an ideology behind each that indicates WHEN/WHY to use them. For example, I use VB if I want easy GUI, c++ if I …

Member Avatar for leegeorg07
0
136
Member Avatar for daviddoria

I am trying to do this [code] #!/bin/bash for i in 1 2 3 4 5; do File1="$i.txt" File2="$i.obj" ./Test $File1 $File2 #save i and the result of the program somehow done; [/code] For example, at the end I would like to have a file like this [code] 1 3.4 …

Member Avatar for nucleon
0
162
Member Avatar for daviddoria

I have used boost's progress bar (it outputs ***** from 0 to 100% complete) to track the progress of long loops. It would also be nice to be able to see a counter along with that, like if I run 1000 tests, the *'s will go from 0 to 100%, …

Member Avatar for daviddoria
0
115
Member Avatar for daviddoria

I am trying to write a pretty straight forward algorithm (agglomerative clustering), but the details are getting pretty hairy. (A cluster is simply a group of points. The idea is to take a list of points and decide which are "grouped" or "clustered" close together.) Here is the outline: Input: …

Member Avatar for daviddoria
0
118
Member Avatar for daviddoria

On the line [code] set<T>::iterator iter; [/code] I am getting "expected ';' before 'iter'" [code] #include <vector> #include <set> using namespace std; template <typename T> vector<T> UniqueElements(const vector<T> &V) { set<T> s; s.insert(V.begin(), V.end()); vector<T> Elements; set<T>::iterator iter; return Elements; } [/code] Can anyone see why? It compiles fine if …

Member Avatar for daviddoria
0
102
Member Avatar for daviddoria

This simple example fills a vector with numbers 0-9. Then I use find() to find where the 7 is. Then I saw online you can get the index by simply subtracting V.begin() from the iterator that find() returns. Has - been overloaded for iterators to do some magic and return …

Member Avatar for StuXYZ
0
95
Member Avatar for daviddoria

I was using a library recently and I was getting a "undefined reference" linker error when I tried to call a template function with a type that they did not plan on me using. I asked on the mailing list and they said to call [code] VSL_VECTOR_IO_INSTANTIATE(vnl_matrix_fixed<double,3,3>); [/code] I guess …

0
50
Member Avatar for daviddoria

Currently, my index.html is like this [code] <html> <head> <title>EngineeringNotes.net</title> <link href="style.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body> <div class="header"> <div id="logo"> <h1>EngineeringNotes.net</h1> </div> <div class="menu"> <ul> <li><a href="mailto:daviddoria@gmail.com">Contact Me</a></li> <li><a href="phpBB3">Forums</a></li> <li><a href="Ideology.html">Ideology</a></li> </ul> </div><!-- end menu --> </div><!-- end header --> <div class="page"><!-- start page --> <div class="sidebar"><!-- …

Member Avatar for daviddoria
0
181
Member Avatar for daviddoria

According to this: [url]http://www.parashift.com/c++-faq-lite/templates.html#faq-35.13[/url] One way to keep only the function declaration in the .h file is to do this [code] ////////// file: Tools.h #include <iostream> #include <vector> using namespace std; template <typename T> T Sum(vector<T> &V); [/code] [code] ///////// file: Tools.cpp #include "Tools.h" #include <iostream> #include <vector> using namespace …

Member Avatar for tux4life
0
294
Member Avatar for daviddoria

To remove duplicates from a vector, my first thought was to insert them all into a set, it would take care of the uniqueness of the elements, and then read them back out into my vector. However, I have a vector<Point>, where Point is a point in 3d space (ie. …

Member Avatar for daviddoria
0
213
Member Avatar for daviddoria

I was reading about the new "tuple" type coming in c++0x, and I decided to try it. I saw that if you give a compiler flag -std=c++0x it will work. So I did it, and then #include <tuple> works and everything was good. Then I decided to try the default …

Member Avatar for daviddoria
0
85
Member Avatar for daviddoria

Is there a built in type to store UNordered pairs? ie. I want these [code] pair<double, double> a(4.0, 5.0); pair<double, double> a(5.0, 4.0); [/code] to be equal. Do I have to make a wrapper and override == ? Thanks, Dave

Member Avatar for DemonGal711
0
144
Member Avatar for daviddoria

I often have this situation [code] class OrientedPoint { private: Point P; Vector N; Color C; bool valid; public: //////////// Constructors ////////// OrientedPoint() {} OrientedPoint(const Point &Coord); OrientedPoint(const Point &Coord, const Vector &Normal); OrientedPoint(const Point &Coord, const Color &C); OrientedPoint(const Point &Coord, const Vector &Normal, const Color &C); [/code] where …

Member Avatar for daviddoria
0
122
Member Avatar for daviddoria

Is pthreads still the way to go to detach a process from the main thread in linux? It seems seems kind of convoluted/old/c-style from looking at some examples - is there a more "c++" way? Thanks, Dave

0
48
Member Avatar for daviddoria

I'm just trying to figure out how this stuff works. I wrote this function: [code] #include <algorithm> #include <vector> double VectorMax(const vector<double> &a) { vector<double>::iterator pos; pos = max_element (a.begin(), a.end()); return *pos; } [/code] and call it with: [code] vector<double> Numbers; Numbers.push_back(3.4); Numbers.push_back(4.5); Numbers.push_back(1.2); cout << VectorMax(Numbers) << endl; …

Member Avatar for nucleon
0
193
Member Avatar for daviddoria

I am trying to use the for_each from stl algorithm. [url]http://www.cplusplus.com/reference/algorithm/for_each.html[/url] [code] #include <algorithm> #include <vector> #include <iostream> template <typename T> void OutputObject(const T &obj) { cout << obj << endl; } template <typename T> void OutputVector(const vector<T> &V) { for_each (V.begin(), V.end(), OutputObject); cout << endl; } [/code] I …

Member Avatar for daviddoria
0
576
Member Avatar for daviddoria

I found this while googling for something [url]http://msdn.microsoft.com/en-us/library/ms177203(VS.80).aspx[/url] I tried it (with g++) and it seems to be a syntax error - is this like something specific to Visual Studio or something? Dave

Member Avatar for Narue
0
92
Member Avatar for daviddoria

Is there a reason to use [code] cout << static_cast<int>(thing); [/code] instead of [code] cout << (int)thing; [/code] ? Thanks, Dave

Member Avatar for Narue
0
102
Member Avatar for daviddoria

If I make an array like this [code] GLubyte bufImage[100][100][3]; [/code] I can pass bufImage to a function and then get the values using: [code] r = bufImage[im_x][im_y][0]; g = bufImage[im_x][im_y][1]; b = bufImage[im_x][im_y][2]; [/code] However, if I don't know Width and Height at runtime, this does not work. I …

Member Avatar for Narue
0
311
Member Avatar for daviddoria

I've seen a few questions about this floating around here (mostly from me :) ) but I finally got this is into a nice working form - maybe it will be useful for someone. It is called like this: [code] void TestParallelSort() { vector<double> Numbers; Numbers.push_back(3.4); Numbers.push_back(4.5); Numbers.push_back(1.2); vector<string> Names; …

0
230
Member Avatar for daviddoria

It seems like SO often I need to attach a "valid" flag to a standard type. For example - I have a function called "CalculateLunchTime" that I pass a vector of times. If the vector has 0 elements, they did not take a lunch, so the duration is 0 minutes. …

Member Avatar for Rashakil Fol
0
598
Member Avatar for daviddoria

If I use the uncommented 3 lines for getting an int out of a stringstream, the value in MPV is wrong. However, if I make a new stringstream, then it works fine. I thought setting .str("") was essentially resetting the stringstream? [code] line = ""; getline(fin, line); //get fourth line …

Member Avatar for daviddoria
0
469
Member Avatar for daviddoria

I have two functions: GetDayTime and GetLunchTime. From some places in the program, all I have is the associate name and a date and I want to determine these quantities. So I just query the database inside the function: [code] Public Function CalculateLunchTime(ByVal DateToCalculate As DateTime) As Double Dim daEvent …

0
79
Member Avatar for daviddoria

I have a delete button which does this: [code] TTDataSet.PunchEventTable.Rows(dgvData.SelectedRows(0).Index).Delete() [/code] The problem is that if I delete row 0 (the 0th index in the DataGridView and in the underlying table, all is well. But now row 1 in the table corresponds to row 0 in the DataGridView, so if …

Member Avatar for rapture
0
895
Member Avatar for daviddoria

I have tried to make a SumVector function for all types, but if it is called with a vector of unsigned char's, it will do something special. Here is what I tried, but I get a multiple definitions of the function compiler error. [code] template <typename T> void SumVector(vector<T> &V) …

Member Avatar for nucleon
0
3K
Member Avatar for daviddoria

I have a program with about 20 forms, almost all of which use the data from a tables in a dataset (from a datasource I added to the project). So I have made a global variable in a module: [code] Public TTData As New TTDataSet [/code] And a DataAdapter for …

0
50
Member Avatar for daviddoria

I have a typed datatable that I am viewing part of with a datagridview [code] dgvData.DataSource = TTData.PunchEventTable.Select(FilterString, SortString) [/code] My question is how do I delete the row that is selected in the DataGridView from the database? If I use [code] TTData.PunchEventTable.Rows.RemoveAt(dgvData.SelectedRows(0).Index) [/code] I believe it will delete the …

0
50
Member Avatar for daviddoria

I want to do something like this [code] template <class T> vector<T> DereferenceVector(vector<T*> &PointerVec) { vector<T> ObjectVec; for(unsigned int i = 0; i < PointerVec.size(); i++) ObjectVec.push_back(*PointerVec[i]); return ObjectVec; } [/code] and call it with [code] void TestDereferenceVector() { vector<double*> a(10); vector<double> b = DereferenceVector(a); } [/code] That seems to …

Member Avatar for daviddoria
0
107
Member Avatar for daviddoria

If I do this, I get "warning: address of local variable returned". [code] unsigned char* CharArray(void) const { unsigned char arr[3]; arr[0] = R_; arr[1] = G_; arr[2] = B_; return arr; } [/code] So the reason for that is that the memory allocated for arr[] is only available within …

Member Avatar for ArkM
0
86
Member Avatar for daviddoria

A friend convinced me to store a vector of pointers in my class: [code] vector<Point*> Points; [/code] In my class instead of a vector of "real" objects (what do you call this?). The problem now is that there are several functions (out of my control ie. in a library) that …

Member Avatar for Narue
0
115
Member Avatar for daviddoria

I have a function that I call recursively, but I want to keep track of a maximum through the entire process. This is what I am doing: [code] void Intersect(double &MaxDistance) { if(something) MaxDistance = something; Intersect(MaxDistance); } [/code] Is that correct/reasonable? Something doesn't seem to be working and I'm …

Member Avatar for vmanes
0
158
Member Avatar for daviddoria

There was another thread about this ([url]http://www.daniweb.com/forums/thread114737.html[/url]) but it didn't seem to be resolved? If I have a vector of int's and another vector of the same length of corresponding names, I would like to sort the ints and have the names "follow" [code] vector<string> Doubles; Doubles.push_back("Name1"); Doubles.push_back("Name2"); Doubles.push_back("Name3"); vector<int> …

Member Avatar for kbshibukumar
0
134
Member Avatar for daviddoria

[code] double P = 3.5/(.1 * sqrt(2.0*3.14159)) * exp(-pow(5.0,2) / (2.0*pow(.1,2))); cout << P << endl; if (P==0) cout << "P is zero!" << endl; [/code] Is this underflowing so it is getting rounded to zero? The problem is that I am taking the log of this, so if it …

Member Avatar for Rashakil Fol
0
115
Member Avatar for daviddoria

I wrote a pause function: [code] void Pause(void) { printf("Paused...\n\n"); fgetc(stdin); } [/code] It generally works fine (hit enter to continue). But one program doesn't seem to want to stop at all... [code] if(P == 0) { cout << "P=0!" << endl; //just as another attempt to stop it , …

Member Avatar for Nick Evan
0
150
Member Avatar for daviddoria

Is there anyway to get the calling function? ie [code] void A() { if (A() was called from B() ) do something; else do something else } [/code] Is this possible? Dave

Member Avatar for Rashakil Fol
0
132
Member Avatar for daviddoria

In integration.h I have this [code] class FunctionClass { public: virtual double f(const double x) = 0; }; [/code] Then in probability.h, I have this [code] #include "integration.h" class Mass1 : public FunctionClass { public: double Clutter; Mass1(double c) : Clutter(c) {} double f(const double x) { return Clutter * …

Member Avatar for _adam_
0
1K

The End.