asc-community / GenericTensor

The only library allowing to create Tensors (matrices extension) with custom types
https://angouri.org/#generictensor
MIT License
50 stars 5 forks source link

Inverting a matrix twice causes the program to get stuck #28

Closed Julpe closed 2 years ago

Julpe commented 2 years ago

I am using the latest release 1.0.4 for my .NET project

When inverting a matrix twice with <GenTensor>.InvertMatrix(), i am expecting it to compute the inverse back to the original matrix, but the program is stuck and will not continue. I tried waiting for a few minutes but nothing has happened.

The matrix i used was one of type GenTensor<Entity, EntityWrapper> containing only diagonal elements ("-1", "1", "r^2", "r^2 * sin(theta)^2")

Julpe commented 2 years ago

For completeness sake: here is my EntityWrapper.cs class:

public struct EntityWrapper : IOperations<Entity> {
        public Entity Add(Entity a, Entity b) {
            return $"{a} + {b}".Trim();
        }

        public Entity Subtract(Entity a, Entity b) {
            return $"{a} - {b}".Trim();
        }

        public Entity Multiply(Entity a, Entity b) {
            return $"({a}) * ({b})".Trim();
        }

        public Entity Negate(Entity a) {
            return $"-({a})";
        }

        public Entity Divide(Entity a, Entity b) {
            return $"({a}) / ({b})".Trim();
        }

        public Entity CreateOne() {
            return "1";
        }

        public Entity CreateZero() {
            return "0";
        }

        public Entity Copy(Entity a) {
            return a;
        }

        public bool AreEqual(Entity a, Entity b) {
            return a == b;
        }

        public bool IsZero(Entity a) {
            return a == "0";
        }

        public string ToString(Entity a) {
            return a.ToString();
        }

        public byte[] Serialize(Entity a) {
            return Encoding.Unicode.GetBytes(a.ToString());
        }

        public Entity Deserialize(byte[] data) {
            return BitConverter.ToString(data, 0);
        }
}