Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C/C++ for Python programmer [closed]

I have to switch from Python to C/C++.
Do you know a quick "reference tutorial" or something like that to have a reference to how to start? For example something like the Numpy and Scipy tutorials.
I have read a lot of "documentation", for example

  • C++ for dummies
  • the K&R C Programming Language
  • a lot of blog and online documentation such as: http://eli.thegreenplace.net/2010/01/11/pointers-to-arrays-in-c/,
  • http://newdata.box.sk/bx/c/
  • tons of Q&A here on StackOverflow
  • ...

but it's still not clear to me even how to do start porting to C/C++ something like:

#!/usr/bin/env python

import time
import numpy as np
import tables as tb

"""Retrieve 3D positions form 1000 files and store them in one single HDF5 file.
"""

t = time.time()

# Empty array
sample = np.array([])
sample.shape = (0,3)

# Loop over the files
for i in range(0, 1000):
  filename = "mill2sort-"+str(i)+"-extracted.h5"
  print "Doing ", filename
  # Open data file
  h5f = tb.openFile(filename, 'r')
  # Stack new data under previous data
  sample = np.vstack((sample, h5f.root.data.read()))
  h5f.close()

# Create the new file
h5 = tb.openFile("mill2sort-extracted-all", 'w')
# Save the array
h5.createArray(h5.root, 'data', sample, title='mill_2_sub_sample_all')
h5.flush()
h5.close()

print "Done in ", time.time()-t, " seconds."

in C or C++. In this example I was not even able to understand how to pass a 3D array to a function that find it's dimensions, something like

int getArrayDimensions(int* array, int *dimensions){
  *dimensions = sizeof(*array)/sizeof(array[0]);
  return 0;
}

With array being

int array[3][3][3] = ...

Thank you for any suggestion!:)

like image 597
brunetto Avatar asked Mar 22 '12 12:03

brunetto


1 Answers

This question is getting quite old, but here is a couple of references that have been useful to me:

A Transition Guide: Python to C++ (pdf)

A Brief Introduction to C++ for Python programmers (incomplete but quite good)

like image 200
cedbeu Avatar answered Sep 21 '22 16:09

cedbeu