Skip to content

Commit

Permalink
fixing matrix allocation in Kernel and Distance
Browse files Browse the repository at this point in the history
close istream in OutputStream test before deleting the file
  • Loading branch information
vigsterkr committed Mar 20, 2020
1 parent e56697c commit ca81ec2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
6 changes: 2 additions & 4 deletions src/shogun/distance/Distance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,6 @@ void Distance::init()
template <class T>
SGMatrix<T> Distance::get_distance_matrix()
{
T* result = NULL;

require(has_features(), "no features assigned to distance");
init(lhs, rhs);

Expand All @@ -283,7 +281,7 @@ SGMatrix<T> Distance::get_distance_matrix()

SG_DEBUG("returning distance matrix of size {}x{}", m, n)

result=SG_MALLOC(T, total_num);
SGMatrix<T> result (m,n);

PRange<int64_t> pb = PRange<int64_t>(
range(total_num), "PROGRESS: ", UTF8, []() { return true; });
Expand Down Expand Up @@ -342,7 +340,7 @@ SGMatrix<T> Distance::get_distance_matrix()
}
pb.complete();

return SGMatrix<T>(result,m,n,true);
return result;
}

template SGMatrix<float64_t> Distance::get_distance_matrix<float64_t>();
Expand Down
10 changes: 4 additions & 6 deletions src/shogun/kernel/Kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1306,8 +1306,6 @@ template <class T> void* Kernel::get_kernel_matrix_helper(void* p)
template <class T>
SGMatrix<T> Kernel::get_kernel_matrix()
{
T* result = NULL;

require(has_features(), "no features assigned to kernel");

int32_t m=get_num_vec_lhs();
Expand All @@ -1320,7 +1318,7 @@ SGMatrix<T> Kernel::get_kernel_matrix()

SG_DEBUG("returning kernel matrix of size {}x{}", m, n)

result=SG_MALLOC(T, total_num);
SGMatrix<T> result(m,n);

int32_t num_threads=env()->get_num_threads();
K_THREAD_PARAM<T> params;
Expand All @@ -1331,7 +1329,7 @@ SGMatrix<T> Kernel::get_kernel_matrix()
for (t = 0; t < num_threads; ++t)
{
params.kernel = this;
params.result = result;
params.result = result.matrix;
params.start = compute_row_start(t*step, n, symmetric);
params.end = compute_row_start((t+1)*step, n, symmetric);
params.total_start=t*step;
Expand All @@ -1346,7 +1344,7 @@ SGMatrix<T> Kernel::get_kernel_matrix()
if (total_num % num_threads != 0)
{
params.kernel = this;
params.result = result;
params.result = result.matrix;
params.start = compute_row_start(t*step, n, symmetric);
params.end = m;
params.total_start=t*step;
Expand All @@ -1360,7 +1358,7 @@ SGMatrix<T> Kernel::get_kernel_matrix()

pb.complete();

return SGMatrix<T>(result,m,n,true);
return result;
}


Expand Down
1 change: 1 addition & 0 deletions tests/unit/io/stream/OutputStream_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ TEST(FileOutputStream, write)
ifstream is(fname);
char str_in[5];
is.get(&str_in[0], 5);
is.close();
EXPECT_EQ(test_str, string(str_in));
r = fs_registry->delete_file(fname);
ASSERT_FALSE(r);
Expand Down

0 comments on commit ca81ec2

Please sign in to comment.