Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'scalar-multiplication' into next
Browse files Browse the repository at this point in the history
  • Loading branch information
guimspace committed May 26, 2021
2 parents 30c97c7 + 6e338b8 commit 9bfaece
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
18 changes: 18 additions & 0 deletions c/src/operation.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@
#include "operation.h"
#include "solve.h"

void scalar_multiplication(env envelope, float scalar)
{
int n = envelope->n;
int i;

if (scalar == 0) {
end_envelope(envelope);
envelope = init_eye_envelope(n, 0);
return;
}

for (i = 0; i < n; i++)
envelope->diagg[i] *= scalar;

for (i = 0; i < envelope->enveCol[n]; i++)
envelope->enve[i] *= scalar;
}

float *multiply_triangles(env triL, env triU)
{
int d, i, j, k;
Expand Down
1 change: 1 addition & 0 deletions c/src/operation.h
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
float *multiply_triangles(env triL, env triU);
void scalar_multiplication(env envelope, float scalar);
31 changes: 31 additions & 0 deletions python/src/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,37 @@

import solve

def scalarMultiplication(enve, m):
envelope = enve['enve']
ENVcol = enve['enveCol']
ENVlin = enve['enveLin']
diagonal = enve['diagg']

p = 0

if m != 0:
n = len(envelope)
while(p < n):
envelope[p] = envelope[p] * m
p = p + 1
else:
n = len(diagonal)
enve['enveCol'] = [0] * (n + 1)
enve['enve'] = [0]


p = 0
n = len(diagonal)

if m == 0:
enve['enveLin'] = []

while(p < n):
if m == 0:
enve['enveLin'].append(p)
diagonal[p] = diagonal[p] * m
p = p + 1

def multiplyTriangles(triL, triU):
n = len(triL['diagg'])

Expand Down

0 comments on commit 9bfaece

Please sign in to comment.