Skip to content

Commit 7f894e0

Browse files
author
Ronan Collobert
committed
added access methods in convolutions/ classes, a copy parameters method in GradientMachine. minor change in PNMLoader.
git-archimport-id: [email protected]/torch--devel--1.0--patch-70
1 parent a566321 commit 7f894e0

11 files changed

+142
-5
lines changed

convolutions/T4SpatialConvolution.h

+7
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,14 @@
7676
kernelWidthStep: (int)aDW
7777
kernelHeightStep: (int)aDH;
7878

79+
-(int)numberOfInputPlanes;
7980
-(int)numberOfOutputPlanes;
81+
-(int)inputWidth;
82+
-(int)inputHeight;
83+
-(int)kernelWidth;
84+
-(int)kernelHeight;
85+
-(int)kernelWidthStep;
86+
-(int)kernelHeightStep;
8087
-(int)outputWidth;
8188
-(int)outputHeight;
8289

convolutions/T4SpatialConvolution.m

+35
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,46 @@ -(T4Matrix*)backwardGradOutputs: (T4Matrix*)someGradOutputs inputs: (T4Matrix*)s
235235
return gradInputs;
236236
}
237237

238+
-(int)numberOfInputPlanes
239+
{
240+
return numInputPlanes;
241+
}
242+
238243
-(int)numberOfOutputPlanes
239244
{
240245
return numOutputPlanes;
241246
}
242247

248+
-(int)inputWidth
249+
{
250+
return inputWidth;
251+
}
252+
253+
-(int)inputHeight
254+
{
255+
return inputHeight;
256+
}
257+
258+
-(int)kernelWidth
259+
{
260+
return kW;
261+
}
262+
263+
-(int)kernelHeight
264+
{
265+
return kH;
266+
}
267+
268+
-(int)kernelWidthStep
269+
{
270+
return dW;
271+
}
272+
273+
-(int)kernelHeightStep
274+
{
275+
return dH;
276+
}
277+
243278
-(int)outputHeight
244279
{
245280
return outputHeight;

convolutions/T4SpatialSubSampling.h

+7
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@
7373
kernelHeightStep: (int)aDH;
7474

7575

76+
-(int)numberOfInputPlanes;
77+
-(int)inputWidth;
78+
-(int)inputHeight;
79+
-(int)kernelWidth;
80+
-(int)kernelHeight;
81+
-(int)kernelWidthStep;
82+
-(int)kernelHeightStep;
7683
-(int)outputWidth;
7784
-(int)outputHeight;
7885

convolutions/T4SpatialSubSampling.m

+35
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,41 @@ -(T4Matrix*)backwardGradOutputs: (T4Matrix*)someGradOutputs inputs: (T4Matrix*)s
203203
return gradInputs;
204204
}
205205

206+
-(int)numberOfInputPlanes
207+
{
208+
return numInputPlanes;
209+
}
210+
211+
-(int)inputWidth
212+
{
213+
return inputWidth;
214+
}
215+
216+
-(int)inputHeight
217+
{
218+
return inputHeight;
219+
}
220+
221+
-(int)kernelWidth
222+
{
223+
return kW;
224+
}
225+
226+
-(int)kernelHeight
227+
{
228+
return kH;
229+
}
230+
231+
-(int)kernelWidthStep
232+
{
233+
return dW;
234+
}
235+
236+
-(int)kernelHeightStep
237+
{
238+
return dH;
239+
}
240+
206241
-(int)outputHeight
207242
{
208243
return outputHeight;

convolutions/T4TemporalConvolution.h

+3
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,7 @@
4141
kernelTimeWidth: (int)aKW
4242
kernelTimeStep: (int)aDT;
4343

44+
-(int)kernelTimeWidth;
45+
-(int)kernelTimeStep;
46+
4447
@end

convolutions/T4TemporalConvolution.m

+10
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ -(T4Matrix*)backwardGradOutputs: (T4Matrix*)someGradOutputs inputs: (T4Matrix*)s
156156
return gradInputs;
157157
}
158158

159+
-(int)kernelTimeWidth
160+
{
161+
return kW;
162+
}
163+
164+
-(int)kernelTimeStep
165+
{
166+
return dT;
167+
}
168+
159169
-initWithCoder: (NSCoder*)aCoder
160170
{
161171
self = [super initWithCoder: aCoder];

convolutions/T4TemporalSubSampling.h

+3
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,7 @@
4040
kernelTimeWidth: (int)aKW
4141
kernelTimeStep: (int)aDT;
4242

43+
-(int)kernelTimeWidth;
44+
-(int)kernelTimeStep;
45+
4346
@end

convolutions/T4TemporalSubSampling.m

+10
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,16 @@ -(T4Matrix*)backwardGradOutputs: (T4Matrix*)someGradOutputs inputs: (T4Matrix*)s
141141
return gradInputs;
142142
}
143143

