From 97eddc6f61ca53ba39f547360ced35a2f69908cb Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 30 Oct 2016 16:27:12 -0400 Subject: [PATCH] Add a "typecode" parameter to the identity() matrix function. --- dunshire/matrices.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dunshire/matrices.py b/dunshire/matrices.py index 6ed4f85..66c2176 100644 --- a/dunshire/matrices.py +++ b/dunshire/matrices.py @@ -209,7 +209,7 @@ def eigenvalues_re(anymat): return [eig.real for eig in eigs] -def identity(domain_dim): +def identity(domain_dim, typecode='i'): """ Create an identity matrix of the given dimensions. @@ -219,6 +219,10 @@ def identity(domain_dim): domain_dim : int The dimension of the vector space on which the identity will act. + typecode : {'i', 'd', 'z'}, optional + The type code for the returned matrix, defaults to 'i' for integers. + Can also be 'd' for real double, or 'z' for complex double. + Returns ------- @@ -247,7 +251,7 @@ def identity(domain_dim): entries = [int(i == j) for i in range(domain_dim) for j in range(domain_dim)] - return matrix(entries, (domain_dim, domain_dim)) + return matrix(entries, (domain_dim, domain_dim), tc=typecode) def inner_product(vec1, vec2): -- 2.44.2