Skip to content

Commit 054afd5

Browse files
committed
refactor slice to shape_int
1 parent f35a854 commit 054afd5

File tree

4 files changed

+597
-1589
lines changed

4 files changed

+597
-1589
lines changed

Diff for: cmat.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ int create_double_matrix_from_array(shape_uint shape[2], double* array, shape_ui
130130
return 0;
131131
}
132132

133-
int_cmat slice_int_matrix(int_cmat mat, shape_uint slice0[2], shape_uint slice1[2]) {
133+
int_cmat slice_int_matrix(int_cmat mat, shape_int slice0[2], shape_int slice1[2]) {
134134
int_cmat empty_mat;
135135
empty_mat.data = NULL;
136136
empty_mat.arena = NULL;
@@ -169,7 +169,7 @@ int_cmat slice_int_matrix(int_cmat mat, shape_uint slice0[2], shape_uint slice1[
169169
return new_mat;
170170
}
171171

172-
float_cmat slice_float_matrix(float_cmat mat, shape_uint slice0[2], shape_uint slice1[2]) {
172+
float_cmat slice_float_matrix(float_cmat mat, shape_int slice0[2], shape_int slice1[2]) {
173173
float_cmat empty_mat;
174174
empty_mat.data = NULL;
175175
empty_mat.arena = NULL;
@@ -208,7 +208,7 @@ float_cmat slice_float_matrix(float_cmat mat, shape_uint slice0[2], shape_uint s
208208
return new_mat;
209209
}
210210

211-
double_cmat slice_double_matrix(double_cmat mat, shape_uint slice0[2], shape_uint slice1[2]) {
211+
double_cmat slice_double_matrix(double_cmat mat, shape_int slice0[2], shape_int slice1[2]) {
212212
//printf("slice double\n");
213213
double_cmat empty_mat;
214214
empty_mat.data = NULL;
@@ -248,7 +248,7 @@ double_cmat slice_double_matrix(double_cmat mat, shape_uint slice0[2], shape_uin
248248
return new_mat;
249249
}
250250

251-
int create_slice_double_matrix_contiguous(double_cmat *dst, double_cmat mat, shape_uint slice0[2], shape_uint slice1[2]) {
251+
int create_slice_double_matrix_contiguous(double_cmat *dst, double_cmat mat, shape_int slice0[2], shape_int slice1[2]) {
252252
//printf("slice conting\n");
253253
// dst = mat[slice0, slice1]
254254
if (slice0[1] < 0) {
@@ -301,7 +301,7 @@ int create_double_contiguous_from_slice(double_cmat *dest, double_cmat *src) {
301301
return 0;
302302
}
303303

304-
int assign_int_slice(int_cmat m1, int_cmat m2, shape_uint slice0[2], shape_uint slice1[2]) {
304+
int assign_int_slice(int_cmat m1, int_cmat m2, shape_int slice0[2], shape_int slice1[2]) {
305305
if (slice0[1] < 0) {
306306
slice0[1] += m1.shape[0];
307307
}
@@ -320,7 +320,7 @@ int assign_int_slice(int_cmat m1, int_cmat m2, shape_uint slice0[2], shape_uint
320320
return 0;
321321
}
322322

323-
int assign_float_slice(float_cmat m1, float_cmat m2, shape_uint slice0[2], shape_uint slice1[2]) {
323+
int assign_float_slice(float_cmat m1, float_cmat m2, shape_int slice0[2], shape_int slice1[2]) {
324324
if (slice0[1] < 0) {
325325
slice0[1] += m1.shape[0];
326326
}
@@ -339,7 +339,7 @@ int assign_float_slice(float_cmat m1, float_cmat m2, shape_uint slice0[2], shape
339339
return 0;
340340
}
341341

342-
int assign_double_slice(double_cmat m1, double_cmat m2, shape_uint slice0[2], shape_uint slice1[2]) {
342+
int assign_double_slice(double_cmat m1, double_cmat m2, shape_int slice0[2], shape_int slice1[2]) {
343343
//printf("assign slice\n");
344344
// assign m2 to a slice of m1 defined by slice0(x) and slice1(y)
345345
// m1[slice0, slice1] = m2
@@ -718,8 +718,8 @@ int main() {
718718
}
719719
create_double_matrix_from_array(pairint {2, 3}, double_array2, 6, pairint {0, 0}, &array_double2);
720720
print_double_matrix(array_double2);
721-
shape_uint slice_double_lr0[2] = {1, 3};
722-
shape_uint slice_double_lr1[2] = {1, -1};
721+
shape_int slice_double_lr0[2] = {1, 3};
722+
shape_int slice_double_lr1[2] = {1, -1};
723723
double_cmat slice_double2 = slice_double_matrix(array_double2, slice_double_lr0, slice_double_lr1);
724724
print_double_matrix(slice_double2);
725725
free_double_matrix(array_double2);

Diff for: cmat.h

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,37 @@
1414
#include <stdint.h>
1515
#define shape_uint uint32_t
1616
#define shape_int int32_t
17-
// TODO: refactor slice to shape_int
1817

1918

2019
struct int_cmat {
2120
int* arena; // keep all the data in one arena
2221
int** data; // two dim indexing
2322
shape_uint shape[2];
2423
shape_uint arena_shape[2]; // to record the original matrix shape for sliced matrix indexing
25-
shape_uint offset[2]; // to offset sliced matrix index
24+
shape_int offset[2]; // to offset sliced matrix index
2625
};
2726

2827
struct float_cmat {
2928
float* arena; // keep all the data in one arena
3029
float** data; // two dim indexing
3130
shape_uint shape[2];
3231
shape_uint arena_shape[2]; // to record the original matrix shape for sliced matrix indexing
33-
shape_uint offset[2]; // to offset sliced matrix index
32+
shape_int offset[2]; // to offset sliced matrix index
3433
};
3534

3635
struct double_cmat {
3736
double* arena; // keep all the data in one arena
3837
double** data; // two dim indexing
3938
shape_uint shape[2];
4039
shape_uint arena_shape[2]; // to record the original matrix shape for sliced matrix indexing
41-
shape_uint offset[2]; // to offset sliced matrix index
40+
shape_int offset[2]; // to offset sliced matrix index
4241
};
4342

4443
typedef struct int_cmat int_cmat;
4544
typedef struct float_cmat float_cmat;
4645
typedef struct double_cmat double_cmat;
47-
#define pairint (shape_uint[2])
46+
#define pairuint (shape_uint[2])
47+
#define pairint (shape_int[2])
4848

4949
int is_contiguous_double(double_cmat m);
5050

@@ -60,21 +60,21 @@ int create_float_matrix_from_array(shape_uint shape[2], float* array, shape_uint
6060

6161
int create_double_matrix_from_array(shape_uint shape[2], double* array, shape_uint array_length, shape_uint offset[2], double_cmat* p_new_mat);
6262

63-
int_cmat slice_int_matrix(int_cmat mat, shape_uint slice0[2], shape_uint slice1[2]);
63+
int_cmat slice_int_matrix(int_cmat mat, shape_int slice0[2], shape_int slice1[2]);
6464

65-
float_cmat slice_float_matrix(float_cmat mat, shape_uint slice0[2], shape_uint slice1[2]);
65+
float_cmat slice_float_matrix(float_cmat mat, shape_int slice0[2], shape_int slice1[2]);
6666

67-
double_cmat slice_double_matrix(double_cmat mat, shape_uint slice0[2], shape_uint slice1[2]);
67+
double_cmat slice_double_matrix(double_cmat mat, shape_int slice0[2], shape_int slice1[2]);
6868

69-
int create_slice_double_matrix_contiguous(double_cmat *dst, double_cmat mat, shape_uint slice0[2], shape_uint slice1[2]);
69+
int create_slice_double_matrix_contiguous(double_cmat *dst, double_cmat mat, shape_int slice0[2], shape_int slice1[2]);
7070

7171
int create_double_contiguous_from_slice(double_cmat *dest, double_cmat *src);
7272

73-
int assign_int_slice(int_cmat m1, int_cmat m2, shape_uint slice0[2], shape_uint slice1[2]);
73+
int assign_int_slice(int_cmat m1, int_cmat m2, shape_int slice0[2], shape_int slice1[2]);
7474

75-
int assign_float_slice(float_cmat m1, float_cmat m2, shape_uint slice0[2], shape_uint slice1[2]);
75+
int assign_float_slice(float_cmat m1, float_cmat m2, shape_int slice0[2], shape_int slice1[2]);
7676

77-
int assign_double_slice(double_cmat m1, double_cmat m2, shape_uint slice0[2], shape_uint slice1[2]);
77+
int assign_double_slice(double_cmat m1, double_cmat m2, shape_int slice0[2], shape_int slice1[2]);
7878

7979
int assign_double_clone(double_cmat m1, double_cmat m2);
8080

0 commit comments

Comments
 (0)