diff --git a/src/builtins/complex.pir b/src/builtins/complex.pir index ffe6926..2a93f13 100644 --- a/src/builtins/complex.pir +++ b/src/builtins/complex.pir @@ -18,33 +18,3 @@ $P0 = "1i" .return ($P0) .end - - -.sub 'conj' - .param int nargout - .param int nargin - .param pmc x - -$S0 = <<"EOS" -.sub '' :anon - .param int nargout - .param int nargin - .param pmc z - $S0 = typeof z - unless $S0 == 'Complex' goto return_conj - $N0 = z["imag"] - $N0 = $N0 * -1 - z["imag"] = $N0 - return_conj: - .return(z) -.end -EOS - - $P0 = compreg "PIR" - $P1 = $P0($S0) - $P2 = $P1[0] - $P3 = '!lookup_function'('arrayfun') - $P4 = $P3(1,1,$P2,x) - .return($P4) -.end - diff --git a/src/classes/matrix_row.pir b/src/classes/matrix_row.pir index f4ccf20..b0c2539 100644 --- a/src/classes/matrix_row.pir +++ b/src/classes/matrix_row.pir @@ -6,6 +6,7 @@ addattribute $P0, "has_number" addattribute $P0, "row" addattribute $P0, "row_length" + addattribute $P0, "has_complex" .end .sub 'init' :vtable @@ -17,6 +18,8 @@ setattribute self, "has_number", $P0 $P0 = box 0 setattribute self, "row_length", $P0 + $P0 = box 0 + setattribute self, "has_complex", $P0 .end .sub 'get_iter' :vtable @@ -69,6 +72,22 @@ .return(has_number) .end +.sub 'has_complex' :method + .param int has_complex :optional + .param int has_has_complex :opt_flag + + if has_has_complex goto set_has_complex + $P0 = getattribute self, "has_complex" + $I0 = $P0 + .return($I0) + + set_has_complex: + $P0 = box has_complex + setattribute self, "has_complex", $P0 + .return(has_complex) +.end + + .sub 'row_length' :method $P0 = getattribute self, "row_length" $I0 = $P0 @@ -86,10 +105,12 @@ .local pmc arg .local pmc has_string .local pmc has_number + .local pmc has_complex .local int row_length row_length = 0 has_string = getattribute self, "has_string" has_number = getattribute self, "has_number" + has_complex = getattribute self, "has_complex" myiter = iter args loop_top: unless myiter goto loop_bottom @@ -98,6 +119,7 @@ if $S0 == "Integer" goto has_arg_number if $S0 == "Float" goto has_arg_number if $S0 == "String" goto has_arg_string + if $S0 == "Complex" goto has_arg_complex # TODO: What here? goto loop_top has_arg_number: @@ -110,6 +132,11 @@ $I0 = length $S0 row_length = row_length + $I0 goto loop_top + has_arg_complex: + has_number = 1 + has_complex = 1 + inc row_length + goto loop_top loop_bottom: setattribute self, "row", args diff --git a/src/internals/aggregates.pir b/src/internals/aggregates.pir index 3e076a5..d720953 100644 --- a/src/internals/aggregates.pir +++ b/src/internals/aggregates.pir @@ -15,6 +15,8 @@ .param pmc args :slurpy $P0 = new ['matrix_row'] $P0.'build_row'(args) + $I0 = $P0.'row_length'() + say $I0 .return($P0) .end @@ -24,14 +26,16 @@ # Setup local variables .local pmc thisrow .local pmc lengths + .local int numbers + .local int strings + .local int complex lengths = new ['FixedIntegerArray'] $I0 = ary lengths = $I0 .local int idx idx = 0 - .local int numbers numbers = 0 - .local int strings + complex = 0 strings = 0 .local pmc myiter myiter = iter ary @@ -44,12 +48,14 @@ numbers = or numbers, $I0 $I0 = thisrow.'has_string'() strings = or strings, $I0 + $I0 = thisrow.'has_complex'() + complex = or complex, $I0 $I0 = thisrow.'row_length'() lengths[idx] = $I0 inc idx goto loop_top loop_bottom: - .return(lengths, numbers, strings) + .return(lengths, numbers, strings, complex) .end .sub '!_verify_array_lengths_equal' @@ -90,6 +96,31 @@ .return(matrix) .end +.sub '!_build_complex_matrix' + .param pmc rows + .local pmc matrix + .local int x + .local int y + .local int width + .local int height + matrix = new ['NumMatrix2D'] + y = 0 + height = rows + $P0 = rows[0] + width = $P0 + outer_loop_top: + x = 0 + $P0 = rows[y] + inner_loop_top: + $P1 = $P0[x] + matrix[x;y] = $P1 + inc x + if x < width goto inner_loop_top + inc y + if y < height goto outer_loop_top + .return(matrix) +.end + .sub '!_build_string_matrix' .param pmc rows .local pmc matrix @@ -114,6 +145,7 @@ .local pmc lengths .local int has_numbers .local int has_strings + .local int has_complex # If there are no rows, just return an empty matrix $I0 = ary @@ -122,15 +154,21 @@ .return($P0) construct_the_matrix: - (lengths, has_numbers, has_strings) = '!_get_rows_info'(ary) + (lengths, has_numbers, has_strings, has_complex) = '!_get_rows_info'(ary) unless has_numbers goto dont_check_length '!_verify_array_lengths_equal'(lengths) dont_check_length: + if has_complex goto build_complex_matrix if has_strings goto build_string_matrix .tailcall '!_build_numerical_matrix'(ary) build_string_matrix: .tailcall '!_build_string_matrix'(ary) + build_complex_matrix: + if has_strings goto cant_have_both + .tailcall '!_build_complex_matrix'(ary) + cant_have_both: + _error_all("Cannot have both complex and string values in one matrix") .end .sub '!matrix' diff --git a/t/305-clapack.t b/t/305-clapack.t deleted file mode 100644 index 6a76ed7..0000000 --- a/t/305-clapack.t +++ /dev/null @@ -1,53 +0,0 @@ -function y = round2(N, d) - y = round(N.*(10^d))./(10^d); -endfunction - -if libisloaded('CLAPACK') - plan(8) - - A = [ 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 2.6 ; 1.2 1.0 1.2 1.4 1.6 1.8 2.0 2.2 2.4 ; 1.4 1.2 1.0 1.2 1.4 1.6 1.8 2.0 2.2 ; 1.6 1.4 1.2 1.0 1.2 1.4 1.6 1.8 2.0 ; 1.8 1.6 1.4 1.2 1.0 1.2 1.4 1.6 1.8 ; 2.0 1.8 1.6 1.4 1.2 1.0 1.2 1.4 1.6 ; 2.2 2.0 1.8 1.6 1.4 1.2 1.0 1.2 1.4 ; 2.4 2.2 2.0 1.8 1.6 1.4 1.2 1.0 1.2 ; 2.6 2.4 2.2 2.0 1.8 1.6 1.4 1.2 1.0 ]; - IP = [0;0;0;0;0;0;0;0;0]; - info = -1; - - calllib('CLAPACK', 'dgetrf_', 9,9,A,9,IP,info); - - A1=[2.6,2.4,2.2,2.0,1.8,1.6,1.4,1.2,1.0;0.4,0.3,0.6,0.8,1.1,1.4,1.7,1.9,2.2;0.5,-0.4,0.4,0.8,1.2,1.6,2.0,2.4,2.8;0.5,-0.3,0.0,0.4,0.8,1.2,1.6,2.0,2.4;0.6,-0.3,0.0,0.0,0.4,0.8,1.2,1.6,2.0;0.7,-0.2,0.0,0.0,0.0,0.4,0.8,1.2,1.6;0.8,-0.2,0.0,0.0,0.0,0.0,0.4,0.8,1.2;0.8,-0.1,0.0,0.0,0.0,0.0,0.0,0.4,0.8;0.9,-0.1,0.0,0.0,0.0,0.0,0.0,0.0,0.4]; - IP1 = [9;9;9;9;9;9;9;9;9]; - - is(info, 0, "dgetrf correct info 1") - is(round2(A,1), A1, "dgetrf correct A 1") - is(IP, IP1, "dgetrf correct IP 1") - - - # Ex 3 - # - A = [ 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 0.0 ; 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 0.0 ; 4.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 0.0 ; 0.0 5.0 1.0 1.0 1.0 1.0 1.0 0.0 0.0 ; 0.0 0.0 6.0 1.0 1.0 1.0 1.0 1.0 0.0 ; 0.0 0.0 0.0 7.0 1.0 1.0 1.0 1.0 1.0 ; 0.0 0.0 0.0 0.0 8.0 1.0 1.0 1.0 1.0 ; 0.0 0.0 0.0 0.0 0.0 9.0 1.0 1.0 1.0 ; 0.0 0.0 0.0 0.0 0.0 0.0 10.0 11.0 12.0 ]; - IP = [0;0;0;0;0;0;0;0;0]; - info = -1; - - calllib('CLAPACK', 'dgetrf_', 9,9,A,9,IP,info); - - A1 = [4.0000,1.0000,1.0000,1.0000, 1.0000, 1.0000, 0.0000, 0.0000, 0.0000 ;0.0000,5.0000,1.0000,1.0000, 1.0000, 1.0000, 1.0000, 0.0000, 0.0000 ;0.0000,0.0000,6.0000,1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.0000 ;0.0000,0.0000,0.0000,7.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000 ;0.0000,0.0000,0.0000,0.0000, 8.0000, 1.0000, 1.0000, 1.0000, 1.0000 ;0.0000,0.0000,0.0000,0.0000, 0.0000, 9.0000, 1.0000, 1.0000, 1.0000 ;0.0000,0.0000,0.0000,0.0000, 0.0000, 0.0000,10.0000,11.0000,12.0000 ;0.2500,0.1500,0.1000,0.0714, 0.0536,-0.0694,-0.0306, 0.1806, 0.3111 ;0.2500,0.1500,0.1000,0.0714,-0.0714,-0.0556,-0.0194, 0.9385,-0.0031]; - IP1 = [3;4;5;6;7;8;9;8;9]; - - is(info, 0, "dgetrf correct info 2") - is(round2(A,4), A1, "dgetrf correct A 2") - is(IP, IP1, "dgetrf correct IP 2") - - - # Ex 1 - # - info = -1; - WORK = zeros(10, 1); - - calllib('CLAPACK', 'dgetri_', 9, A, 9, IP, WORK, 10, info); - - A1 = [0.333,-0.667,0.333,0.000,0.000,0.000,0.042,-0.042,0.000; 56.833,-52.167,-1.167,-0.500,-0.500,-0.357,6.836,-0.479,-0.500; -55.167,51.833,0.833,0.500,0.500,0.214,-6.735,0.521,0.500; -1.000,1.000,0.000,0.000,0.000,0.143,-0.143,0.000,0.000; -1.000,1.000,0.000,0.000,0.000,0.000,0.000,0.000,0.000; -1.000,1.000,0.000,0.000,0.000,0.000,-0.125,0.125,0.000; -226.000,206.000,5.000,3.000,2.000,1.429,-27.179,1.750,2.000;560.000,-520.000,-10.000,-6.000,-4.000,-2.857,67.857,-5.000,-5.000; -325.000,305.000,5.000,3.000,2.000,1.429,-39.554,3.125,3.000]; - - is(info, 0, "dgetri correct info 1") - is(round2(A,3), A1, "dgetri correct A 1") - -else - plan(0) -end -