aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/TCC/Tango.TCC.LoadTestLib/EigenDir/lapack/lu.cpp
blob: 90cebe0f4801c40c5b5979b7eb0553952b880951 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// This file is part of Eigen, a lightweight C++ template library
// for linear algebra.
//
// Copyright (C) 2010-2011 Gael Guennebaud <gael.guennebaud@inria.fr>
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "common.h"
#include <Eigen/LU>

// computes an LU factorization of a general M-by-N matrix A using partial pivoting with row interchanges
EIGEN_LAPACK_FUNC(getrf,(int *m, int *n, RealScalar *pa, int *lda, int *ipiv, int *info))
{
  *info = 0;
        if(*m<0)                  *info = -1;
  else  if(*n<0)                  *info = -2;
  else  if(*lda<std::max(1,*m))   *info = -4;
  if(*info!=0)
  {
    int e = -*info;
    return xerbla_(SCALAR_SUFFIX_UP"GETRF", &e, 6);
  }

  if(*m==0 || *n==0)
    return 0;

  Scalar* a = reinterpret_cast<Scalar*>(pa);
  int nb_transpositions;
  int ret = int(Eigen::internal::partial_lu_impl<Scalar,ColMajor,int>
                     ::blocked_lu(*m, *n, a, *lda, ipiv, nb_transpositions));

  for(int i=0; i<std::min(*m,*n); ++i)
    ipiv[i]++;

  if(ret>=0)
    *info = ret+1;

  return 0;
}

