something like this does work:

julia> using IntModN

julia> a = [GF2(1) GF2(1); GF2(0) GF2(1)]
2x2 Array{ZField{2,Int64},2}:
 1  1
 0  1

ulia> b = inv(a)
2x2 Array{ZField{2,Int64},2}:
 1  1
 0  1

julia> b * a
2x2 Array{ZField{2,Int64},2}:
 1  0
 0  1


that's all GF(2), not integers.

i do subclass Number (i can't remember why, but it's necessary).  i also 
have promotion *from* Int, so that you can add and compare against constant 
integers in the code (typically 0 and 1).

andrew


On Tuesday, 25 March 2014 13:18:06 UTC-3, Andreas Noack Jensen wrote:
>
> Okay. Now I understand what is going on. I would like something like this 
> to work. I'll have to go now, but will think about what to do.
>
>
> 2014-03-25 16:40 GMT+01:00 James Crist <[email protected] <javascript:>>:
>
>> I just realized that my test case is obviously singular, so not 
>> invertible. But I don't think it even gets to the actual inversion code 
>> before erroring, so I doubt that's the problem.
>>
>> -Jim
>>
>>
>> On Tuesday, March 25, 2014 10:38:45 AM UTC-5, James Crist wrote:
>>>
>>> Here's the gist: https://gist.github.com/jcrist/ad663d6bdc4d82896176
>>>
>>> I tried to simplify everything down to just the bare essentials, but 
>>> there may be something I missed. Gives the same error as it did in the full
>>> code though, so I think I got it all.
>>>
>>> I'm running version 0.2.0.
>>>
>>> Thanks,
>>>
>>> -Jim
>>>
>>> On Tuesday, March 25, 2014 10:21:10 AM UTC-5, Andreas Noack Jensen wrote:
>>>>
>>>> A gist would be helpful. By the way, which version of Julia are you 
>>>> running?
>>>>
>>>>
>>>> 2014-03-25 16:19 GMT+01:00 James Crist <[email protected]>:
>>>>
>>>>> I'm probably not. New to this language, still figuring things out. The 
>>>>> matrix type seems to be inferred correctly though. I'll put a gist up in 
>>>>> a 
>>>>> bit to try and get some more relevant feedback.
>>>>>
>>>>>
>>>>> On Tuesday, March 25, 2014 9:54:53 AM UTC-5, Andreas Noack Jensen 
>>>>> wrote:
>>>>>
>>>>>> I don't think you are right about LAPACK. The code tries to promote 
>>>>>> to a type which is stable under lu factorizing which is the intermediate 
>>>>>> step in the calculation. The problem could be that your matrix type is 
>>>>>> not 
>>>>>> inferred correctly. Please try to let your type by subtype of Number and 
>>>>>> then define your matrix by
>>>>>>
>>>>>> a = Mytype[mytype(1) mytype(2); mytype(3) mytype(4)]
>>>>>>
>>>>>> and see if it works.
>>>>>>
>>>>>>
>>>>>> 2014-03-25 15:29 GMT+01:00 James Crist <[email protected]>:
>>>>>>
>>>>>> Yeah, I get a "ERROR: no method Triangular{..." error, because my 
>>>>>>> type doesn't subtype Number. If I do subtype number, then it wants a 
>>>>>>> conversion function to convert it to a float, so it can use the LAPACK 
>>>>>>> routines.
>>>>>>>
>>>>>>> -Jim
>>>>>>>
>>>>>>>
>>>>>>> On Tuesday, March 25, 2014 9:22:29 AM UTC-5, Andreas Noack Jensen 
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Have you tried to invert it? Maybe it works already. There is a 
>>>>>>>> generic inv in base/linalg/generic.jl. You'll have to define a one 
>>>>>>>> method 
>>>>>>>> for you type and maybe also a zero method.
>>>>>>>>
>>>>>>>>
>>>>>>>> 2014-03-25 15:14 GMT+01:00 James Crist <[email protected]>:
>>>>>>>>
>>>>>>>> I have a type I've defined. It's not a number, but it has all 
>>>>>>>>> arithmetic operations defined for it. Is there a way to calculate the 
>>>>>>>>> inverse of a matrix of a user defined type? For example, if I was to 
>>>>>>>>> define:
>>>>>>>>>
>>>>>>>>> a = [mytype(1) mytype(2); mytype(3) mytype(4)]
>>>>>>>>> b = inv(a)
>>>>>>>>>
>>>>>>>>> Looking through base, there doesn't seem to be a way to find 
>>>>>>>>> inverses of non-numeric matrices (although I may be missing it). For 
>>>>>>>>> my 
>>>>>>>>> case, even a simple algorithm that only works well for small matrices 
>>>>>>>>> (<10x10) would be more than sufficient. If a way for doing this 
>>>>>>>>> doesn't 
>>>>>>>>> currently exist, I'll probably try to roll my own.
>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> -- 
>>>>>>>> Med venlig hilsen
>>>>>>>>
>>>>>>>> Andreas Noack Jensen
>>>>>>>>  
>>>>>>>
>>>>>>
>>>>>>
>>>>>> -- 
>>>>>> Med venlig hilsen
>>>>>>
>>>>>> Andreas Noack Jensen
>>>>>>  
>>>>>
>>>>
>>>>
>>>> -- 
>>>> Med venlig hilsen
>>>>
>>>> Andreas Noack Jensen
>>>>  
>>>
>
>
> -- 
> Med venlig hilsen
>
> Andreas Noack Jensen
>  

Reply via email to