@@ -567,12 +567,54 @@ VALUE cmatrix_dense_zeros(VALUE self, VALUE r, VALUE c)
567567
568568 return result ;
569569}
570- /*
570+
571571VALUE cmatrix_dense_diag (VALUE self , VALUE args )
572572{
573+ int argc = RARRAY_LEN (args );
574+
575+ if (argc != 1 && argc != 2 ){
576+ rb_raise (rb_eTypeError , "Wrong number of arguments" );
577+ }
578+
579+ CDenseMatrix * cresult ;
580+ cresult = dense_matrix_new ();
581+ VALUE result ;
582+
583+ VALUE operand = rb_ary_shift (args );
584+ char * s = rb_obj_classname (operand );
585+
586+ CVecBasic * cargs ;
587+
588+ if (strcmp (s , "Array" ) == 0 ) {
589+ cargs = vecbasic_new ();
590+ basic x ;
591+ basic_new_stack (x );
592+ int cols = RARRAY_LEN (operand );
593+ int j ;
594+ for (j = 0 ; j < cols ; j ++ ) {
595+ sympify (rb_ary_shift (operand ), x );
596+ vecbasic_push_back (cargs , x );
597+ }
598+ basic_free_stack (x );
599+ } else {
600+ rb_raise (rb_eTypeError , "Invalid Argument type" );
601+ }
602+
603+ long int k = 0 ;
604+
605+ if (argc == 2 ) { // With offset
606+ k = NUM2LONG (rb_ary_shift (args ));
607+ }
608+
609+ dense_matrix_diag (cresult , cargs , k );
610+
611+ result = Data_Wrap_Struct (c_dense_matrix , NULL , dense_matrix_free ,
612+ cresult );
613+ vecbasic_free (cargs );
573614
615+ return result ;
574616}
575-
617+ /*
576618VALUE cmatrix_dense_eye(VALUE self, VALUE args)
577619{
578620
0 commit comments