Search results for

column

2,051 results found

Post

Replies

Boosts

Views

Activity

Reply to Question About Swift
I'm still tweaking it but I was thinking something along these lines...printTable Function Initialize two variables: one to hold the character count of the column label and the other to hold the character count of each itemif the character count of item is greater than the character count in the column label set them equal to each otherfor the column labels, set paddingNeeded equal to the width of each column minus the character count in columnLabelfor the rows, set paddingNeeded equal to width of each column minus the character count of each item or might use a function to compute widths then implement in printTable functionWhat do you think?
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’18
Reply to Question About Swift
So you're making the columns wider as necessary? That's a bit of work, as you've seen, to compute the widths. What happens if a name has a million characters? So, there is more to think about here.A simpler approach is to keep the column widths, but then you can't show all the data. So, what can you show instead? You can solve the crashing problem by only showing as much data as fits, but that's going to be misleading to anyone using the table.Either way, solving the problem takes a bit of analysis and planning.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’18
Reply to Question About Swift
Yeah and a million characters is a lot lol but I see your point. I'm going to try basing the column widths by the difference in the variable character counts. I solved the crashing problem, it's just an alignment problem now. I'm going to try one of these ways and I'll post the results
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’18
Reply to Sample code for MPSMatrixDecompositionCholesky?
Thank you, but I still don't know if there is any bug. I think I must be misaligning the data in the Metal buffer. The Intel Iris Pro 650 on the MacBook Pro gives me the 'closest' answer, the Radeon 555 iMac doesn't make sense at all ... but you know 'close' doesn't count in matrix algebra. I am trying to understand how to assign data to specific locations in the buffer. Obviously, if the GPUs all require 16 byte rows (from .rowBytes) then my 8 bytes (of 2 columns) of data may be the issue?
Topic: Graphics & Games SubTopic: General Tags:
Mar ’18
Create Article using apple-news api problems
Hello, I am stuck at the same point my code and can't figure out what is wrong with it. Can someone take a look an advise on what might be the problem. I am writing a curl post request using PHP. I can successfully connect to get information about my channel but can't post an article there.Error I am getting is( [code] => MISSING [keyPath] => Array ( [0] => article.json ) ) JSON FILE{ title: Article Title, version: 1.5, identifier: testArticle, language: en, layout: { columns: 10, width: 1024, margin: 85, gutter: 20 }, documentStyle: { backgroundColor: #F5F9FB }, components: [], textStyles: {}, componentLayouts: {}, componentStyles: {}, componentTextStyles: {} }CODE<?php //set the timezone date_default_timezone_set('UTC'); //get json to be sent $data = json_encode('article.json'); $Content_Type='Content-Type: multipart/form-data; boundary=--535e329ca936f79a19ac9a251f7d48f7'; //set variables $http_method = 'POST'; $date = gmdate('Y-m-dTH:i:sZ'); $key = 'xxxx'; $url = 'https://news-api.appl
1
0
1.4k
Mar ’18
Reply to Sample code for MPSMatrixDecompositionCholesky?
Here is the code I am running which yields these results:1.41421 1.00.707107 1.22474I don't get good results with MPSMatrixDescriptor.rowBytesthe results above employ MemoryLayout.strideIf I used the above results in a strictly mathematical matrix operation of L* L transposed it would give me theincorrect A matrix, but if I 'filter' out the upper off diagonal and replace it by zero it would give me the correct answer for A.My real issue is that my iMac doesn't give the same answer as my MacBook Pro does with the code below. (But I'll have to check that again.)import MetalPerformanceShaderslet device = MTLCreateSystemDefaultDevice()!let commandQueue = device.makeCommandQueue()let M = 2let row = M * MemoryLayout<Float>.stridelet mdesc = MPSMatrixDescriptor(dimensions: M, columns: M, rowBytes: row, dataType: MPSDataType.float32)let matlength = M * rowlet arrayA: [Float] = [ 2 , 1 , 1 , 2 ]let buffA = device.makeBuffer(bytes: arrayA, length: matlength)let matA = MPSMatrix(buffer: buffA!, descriptor
Topic: Graphics & Games SubTopic: General Tags:
Mar ’18
Reply to Sample code for MPSMatrixDecompositionCholesky?
I replaced the 1.0 in the upper off diagonal of the Cholesky lower decomposition with a zero and ran the MPSMatrixSolveCholesky. The solution is correct for a left hand side B matrix of:1 00 0The solution for X is:2/3 0-1/3 0Guess what? If you just use the lower decomposition without the zero replacement ... or with the 1.0 you will get the same result!In fact, you can put any number in the upper off diagonal and it will give you the correct result!Apple just ignores the upper off diagonal. I should have thought of this before. (But if you were to use this 'Apple decomposition' in matrix multiplication I think you would need those zeros in the upper off diagonal.)Still, haven't gotten the correct answer on my iMac ... only the MacBook Pro ... so far.-----------------------------------------// Metal_LA : Cholesky factorization and solver test// Metal Linear Algebra solver via Cholesky factorization// This code solves: A * X = B for a 2 x 2 test matrix// where A is M x M, X is M x M, and B is M x M and M = 2imp
Topic: Graphics & Games SubTopic: General Tags:
Mar ’18
Column/table layout for a section of text?
Hi,How might one use UITextView to render some text in a table layout? Something like... Some intro paragraph. Blah blah blah. Blah blah blah blah. red rojo blue azul green verde More normal text following. Blah blah.I'd like the columns centered, so I don't think it's as simple as setting tab stops.Maybe that table area has to be it's own UIView. How do you embed a custom UIView within the flow of text?Rob
0
0
535
Mar ’18
Reply to Question About Swift
Here's what I ended up with, it works now...import Cocoa protocol TabularDataSource { var numberOfRows: Int { get } var numberOfColumns: Int { get } func label(forColumn column: Int) -> String func itemFor(row: Int, column: Int) -> String } func computeWidths(for dataSource: TabularDataSource) -> [Int] { var columnWidths = [Int]() for j in 0 ..< dataSource.numberOfColumns { let columnLabel = dataSource.label(forColumn: j) columnWidths.append(columnLabel.count) for i in 0 ..< dataSource.numberOfRows { let item = dataSource.itemFor(row: i, column: j) if columnWidths[j] < item.count { columnWidths[j] = item.count } } } return columnWidths } func printTable(_ dataSource: TabularDataSource & CustomStringConvertible) { print(Table: (dataSource.description)) var firstRow = | var columnWidths = computeWidths(for: dataSource) for i in 0 ..< dataSource.numberOfColumns { let columnLabel = dataSource.label(forColumn: i) let paddingNeeded = columnWidths[i] - columnLabel.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’18
Reply to UICollectionViewCell & Multitasking on iPad
I have used your code like this... // In your view controller: // This method is called when the app screen size changes. override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { if let flowLayout = collectionView?.collectionViewLayout as? UICollectionViewFlowLayout { // Adjust the layout. This is a flow layout example. // flowLayout.minimumInteritemSpacing = size.width / 0.0 // flowLayout.itemSize = CGSize(width: size.width / 0.0, height: 0.0) // Invalidate the layout. flowLayout.invalidateLayout() } collectionView?.reloadData() }It seems when I get into multitasking this function gets called for 'sizeForItemAt indexPath: IndexPath'& specifically for iPad this function gets called when I go into multitasking... UIDeviceOrientation.unknownif UIDevice.current.orientation == UIDeviceOrientation.unknown { print(It's iPad UIDeviceOrientation.unknown) / let spacing = self.view.frame.size.width - 15 let itemWidth = spacing / 2 let itemHeight = itemWidth sizeAr
Mar ’18
Reply to Setting a Default Property Value with a Closure or Function
This is only to create a chessboard, with alternating black and white cells. No recursion at all here!temporaryBoard will simply be an array of 64 true or false: [false, true, false, true …] var isBlack = false // Start with a white cell for i in 1...8 { // The 8 lines // When on one line, explore all cells of the line (the 8 columns) for j in 1...8 { temporaryBoard.append(isBlack) // Add the cell to the array isBlack = !isBlack // next cell in the line is of alternating color } isBlack = !isBlack // At the end of line, one need to start the new line with a different color than the end of previous line (see how a chessboard is drawn) }
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’18
Reply to Setting a Default Property Value with a Closure or Function
just indexes ; if you want it clearer, you can call them iRow and jColumn var isBlack = false // Start with a white cell for iRow in 1...8 { // The 8 lines // When on one line, explore all cells of the line (the 8 columns) for jColumn in 1...8 { temporaryBoard.append(isBlack) // Add the cell to the array isBlack = !isBlack // next cell in the line is of alternating color } isBlack = !isBlack // At the end of line, one need to start the new line with a different color than the end of previous line (see how a chessboard is drawn) }But in fact, you dont even need them, because they are not used in the loop, and could write: for _ in 1...8 { // The 8 lines // When on one line, explore all cells of the line (the 8 columns) for _ in 1...8 {_ represents a dummy var ; it is not the same for the 2 loops, but a different internal one created by the compiler that you don't even see.
Topic: Programming Languages SubTopic: Swift Tags:
Mar ’18
Reply to Trying to use AutoLayout for a square UICollectionView
There are no errors logged. I am following guidelines to use different priorities for those constraints that might conflict. So, it should work since the Aspect Ratio (1:1) is the highest priority of the sizing constraints.Why am I doing this? Yes, I want to constain the shape so that I can have the same number of rows and columns and equal lengths of sides for each square within the collection. 4x4, 5x5, 6x6, etc with each one filling up the collection view depnding on the preference (see Make it 13 in the App Store and I think this will make sense.Everything works great, except I need the view to be a square always and I want it to automatically size depending on the size of the device and the orientation.Thanks.
Mar ’18