@@ -427,13 +427,13 @@ def evalgrsum( self, isobj, glist, x, nargout ):
427427 # Evaluate the linear term, if any.
428428
429429 if hasattr (self ,"gconst" ) and ig < len (self .gconst ) and not self .gconst [ig ] is None :
430- fin = float (- self .gconst [ig ])
430+ fin = float (np . array ( - self .gconst [ig ]). item () )
431431 else :
432432 fin = 0
433433 if has_A and ig < sA1 :
434434 gin = np .zeros ( (n , 1 ) )
435435 gin [:sA2 , :1 ] = self .A [ ig , :sA2 ].T .toarray ()
436- fin = float ( fin + gin .T .dot (x ) )
436+ fin = float (np . array ( fin + gin .T .dot (x ) ). item () )
437437 elif nargout >= 2 :
438438 gin = np .zeros (( n , 1 ))
439439
@@ -448,7 +448,7 @@ def evalgrsum( self, isobj, glist, x, nargout ):
448448 iel = self .grelt [ ig ][ iiel ] # the element's index
449449 efname = self .elftype [ iel ] # the element's ftype
450450 irange = [iv for iv in self .elvar [ iel ]] # the elemental variable's indeces
451- xiel = x [ np .array (irange ) ] # the elemental variable's values
451+ xiel = x [ np .array (irange ) ]. flatten (). flatten () # the elemental variable's values
452452
453453 if hasattr ( self , 'grelw' ) and ig <= len ( self .grelw ) and not self .grelw [ig ] is None :
454454 has_weights = True ;
@@ -621,11 +621,11 @@ def evalgrsum( self, isobj, glist, x, nargout ):
621621 print ( "ig = " , ig , " cx(final) = " , cx )#D
622622 if isobj :
623623 if nargout == 1 :
624- return float ( fx )
624+ return float (np . array ( fx ). item () )
625625 elif nargout == 2 :
626- return float ( fx ), gx .reshape (- 1 ,1 )
626+ return float (np . array ( fx ). item () ), gx .reshape (- 1 ,1 )
627627 elif nargout == 3 :
628- return float ( fx ), gx .reshape (- 1 ,1 ), Hx
628+ return float (np . array ( fx ). item () ), gx .reshape (- 1 ,1 ), Hx
629629 else :
630630 if nargout == 1 :
631631 return cx
@@ -711,7 +711,7 @@ def evalHJv( self, mode, glist, x, v, y ):
711711 # Evaluate the quadratic term, if any.
712712
713713 if mode == "Hv" and hasattr ( self , "H" ):
714- HJv += self .H .dot (v );
714+ HJv += self .H .dot (v ). item () ;
715715
716716 if debug : #D
717717 print ( "HJv(quadratic) = " , HJv )
@@ -750,13 +750,13 @@ def evalHJv( self, mode, glist, x, v, y ):
750750 # Evaluate the linear term, if any.
751751
752752 if hasattr ( self , "gconst" ) and ig < len ( self .gconst ) and not self .gconst [ ig ] is None :
753- fin = float (- self .gconst [ ig ] )
753+ fin = float (np . array ( - self .gconst [ ig ] ). item () )
754754 else :
755755 fin = 0.0
756756 gin = np .zeros ((n ,1 ))
757757 if has_A and ig < sA1 :
758758 gin [:sA2 , :1 ] = self .A [ ig , :sA2 ].T .toarray ()
759- fin = float (fin + gin .T .dot (x ))
759+ fin = float (np . array ( fin + gin .T .dot (x )). item ( ))
760760
761761 if debug :
762762 print ( "ig = " , ig , " fin(linear)" , fin ) #D
@@ -768,7 +768,7 @@ def evalHJv( self, mode, glist, x, v, y ):
768768 iel = self .grelt [ ig ][ iiel ] # the element's index
769769 efname = self .elftype [ iel ]; # the element's ftype
770770 irange = [iv for iv in self .elvar [ iel ]] # the elemental variable's indeces
771- xiel = x [ np .array (irange ) ] # the elemental variable's values
771+ xiel = x [ np .array (irange ) ]. flatten (). flatten () # the elemental variable's values
772772
773773 if hasattr ( self , 'grelw' ) and ig <= len ( self .grelw ) and not self .grelw [ig ] is None :
774774 has_weights = 1 ;
@@ -831,7 +831,7 @@ def evalHJv( self, mode, glist, x, v, y ):
831831 else :
832832 fa , grada , Hessa = eval ('self.' + egname + '( self, 3, fin, ig )' )
833833 sgin = lil_matrix (gin );
834- HJv += ( ( Hessa * sgin ) * (sgin .transpose ().dot (v )) + grada * Hinv ) / gsc
834+ HJv += ( ( Hessa * sgin ) * (sgin .transpose ().dot (v ). item () ) + grada * Hinv ) / gsc
835835 elif mode == "HIv" :
836836 if egname == "TRIVIAL" :
837837 ic += 1
@@ -840,7 +840,7 @@ def evalHJv( self, mode, glist, x, v, y ):
840840 fa , grada , Hessa = eval ('self.' + egname + '( self, 3, fin, ig )' )
841841 sgin = lil_matrix (gin );
842842 ic += 1
843- HJv += y [ic ] * ( ( Hessa * sgin ) * (sgin .transpose ().dot (v )) + grada * Hinv ) / gsc
843+ HJv += y [ic ] * ( ( Hessa * sgin ) * (sgin .transpose ().dot (v ). item () ) + grada * Hinv ) / gsc
844844 elif mode == "Jv" :
845845 ic += 1
846846 if derlvl >= 1 :
@@ -883,7 +883,7 @@ def evalLx( self, gobjlist, gconlist, x, y, nargout ):
883883 if len ( gconlist ):
884884 c = self .evalgrsum ( False , gconlist , x , 1 )
885885 Lxy = Lxy + y .T .dot (c )
886- return float (Lxy )
886+ return float (np . array ( Lxy ). item () )
887887 elif nargout == 2 :
888888 if len ( gobjlist ) or hasattr ( self , "H" ):
889889 Lxy , Lgxy = self .evalgrsum ( True , gobjlist , x , 2 )
@@ -894,7 +894,7 @@ def evalLx( self, gobjlist, gconlist, x, y, nargout ):
894894 c , J = self .evalgrsum ( False , gconlist , x , 2 )
895895 Lxy = Lxy + y .T .dot (c )
896896 Lgxy = Lgxy + J .T .dot (y )
897- return float (Lxy ), Lgxy
897+ return float (np . array ( Lxy ). item () ), Lgxy
898898 elif nargout == 3 :
899899 if len ( gobjlist ) or hasattr ( self , "H" ):
900900 Lxy , Lgxy , LgHxy = self .evalgrsum ( True , gobjlist , x , 3 )
@@ -909,7 +909,7 @@ def evalLx( self, gobjlist, gconlist, x, y, nargout ):
909909 Lgxy = Lgxy + J .T .dot (y )
910910 for ig in range ( len ( gconlist ) ):
911911 LgHxy = LgHxy + y [ig ,0 ] * cHi [ig ]
912- return float (Lxy ), Lgxy .reshape (- 1 ,1 ), LgHxy
912+ return float (np . array ( Lxy ). item () ), Lgxy .reshape (- 1 ,1 ), LgHxy
913913
914914 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
915915 #
0 commit comments