Hi,
Can someone elaborate on what is happening inside the defs here:
using-math-net-numerics-in-ghpython
@piac, I understand the result but what is happening inside the defs?
EDIT:
I figured out that ctor is a ‘constructor’, not sure what that means but I’ll read about it. You can ignore the first part of this post.
def copy_matrix(m, ctor):
n = ctor(m.RowCount, m.ColumnCount)
for r in range(m.RowCount):
for c in range(m.ColumnCount):
n[r,c]=m[r,c]
return n
def to_rh_matrix(dotnet_m):
from Rhino.Geometry import Matrix as rgm
return copy_matrix(dotnet_m,rgm)
def to_dotnet_matrix(rhinocommon_m):
from MathNet.Numerics.LinearAlgebra.Double import Matrix as dnm
dense = dnm.Build.Dense
return copy_matrix(rhinocommon_m,dense)
def copy_vector(m,ctor):
try:
if m.RowCount==1:
n=ctor(m.ColumnCount)
for c in range(m.ColumnCount):
n[c]=m[0,c]
elif m.ColumnCount==1:
n=ctor(m.RowCount)
for r in range(m.RowCount):
n[r]=m[r,0]
except:
n=ctor(m.Count,1)
for i in range(m.Count):
n[1,0]=m[i]
return n
def to_rh_vector(dotnet_v):
from Rhino.Geometry import Matrix as rgm
return copy_vector(dotnet_v,rgm)
def to_dotnet_vector(rhinocommon_v):
from MathNet.Numerics.LinearAlgebra.Double import Vector as dnv
dense = dnv.Build.Dense
return copy_vector (rhinocommon_v,dense)
So about this code what is ctor?
If it is a variable how can you use it without defining it?
Another question is,
I define a matrix and I get output for A:
and output for B:
However, when I try to convert from output A to GH.matrix I get:
Is there a way to define the matrix as a string from the “panel” component?