首页 \ 问答 \ 如何使用Eigen :: Matrix作为参考(How to use Eigen::Matrix by reference)

如何使用Eigen :: Matrix作为参考(How to use Eigen::Matrix by reference)

我有一个小问题,但我不知道如何解决它。

让我们开始吧:我需要使用多线程来处理一个大的特征矩阵。 每个线程都需要访问矩阵。 维度是在程序执行过程中指定的,所以我必须在main()中声明它,而不是全局的。 我尝试了不同的解决方案而没有成功 我搜索像“通过引用传递”的东西,但我读到这种方法不适用于Eigen矩阵。 这里有一个小例子。 有人可以告诉我如何解决这个问题? 该程序需要很快,例如: - 在一个文件中保存矩阵,读取每个线程中的文件,在矩阵上工作,将矩阵保存在文件中,从主文件重新读取文件 - 不是最好的办法,我认为...;)有人知道更好的解决方案吗? 谢谢!

void calc() {
    // work on the Matrix
}

int main() {
    Eigen::Matrix<bool, a, b> Mat;
    // Start some thread(calc);
    cout << Mat;
}

I have a small problem, but i don't know how to solve it.

Let's start: I need to work on a big Eigen Matrix using multithreads. Each thread need to access to the matrix. The dimension is specified during the program execution, so I must declare it inside the main(), and not as global. I tried different solutions without success. I search something like "pass by reference" but i read that this method don't work with Eigen Matrix. Here there is a small example. Can someone tell me how can I solve this problem? The program need to be fast, so something like: -save the matrix in a file, and read the file in each thread, work on the matrix, save the matrix in a file, re-read the file from the main- is not the best way, I think... ;) Does someone know a better solution? Thanks at all!

void calc() {
    // work on the Matrix
}

int main() {
    Eigen::Matrix<bool, a, b> Mat;
    // Start some thread(calc);
    cout << Mat;
}

原文:https://stackoverflow.com/questions/37333822
更新时间:2022-10-21 08:10

最满意答案

例如,我添加这个

步骤1

创建One UIPickerUItextField和NSArray以加载详细信息

@interface ViewController ()<UITextFieldDelegate,UIPickerViewDataSource,UIPickerViewDelegate>
{

UITextField *myTextField;
UIPickerView *myPickerView;
NSArray *pickerArray;
}

@end

第2步

在您的ViewDidLoad调用选择器方法

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self addPickerView];
}

步骤3

create the picker, textfield and done button

-(void)addPickerView{
pickerArray = [[NSArray alloc]initWithObjects:@"Chess",
               @"Cricket",@"Football",@"Tennis",@"Volleyball", nil];
myTextField = [[UITextField alloc]initWithFrame:
               CGRectMake(10, 100, 300, 30)];
myTextField.borderStyle = UITextBorderStyleRoundedRect;
myTextField.textAlignment = NSTextAlignmentCenter;
myTextField.delegate = self;
[self.view addSubview:myTextField];
[myTextField setPlaceholder:@"Pick a Sport"];
myPickerView = [[UIPickerView alloc]init];
myPickerView.dataSource = self;
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
                               initWithTitle:@"Done" style:UIBarButtonItemStyleDone
                               target:self action:@selector(done:)];
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:
                      CGRectMake(0, self.view.frame.size.height-
                                 myPickerView.frame.size.height-50, 320, 50)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
NSArray *toolbarItems = [NSArray arrayWithObjects:
                         doneButton, nil];
[toolBar setItems:toolbarItems];
myTextField.inputView = myPickerView;
myTextField.inputAccessoryView = toolBar;

}

步骤4

如果用户按下完成按钮,则退出选择器

-(void)done:(id)sender
{

[myTextField resignFirstResponder];
}

步骤-5

PickerView委托方法

#pragma mark - Picker View Data source
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
return [pickerArray count];
}

#pragma mark- Picker View Delegate

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:
(NSInteger)row inComponent:(NSInteger)component{
[myTextField setText:[pickerArray objectAtIndex:row]];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:
(NSInteger)row forComponent:(NSInteger)component{
return [pickerArray objectAtIndex:row];
}

这里我附上了示例项目

样本输出就像

在此处输入图像描述

更新

如果您使用隐藏的按钮,则pickerview使用此选项

-(void)donePressed:(id)sender
{
  [self.myPickerView removeFromSuperview];

}

按下按钮时调用此方法

[self funtion];

for example I add this

Step-1

Create the One UIPicker,UItextField and NSArray for load the details

@interface ViewController ()<UITextFieldDelegate,UIPickerViewDataSource,UIPickerViewDelegate>
{

UITextField *myTextField;
UIPickerView *myPickerView;
NSArray *pickerArray;
}

@end

Step-2

on your ViewDidLoad call the picker method like

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self addPickerView];
}

Step-3

create the picker, textfield and done button

-(void)addPickerView{
pickerArray = [[NSArray alloc]initWithObjects:@"Chess",
               @"Cricket",@"Football",@"Tennis",@"Volleyball", nil];
myTextField = [[UITextField alloc]initWithFrame:
               CGRectMake(10, 100, 300, 30)];
myTextField.borderStyle = UITextBorderStyleRoundedRect;
myTextField.textAlignment = NSTextAlignmentCenter;
myTextField.delegate = self;
[self.view addSubview:myTextField];
[myTextField setPlaceholder:@"Pick a Sport"];
myPickerView = [[UIPickerView alloc]init];
myPickerView.dataSource = self;
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc]
                               initWithTitle:@"Done" style:UIBarButtonItemStyleDone
                               target:self action:@selector(done:)];
UIToolbar *toolBar = [[UIToolbar alloc]initWithFrame:
                      CGRectMake(0, self.view.frame.size.height-
                                 myPickerView.frame.size.height-50, 320, 50)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
NSArray *toolbarItems = [NSArray arrayWithObjects:
                         doneButton, nil];
[toolBar setItems:toolbarItems];
myTextField.inputView = myPickerView;
myTextField.inputAccessoryView = toolBar;

}

Step-4

if user press the Done Button resign the picker

-(void)done:(id)sender
{

[myTextField resignFirstResponder];
}

Step-5

PickerView Delegate methods

#pragma mark - Picker View Data source
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
return [pickerArray count];
}

#pragma mark- Picker View Delegate

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:
(NSInteger)row inComponent:(NSInteger)component{
[myTextField setText:[pickerArray objectAtIndex:row]];
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:
(NSInteger)row forComponent:(NSInteger)component{
return [pickerArray objectAtIndex:row];
}

here I attached the sample project

Sample Output like

enter image description here

Update

if you are used the button hidden the pickerview use this

-(void)donePressed:(id)sender
{
  [self.myPickerView removeFromSuperview];

}

when you pressed the button call this method

[self funtion];

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。