Skip to content

Commit

Permalink
ENH: optimize usage of tmps in matrix_representation
Browse files Browse the repository at this point in the history
  • Loading branch information
kohr-h committed Nov 26, 2015
1 parent 1c678f0 commit 38ba1a6
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions odl/operator/oputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,29 @@ def matrix_representation(op):
# Generate the matrix
matrix = np.zeros([np.sum(n), np.sum(m)])
tmp_ran = op.range.element() # Store for reuse in loop
tmp_dom = op.domain.element() # Store for reuse in loop
tmp_dom = op.domain.zero() # Store for reuse in loop
index = 0
last_i = last_j = 0

for i in range(num_dom):
for j in range(m[i]):
tmp_dom.set_zero()
if op_dom_is_prod_space:
tmp_dom[last_i][last_j] = 0.0
tmp_dom[i][j] = 1.0
else:
tmp_dom[last_j] = 0.0
tmp_dom[j] = 1.0
op(tmp_dom, out=tmp_ran)
if op_ran_is_prod_space:
tmp_result = np.empty(np.sum(n))
tmp_idx = 0
for k in range(num_ran):
tmp_result[tmp_idx: tmp_idx + op.range[k].size] = \
tmp_ran[k].asarray()
matrix[tmp_idx: tmp_idx + op.range[k].size, index] = (
tmp_ran[k])
tmp_idx += op.range[k].size
else:
tmp_result = tmp_ran.asarray()
matrix[:, index] = tmp_result
matrix[:, index] = tmp_ran.asarray()
index += 1
last_j = j
last_i = i

return matrix

0 comments on commit 38ba1a6

Please sign in to comment.