//GETRS solves a system of linear equations
//    A * X = B  or  A' * X = B
//  with a general N-by-N matrix A using the LU factorization computed  by GETRF
EIGEN_LAPACK_FUNC(getrs,(char *trans, int *n, int *nrhs, RealScalar *pa, int *lda, int *ipiv, RealScalar *pb, int *ldb, int *info))
{
  *info = 0;
        if(OP(*trans)==INVALID)  *info = -1;
  else  if(*n<0)                 *info = -2;
  else  if(*nrhs<0)              *info = -3;
  else  if(*lda<std::max(1,*n))  *info = -5;
  else  if(*ldb<std::max(1,*n))  *info = -8;
  if(*info!=0)
  {
    int e = -*info;
    return xerbla_(SCALAR_SUFFIX_UP"GETRS", &e, 6);
  }

  Scalar* a = reinterpret_cast<Scalar*>(pa);
  Scalar* b = reinterpret_cast<Scalar*>(pb);
  MatrixType lu(a,*n,*n,*lda);
  MatrixType B(b,*n,*nrhs,*ldb);

  for(int i=0; i<*n; ++i)
    ipiv[i]--;
  if(OP(*trans)==NOTR)
  {
    B = PivotsType(ipiv,*n) * B;
    lu.triangularView<UnitLower>().solveInPlace(B);
    lu.triangularView<Upper>().solveInPlace(B);
  }
  else if(OP(*trans)==TR)
  {
    lu.triangularView<Upper>().transpose().solveInPlace(B);
    lu.triangularView<UnitLower>().transpose().solveInPlace(B);
    B = PivotsType(ipiv,*n).transpose() * B;
  }
  else if(OP(*trans)==ADJ)
  {
    lu.triangularView<Upper>().adjoint().solveInPlace(B);
    lu.triangularView<UnitLower>().adjoint().solveInPlace(B);
    B = PivotsType(ipiv,*n).transpose() * B;
  }
  for(int i=0; i<*n; ++i)
    ipiv[i]++;

  return 0;
}
n">ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>> _pendingDialogs; private List<AppButton> _appButtons; private bool _notificationsVisible; /// <summary> /// Gets or sets a value indicating whether to allow notifications visibility. /// </summary> public bool NotificationsVisible { get { return _notificationsVisible; } set { _notificationsVisible = value; RaisePropertyChangedAuto(); } } /// <summary> /// Gets the collection of notification items. /// </summary> public ObservableCollection<NotificationItem> NotificationItems { get; private set; } /// <summary> /// Gets the application bar items. /// </summary> public ObservableCollection<AppBarItem> AppBarItems { get; private set; } /// <summary> /// Gets the notification items view. /// </summary> public ICollectionView NotificationItemsView { get; private set; } /// <summary> /// Gets the collection of taskbar items. /// </summary> public ObservableCollection<TaskBarItem> TaskBarItems { get; private set; } /// <summary> /// Initializes a new instance of the <see cref="DefaultNotificationProvider"/> class. /// </summary> public DefaultNotificationProvider() { NotificationsVisible = true; NotificationItems = new ObservableCollection<NotificationItem>(); AppBarItems = new ObservableCollection<AppBarItem>(); CollectionViewSource.GetDefaultView(AppBarItems).SortDescriptions.Add(new SortDescription(nameof(AppBarItem.Priority), ListSortDirection.Ascending)); TaskBarItems = new ObservableCollection<TaskBarItem>(); _pendingMessageBoxes = new ConcurrentQueue<PendingNotification<MessageBoxVM, bool>>(); _pendingDialogs = new ConcurrentQueue<PendingNotification<DialogAndView, DialogViewVM>>(); _appButtons = new List<AppButton>(); PopNotificationCommand = new RelayCommand<NotificationItem>((x) => PopNotification(x)); NotificationItems.EnableCrossThreadOperations(); NotificationItemsView = CollectionViewSource.GetDefaultView(NotificationItems); NotificationItemsView.SortDescriptions.Add(new SortDescription(nameof(NotificationItem.Priority), ListSortDirection.Descending)); } private MessageBoxVM _currentMessageBox; /// <summary> /// Gets the current message box if any. /// </summary> public MessageBoxVM CurrentMessageBox { get { return _currentMessageBox; } private set { _currentMessageBox = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasMessageBox)); RaisePropertyChanged(nameof(HasDialogOrMessage)); } } /// <summary> /// Gets a value indicating whether a message box is available. /// </summary> public bool HasMessageBox { get { return CurrentMessageBox != null; } } private FrameworkElement _currentDialog; /// <summary> /// Gets the current dialog if any. /// </summary> public FrameworkElement CurrentDialog { get { return _currentDialog; } private set { _currentDialog = value; RaisePropertyChangedAuto(); RaisePropertyChanged(nameof(HasDialog)); RaisePropertyChanged(nameof(HasDialogOrMessage)); } } private AppButton _currentAppButton; /// <summary> /// Gets the current app button. /// </summary> public AppButton CurrentAppButton { get { return _currentAppButton; } private set { _currentAppButton = value; RaisePropertyChangedAuto(); } } /// <summary> /// Gets a value indicating whether a dialog is available. /// </summary> public bool HasDialog { get { return CurrentDialog != null; } } public bool HasDialogOrMessage { get { return HasDialog || HasMessageBox; } } /// <summary> /// Shows an error message box. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public Task ShowError(string message) { return ShowMessageBox(new MessageBoxVM() { Message = message, Icon = TouchIconKind.AlertCircleOutline, Title = "Error", Brush = Application.Current.Resources["TangoMessageBoxErrorBrush"] as Brush, HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderErrorBrush"] as Brush, }); } /// <summary> /// Shows an information message box. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public Task ShowInfo(string message) { return ShowMessageBox(new MessageBoxVM() { Message = message, Icon = TouchIconKind.AlertCircleOutline, Title = "Information", Brush = Application.Current.Resources["TangoMessageBoxInfoBrush"] as Brush, HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderInfoBrush"] as Brush, }); } /// <summary> /// Shows warning message box. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public Task ShowWarning(string message) { return ShowMessageBox(new MessageBoxVM() { Message = message, Icon = TouchIconKind.AlertCircleOutline, Title = "Warning", Brush = Application.Current.Resources["TangoMessageBoxWarningBrush"] as Brush, HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderWarningBrush"] as Brush, }); } /// <summary> /// Shows a question message box. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public Task<bool> ShowQuestion(string message) { return ShowMessageBox(new MessageBoxVM() { Message = message, Icon = TouchIconKind.QuestionCircleRegular, Title = "Confirm", HasCancel = true, Brush = Application.Current.Resources["TangoMessageBoxQuestionBrush"] as Brush, HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderQuestionBrush"] as Brush, }); } /// <summary> /// Shows a success message box. /// </summary> /// <param name="message">The message.</param> /// <returns></returns> public Task ShowSuccess(string message) { return ShowMessageBox(new MessageBoxVM() { Message = message, Icon = TouchIconKind.Check, Title = "Success", Brush = Application.Current.Resources["TangoMessageBoxSuccessBrush"] as Brush, HeaderBrush = Application.Current.Resources["TangoMessageBoxHeaderSuccessBrush"] as Brush, }); } /// <summary> /// Shows the message box. /// </summary> /// <param name="vm">The view model.</param> /// <returns></returns> private Task<bool> ShowMessageBox(MessageBoxVM vm) { ReleaseGlobalBusyMessage(); LogManager.Log($"Displaying MessagBox '{vm.Message}'."); TaskCompletionSource<bool> source = new TaskCompletionSource<bool>(); vm.Accepted += () => { OnMessageBoxClosed(); source.SetResult(true); }; vm.Canceled += () => { OnMessageBoxClosed(); source.SetResult(false); }; if (CurrentMessageBox == null) { CurrentMessageBox = vm; } else { _pendingMessageBoxes.Enqueue(new PendingNotification<MessageBoxVM, bool>(vm, source)); } return source.Task; } /// <summary> /// Called when the message box has been closed. /// </summary> private void OnMessageBoxClosed() { LogManager.Log("MessageBox closed."); CurrentMessageBox = null; if (_pendingMessageBoxes.Count > 0) { PendingNotification<MessageBoxVM, bool> p = null; if (_pendingMessageBoxes.TryDequeue(out p)) { CurrentMessageBox = p.Item; } } } /// <summary> /// Inserts the notification item to the bottom of the notifications collection. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public NotificationItem PushNotification(NotificationItem item) { LogManager.Log($"Pushing NotificationItem '{item.GetType().Name}'."); item.RemoveAction = () => { PopNotification(item); }; NotificationItems.Insert(0, item); RaisePropertyChanged(nameof(HasNotificationItems)); RaisePropertyChanged(nameof(NotificationItems)); return item; } /// <summary> /// Pushes the notification. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public NotificationItem PushNotification<T>() where T : NotificationItem { return PushNotification(Activator.CreateInstance<T>()); } /// <summary> /// Removed the specified notification item. /// </summary> /// <param name="item">The item.</param> public void PopNotification(NotificationItem item) { LogManager.Log($"Popping out NotificationItem '{item.GetType().Name}'."); NotificationItems.Remove(item); RaisePropertyChanged(nameof(HasNotificationItems)); RaisePropertyChanged(nameof(NotificationItems)); } /// <summary> /// Gets a value indicating whether this instance has notification items. /// </summary> public bool HasNotificationItems { get { return NotificationItems.Count > 0; } } /// <summary> /// Gets the pop notification command. /// </summary> public RelayCommand<NotificationItem> PopNotificationCommand { get; private set; } /// <summary> /// Displays the specified dialog in a modal design. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="datacontext">The data context.</param> /// <param name="view">The view.</param> /// <returns></returns> public async Task<T> ShowDialog<T>(T datacontext, FrameworkElement view) where T : DialogViewVM { TaskCompletionSource<DialogViewVM> source = new TaskCompletionSource<DialogViewVM>(); InvokeUI(() => { view.DataContext = datacontext; TangoIOC.Default.Inject(datacontext); view.Loaded += (_, __) => { view.DataContext = datacontext; datacontext.OnShow(); }; datacontext.Accepted += () => { OnDialogClosed(); source.SetResult(datacontext); }; datacontext.Canceled += () => { OnDialogClosed(); source.SetResult(datacontext); }; if (CurrentDialog == null) { CurrentDialog = view; } else { _pendingDialogs.Enqueue(new PendingNotification<DialogAndView, DialogViewVM>(new DialogAndView(datacontext, view), source)); } }); var result = await source.Task; return result as T; } /// <summary> /// Called when [dialog closed]. /// </summary> private void OnDialogClosed() { CurrentDialog = null; if (_pendingDialogs.Count > 0) { PendingNotification<DialogAndView, DialogViewVM> p = null; if (_pendingDialogs.TryDequeue(out p)) { CurrentDialog = p.Item.View; } } } /// <summary> /// Displays the specified dialog in a modal design. /// The notification provider will try to locate the view automatically using conventions. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="datacontext">The data context.</param> /// <returns></returns> public Task<T> ShowDialog<T>(T datacontext) where T : DialogViewVM { TaskCompletionSource<T> source = new TaskCompletionSource<T>(); InvokeUI(async () => { var callingAssembly = datacontext.GetType().Assembly; String viewName = datacontext.GetType().FullName.Replace("VM", ""); var viewType = callingAssembly.GetType(viewName); if (viewType == null) { throw new NullReferenceException("View type for " + datacontext.GetType().Name + " could not be found!"); } var view = Activator.CreateInstance(viewType) as FrameworkElement; if (view == null) { throw new NullReferenceException("The view " + viewType.ToString() + " is not of type framework element."); } T result = await ShowDialog<T>(datacontext, view); source.SetResult(result); }); return source.Task; } /// <summary> /// Displays the specified dialog in a modal design. /// The data context instance will be automatically created. /// The notification provider will try to locate the view automatically using conventions. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public Task<T> ShowDialog<T>() where T : DialogViewVM { TaskCompletionSource<T> source = new TaskCompletionSource<T>(); InvokeUI(async () => { var result = await ShowDialog<T>(Activator.CreateInstance<T>()); source.SetResult(result); }); return source.Task; } /// <summary> /// Sets the global busy message. /// </summary> /// <param name="message">The message.</param> public void SetGlobalBusyMessage(string message) { GlobalBusyMessage = message; IsInGlobalBusyState = true; RaisePropertyChanged(nameof(IsInGlobalBusyState)); RaisePropertyChanged(nameof(GlobalBusyMessage)); } /// <summary> /// Releases the global busy message. /// </summary> public void ReleaseGlobalBusyMessage() { GlobalBusyMessage = null; IsInGlobalBusyState = false; RaisePropertyChanged(nameof(IsInGlobalBusyState)); RaisePropertyChanged(nameof(GlobalBusyMessage)); } /// <summary> /// Gets the current global busy message. /// </summary> public string GlobalBusyMessage { get; private set; } /// <summary> /// Gets a value indicating whether this instance is in global busy state. /// </summary> public bool IsInGlobalBusyState { get; private set; } /// <summary> /// Gets a value indicating whether this instance has application bar item. /// </summary> public bool HasAppBarItems { get { return AppBarItems.Count > 0; } } /// <summary> /// Pushes the application bar item. /// </summary> /// <param name="appBarItem">The application bar item.</param> /// <returns></returns> public AppBarItem PushAppBarItem(AppBarItem appBarItem) { LogManager.Log($"Pushing AppBarItem '{appBarItem.GetType().Name}'."); AppBarItems.Add(appBarItem); appBarItem.RemoveAction = () => PopAppBarItem(appBarItem); RaisePropertyChanged(nameof(HasAppBarItems)); return appBarItem; } /// <summary> /// Pushes the application bar item. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public T PushAppBarItem<T>() where T : AppBarItem { return PushAppBarItem(Activator.CreateInstance<T>()) as T; } /// <summary> /// Pops the application bar item. /// </summary> /// <param name="appBarItem">The application bar item.</param> public void PopAppBarItem(AppBarItem appBarItem) { InvokeUI(() => { LogManager.Log($"Popping out AppBarItem '{appBarItem.GetType().Name}'."); AppBarItems.Remove(appBarItem); RaisePropertyChanged(nameof(HasAppBarItems)); }); } /// <summary> /// Pushes the task bar item. /// </summary> /// <param name="taskBarItem">The task bar item.</param> /// <returns></returns> public TaskBarItem PushTaskBarItem(TaskBarItem taskBarItem) { TaskBarItems.Add(taskBarItem); return taskBarItem; } /// <summary> /// Handles the Push Task Bar Item event. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public TaskBarItem PushTaskBarItem<T>() where T : TaskBarItem { return PushTaskBarItem(Activator.CreateInstance<T>()); } /// <summary> /// Pops the task bar item. /// </summary> /// <param name="taskBarItem"></param> public void PopTaskBarItem(TaskBarItem taskBarItem) { TaskBarItems.Remove(taskBarItem); } /// <summary> /// Pushes the app button. /// </summary> /// <param name="appButton">The app button.</param> public void PushAppButton(AppButton appButton) { if (appButton != null) { LogManager.Log($"Pushing app button '{appButton.GetType().Name}'..."); } _appButtons.Insert(0, appButton); CurrentAppButton = appButton; } /// <summary> /// Pops the app button. /// </summary> /// <param name="appButton">The app button.</param> public void PopAppButton(AppButton appButton) { if (appButton != null) { LogManager.Log($"Popping app button '{appButton.GetType().Name}'..."); } else { LogManager.Log("Popping app button 'null' ??", LogCategory.Warning); } _appButtons.RemoveAll(x => x == appButton); CurrentAppButton = _appButtons.FirstOrDefault(); } } }