Cythonizing function containing too many arrays - cythonize

Running setup.py on the code below takes some seconds to finish; however, by increasing number of arrays to 20k, .pyd is not generated after 2 hours of running the setup on windows XP 32 bit. Should I use a specific definition for the arrays?
import numpy
import scipy.interpolate
from scipy.interpolate import interp2d
x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
y = [0.1, 0.2, .3, 0.4, 0.5, 0.6, .7, 0.8, .9, 1, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8, 2.9]
def interpolate(DATA,x_new,y_new):
var1 = DATA[0]
var2 = DATA[1]
f = interp2d(y,x,var1,kind='linear')
k1 = f(y_new,x_new)
f = interp2d(y,x,var2,kind='linear')
k2 = f(y_new,x_new)
return (k1[0],k2[0])
def function(condition1,condition2,param1,param2):
Data1_var1=[[6L, 5L, 8L, 8L, 9L, 3L, 2L, 1L, 1L, .7, 5.7, 4.8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [5L, 1L, 9L, 5L, 4L, 8L, 9L, 3L, 9.5, 7.2, 5.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2L, 3L, 9L, 8L, 4L, 2L, 6L, 2L, 8, 7, 5.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [8L, 3L, 8L, 4L, 2L, 2L, 4L, 1L, .8, .1, 4.6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [6L, 5L, 4L, 2L, 1L, 6L, 1L, 8, .8, 5.4, 4.2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [5L, 4L, 3L, 2L, 7L, 3L, 1L, 8L, 6.3, 5.2, 4.1, 0, 0, 0, 0, 0, 0, 0, 0, 0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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [8L, 3L, 8L, 4L, 2L, 2L, 4L, 1L, .8, .1, 4.6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [6L, 5L, 4L, 2L, 1L, 6L, 1L, 8, .8, 5.4, 4.2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [5L, 4L, 3L, 2L, 7L, 3L, 1L, 8L, 6.3, 5.2, 4.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [4L, 3L, 2L, 2L, 1L, 3L, 1L, 8.4, 6.8, 5.6, 4.4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [6L, 1L, 6L, 2L, 1L, 4L, 1L, 9.2, 6, 6.3, 5L, 4.2, 3.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [3L, 7L, 4L, 1L, 6L, 4L, 2L, .8, 8.3, 7L, .6, 4.8, 4.1, 3.7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2L, 4L, 1L, 8L, 6L, 1L, 2L, 10L, 8.9, 7.7, 6.5, 5.6, 5L, 4.6, 4.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2L, 3L, 2L, 7L, 5L, 3L, 2L, 10L, 9.2, 8.1, 6.9, .1, .6, 5.1, 4.6, .2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
if condition1:
if condition2:
out = interpolate(Data1,param1,param2)
else:
out = interpolate(Data2,param1,param2)

Related

Printing tchar array as unicode string rust winapi

I'm using the winapi to grab a list of the current processes running on the system, here's my code:
use winapi::um::tlhelp32::{Process32Next, Process32First, CreateToolhelp32Snapshot, TH32CS_SNAPPROCESS, PROCESSENTRY32};
use winapi::um::winnt::HANDLE;
use winapi::um::handleapi::CloseHandle;
use std::mem::size_of;
...
fn get_processes() {
let h_process_snap: HANDLE;
// really, rust?
let mut pe32 = &mut PROCESSENTRY32{
dwSize: 0,
cntUsage: 0,
th32ProcessID: 0,
th32DefaultHeapID: 0,
th32ModuleID: 0,
cntThreads: 0,
th32ParentProcessID: 0,
pcPriClassBase: 0,
dwFlags: 0,
szExeFile: [0; 260],
};
unsafe {
h_process_snap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
}
pe32.dwSize = size_of::<PROCESSENTRY32>() as u32;
unsafe {
if Process32First(h_process_snap, pe32) == 0 {
CloseHandle(h_process_snap);
println!("can't get a process snapshot");
// TODO: return
}
while Process32Next(h_process_snap, pe32) != 0 {
println!("{:?}", pe32.szExeFile);
}
}
}
...
Now I'm trying to print the actual name of the process, in C++, this can be done using cout or wcout.
When I use println!("{:?}", pe32.szExeFile);, this is what I get:
[115, 117, 112, 101, 114, 102, 52, 45, 114, 117, 115, 116, 46, 101, 120, 101, 0, 116, 46, 101, 120, 101, 0, 98, 108, 101, 83, 104, 101, 108, 108, 46, 69, 120, 112, 101, 114, 105, 101, 110, 99, 101, 115, 46, 84, 101, 120, 116, 73, 110, 112, 117, 116, 46, 73, 110, 112, 117, 116, 65, 112, 112, 46, 101, 120, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
I don't really understand how to work with this, how can I print the pe32.szExeFile as a Unicode string in rust?
see also: https://docs.rs/winapi/0.3.6/winapi/um/tlhelp32/struct.PROCESSENTRY32.html
Thanks to #IInspectable, I used the explicit Unicode versions, e.g. Process32FirstW, and from_wide to print the values in readable format:
let os_string = OsString::from_wide(&pe32.szExeFile[..]);
// ExeFile names have a lot of trailing 0's, remove them...
let exe_files: String = os_string.into_string().unwrap().replace("\u{0}", "");
println!("{:?}", exe_files);

Obtain sub-cv::Mat from a given image such that

I have a processed an image that returns a Mat say:
[
[ 0, 0, 255, 255, 255, 0, 0, 0],
[ 0, 0, 0, 255, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 255, 255, 0],
[ 0, 0, 0, 0, 0, 255, 255, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0]
]
are there any segmentation functions that can help me isolate individually ?
if not so what would be the best approach ?
i.e. say if i do mysegment(Mat a,0) should return
[
[ 0, 0, 255, 255, 255, 0, 0, 0],
[ 0, 0, 0, 255, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0]
]
then mysegment(Mat a,1) will return
[
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0],
[ 0, 0, 0, 0, 0, 255, 255, 0],
[ 0, 0, 0, 0, 0, 255, 255, 0],
[ 0, 0, 0, 0, 0, 0, 0, 0]
]
I consider continuous 255 pixels to be a block. Now I want to iterate over or process these blocks ... since more than one block can be formed in a matrix.
You can use contours
findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );
the link to the library

3D skew transformation matrix along one coordinate axis

Is there a way to calculate the skew transformation matrix along one coordinate axis, given the skew angle, as follows
This should work for the most part for skewing an object with a transformation matrix, in particular using glMultMatrix(matrix)
matrix1[] = {
1, 0, 0, 0,
tan(a), 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
matrix2[] = {
1, 0, 0, 0,
0, 1, 0, 0,
tan(a), 0, 1, 0,
0, 0, 0, 1
};
matrix3[] = {
1, tan(a), 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
matrix4[] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, tan(a), 1, 0,
0, 0, 0, 1
};
matrix5[] = {
1, 0, tan(a), 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1
};
matrix6[] = {
1, 0, 0, 0,
0, 1, tan(a), 0,
0, 0, 1, 0,
0, 0, 0, 1
};

Error without an error being thrown

I'm trying to multiply impute some data, and it's failing in a very odd way. I have options(error=recover) set, and mi() doesn't throw an error, but it does stop imputing after the first attempt. It also doesn't return a value. consequently I have no idea where to even start with debugging. minimal reproducible example below.
> library(mi)
> temp <- mi(dat)
Beginning Multiple Imputation ( Wed Dec 14 10:44:44 2011 ):
Iteration 1
Chain 1 : HLTHA5.fac* BMI* INCOME*
> temp
Error: object 'temp' not found
dat<-structure(list(treat = c(FALSE, FALSE, TRUE, TRUE, TRUE, FALSE,
FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, TRUE,
FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE), NUMADULT = c(2,
1, 2, 1, 2, 1, 2, 1, 2, 4, 1, 1, 2, 2, 1, 2, 1, 1, 2, 1, 2, 2,
3, 3, 1), HLTHA5.fac = structure(c(3L, NA, 3L, 2L, 4L, 5L, 5L,
4L, 4L, 3L, 3L, 5L, 3L, 4L, 5L, 4L, 2L, 2L, 3L, 5L, 4L, 5L, 4L,
3L, 3L), .Label = c("0", "1", "2", "3", "4"), class = "factor"),
SOURCEA = structure(c(1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), .Label = c("Yes", "No", "Don't know", "Refused"), class = "factor"),
BMI = c(27.363941459046, 24.0265857515842, 34.3236939308346,
27.0907152026518, 32.6101901381975, 34.1643655360753, 21.4628674188624,
29.1751398412094, 22.5924920198551, 39.6719545438681, 38.5220574557939,
20.1156133421915, 30.6612391698034, 35.7332536282609, 26.5664872147956,
25.6016897082437, 19.3649931598758, 28.1868713091175, NA,
32.4438116170843, 32.5507197719099, 21.1090717674633, 32.2340044872853,
24.3699149340904, 27.3369153440247), SMOKE2 = structure(c(2L,
1L, 2L, 2L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
1L, 2L, 2L, 2L, 1L, 2L, 2L, 2L, 1L), .Label = c("Yes", "No"
), class = "factor"), INCOME = structure(c(16L, 4L, 13L,
11L, 13L, 7L, 22L, 6L, NA, 1L, 13L, 18L, 12L, 20L, NA, NA,
2L, 13L, 17L, NA, 12L, 21L, 9L, 15L, 13L), .Label = c("Less than $10,800",
"$10,800-$14,600", "$14,601-$16,250", "$16,251-$18,300",
"$18,301-$21,800", "$21,801-$25,000", "$25,001-$27,500",
"$27,501-$29,300", "$29,301-$33,100", "$33,101-$36,700",
"$36,701-$38,700", "$38,701-$44,200", "$44,201-$50,000",
"$50,001-$58,000", "$58,001-$66,500", "$66,501-$73,500",
"$73,501-$80,000", "$80,001-88,200", "$88,201-$100,000",
"$100,001-$120,000", "$120,001-$130,000", "$130,001-$150,000",
"$150,001-$250,000", "Over $250,000", "Don't know", "Refused"
), class = "factor"), RESPMAR = structure(c(1L, 5L, 1L, 4L,
3L, 6L, 1L, 1L, 1L, 1L, 4L, 4L, 1L, 1L, 4L, 1L, 3L, 3L, 1L,
3L, 1L, 1L, 1L, 1L, 1L), .Label = c("Married", "Living w partner",
"Widowed", "Divorced", "Separated", "Single", "Other", "Don't know",
"Refused"), class = "factor"), RESPGRAD = structure(c(5L,
1L, 2L, 5L, 3L, 3L, 5L, 2L, 4L, 2L, 4L, 3L, 4L, 4L, 2L, 3L,
2L, 5L, 2L, 4L, 4L, 5L, 2L, 2L, 3L), .Label = c("< HS 0-11",
"HS graduate", "Some colge 13-15", "Collge grad 16", "Post college 16+",
"Don't know", "Refused"), class = "factor"), RACEA2 = structure(c(1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 2L, 1L,
3L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L), .Label = c("White (Not-Latino)",
"Black (Not-Latino)", "Latino (total)", "Asian", "Biracial/Multi",
"Native American", "Other", "Don't know", "Refused"), class = "factor"),
INSUREDA = structure(c(1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L,
1L), .Label = c("Insured", "Not insured", "Don't know", "Refused"
), class = "factor"), PAP.adj = c(TRUE, FALSE, FALSE, FALSE,
FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, TRUE,
TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE,
TRUE, TRUE)), .Names = c("treat", "NUMADULT", "HLTHA5.fac",
"SOURCEA", "BMI", "SMOKE2", "INCOME", "RESPMAR", "RESPGRAD",
"RACEA2", "INSUREDA", "PAP.adj"), row.names = c(1L, 13L, 15L,
23L, 26L, 33L, 38L, 53L, 56L, 60L, 62L, 85L, 109L, 116L, 138L,
217L, 240L, 262L, 264L, 269L, 277L, 295L, 328L, 334L, 338L), class = "data.frame")
Any ideas as to where to begin?
Update
Thanks to the diagnostic technique below, I tracked down the error, which I am summarizing here since it appears I am not the only one to have this problem.
The error occurs when you have an unordered categorical variable with levels that have no values. mi.default calls .initializeConvCheckArray to fill in AveVar with NAs. That function uses the levels, regardless of whether those levels are used. By contrast, to fill in AveVar it calls .getmean, which drops unused levels. Therefore the dimensions don't match up.
The easy solution on the user end is of course to drop the extra levels before calling mi.info and mi. I'm going to submit a bug fix to the package authors, though, having spent way too much time tracking this down already.
Since the error=recover option is not working, an alternative that does work is to set options(error=dump.frames). That will get you some information about the error, which you can either print out or, more usefully, examine with debugger()
ls()
# [1] "dat"
options(error=dump.frames)
mi(dat)
ls()
# [1] "dat" "last.dump" # Apparently there WAS an error
# INVESTIGATE WITH debugger()
debugger(dump=last.dump)
# ALTERNATIVELY, PRINT last.dump TO CONSOLE
last.dump
$`mi(dat)`
<environment: 0x05155c44>
$`mi(dat)`
<environment: 0x05158f30>
$`.local(object, ...)`
<environment: 0x05158cac>
$`mi.default(object, info, n.imp, n.iter, R.hat, max.minutes, rand.imp.method`
<environment: 0x047dc3a0>
attr(,"error.message")
[1] "Error in aveVar[s, i, ] <- c(avevar.mean, avevar.sd) :
\n number of items to replace is not a multiple of replacement length\n"
attr(,"class")
[1] "dump.frames"

glTexCoordPointer problems using OpenGL ES

I have some problems mapping a texture to a triangle strip. I think I still don't fully understand the texture coordinates.
I have a 512x512 texture, and I'm trying to map the 320x64 part of it on a triangle strip.
Here is my code:
static const Vertex3D bg_vertex [] =
{
{ 0, 0, 0}, { 0, 64, 0}, { 64, 0, 0},
{ 64, 64, 0}, {128, 0, 0}, {128, 64, 0},
{192, 0, 0}, {192, 64, 0}, {256, 0, 0},
{256, 64, 0}, {320, 0, 0}, {320, 64, 0}
};
static const GLfloat bg_texcoords [] =
{
{1.000, 0.000}, {1.000, 0.125}, {0.875, 0.000}, {0.875, 0.125}, {0.750, 0.000}, {0.750, 0.125},
{0.625, 0.000}, {0.625, 0.125}, {0.500, 0.000}, {0.500, 0.125}, {0.375, 0.000}, {0.375, 0.125}
};
glBindTexture (GL_TEXTURE_2D, bg1Texture);
glEnable(GL_TEXTURE_2D);
glColor4f (1.0, 1.0, 1.0, 1.0);
glTexCoordPointer(2, GL_FLOAT, 0, bg_texcoords);
glVertexPointer(3, GL_FLOAT, 0, &bg_vertex);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 12);
When I run the code, it displays a distorted image of the original texture on the triangle strips.
Can someone please tell me what am I doing wrong?
Thanks
OK, it works now when I removed the extra braces from the texture coordinates:
static const GLfloat bg_texcoords [] =
{
1.000, 0.000, 1.000, 0.125, 0.875, 0.000, 0.875, 0.125, 0.750, 0.000, 0.750, 0.125,
0.625, 0.000, 0.625, 0.125, 0.500, 0.000, 0.500, 0.125, 0.375, 0.000, 0.375, 0.125
};
Now it maps the texture perfectly on the triangles

Resources