144+
-(int)kernelTimeWidth
145+
{
146+
return kW;
147+
}
148+
149+
-(int)kernelTimeStep
150+
{
151+
return dT;
152+
}
153+
144154
-initWithCoder: (NSCoder*)aCoder
145155
{
146156
self = [super initWithCoder: aCoder];

datasets/T4PNMLoader.m

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ -(T4Matrix*)loadMatrixFromFile: (T4File*)aFile
8080
else
8181
imageHeight = theImageHeight;
8282

83-
int imageMaxValue = 0;
83+
int pnmMaxValue = 0;
8484
if( (pnmType != 4) && (pnmType != 1) )
8585
{
8686
stringBuffer = [file stringToEndOfLine];
8787
if(!stringBuffer)
8888
T4Error(@"PNMLoader: file is not in a PNM format");
8989
charBuffer = [stringBuffer cString];
90-
sscanf(charBuffer, "%d", &imageMaxValue);
90+
sscanf(charBuffer, "%d", &pnmMaxValue);
9191
}
9292

9393
int theImageType;
@@ -103,7 +103,7 @@ -(T4Matrix*)loadMatrixFromFile: (T4File*)aFile
103103
else
104104
imageType = theImageType;
105105

106-
T4Message(@"PNMLoader: detected image: <%d x %d> with max value: <%d> [mode %d]", imageWidth, imageHeight, imageMaxValue, pnmType);
106+
T4Message(@"PNMLoader: detected image: <%d x %d> with max value: <%d> [mode %d]", imageWidth, imageHeight, pnmMaxValue, pnmType);
107107

108108
// Reading
109109

@@ -181,7 +181,7 @@ -(T4Matrix*)loadMatrixFromFile: (T4File*)aFile
181181

182182
case 5:
183183
case 6:
184-
if(imageMaxValue > 255)
184+
if(pnmMaxValue > 255)
185185
{
186186
ucharBuffer = (unsigned char *)[T4Allocator sysAllocByteArrayWithCapacity: matrixSize*2];
187187

@@ -197,7 +197,7 @@ -(T4Matrix*)loadMatrixFromFile: (T4File*)aFile
197197
{
198198
ucharBuffer = (unsigned char *)[T4Allocator sysAllocByteArrayWithCapacity: matrixSize];
199199

200-
if([file readBlocksInto: ucharBuffer blockSize: 1 numberOfBlocks: matrixSize*2] != matrixSize)
200+
if([file readBlocksInto: ucharBuffer blockSize: 1 numberOfBlocks: matrixSize] != matrixSize)
201201
T4Error(@"PNMLoader: error while reading");
202202

203203
for(i = 0; i < matrixSize; i++)

gradients/T4GradientMachine.h

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242

4343
-setCriterion: (T4Criterion*)aCriterion;
4444

45+
-copyParametersFromMachine: (T4GradientMachine*)aMachine;
46+
4547
-(int)numberOfInputs;
4648
-(int)numberOfOutputs;
4749
-(T4Matrix*)outputs;

gradients/T4GradientMachine.m

+25
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,31 @@ -(T4Matrix*)backwardGradOutputs: (T4Matrix*)someGradOutputs inputs: (T4Matrix*)s
292292
return self;
293293
}
294294

295+
296+
-copyParametersFromMachine: (T4GradientMachine*)aMachine
297+
{
298+
NSArray *copyParameters = [aMachine parameters];
299+
int numSelfParameterMatrices = [parameters count];
300+
int numCopyParameterMatrices = [copyParameters count];
301+
int i;
302+
303+
if(numCopyParameterMatrices != numSelfParameterMatrices)
304+
T4Error(@"GradientMachine: incompatible number of parameters during copy");
305+
306+
for(i = 0; i < numSelfParameterMatrices; i++)
307+
{
308+
T4Matrix *matrix = [parameters objectAtIndex: i];
309+
T4Matrix *copyMatrix = [copyParameters objectAtIndex: i];
310+
311+
if([matrix numberOfRows] != [copyMatrix numberOfRows])
312+
T4Error(@"GradientMachine: incompatible number of parameters during copy");
313+
314+
[matrix copyMatrix: copyMatrix];
315+
}
316+
317+
return self;
318+
}
319+
295320
-(int)numberOfInputs
296321
{
297322
return numInputs;

0 commit comments

Comments
 (0)